Commit 5e70b342 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

fix issue #2552: if no motor controller name is given, build controller name...

fix issue #2552: if no motor controller name is given, build controller name with config md5 hash, to ensure good cache per controller
parent c26f9d26
Pipeline #41365 failed with stages
in 101 minutes and 41 seconds
......@@ -328,6 +328,9 @@ def create_objects_from_config_node(config, node):
controller_class_name = node.get("class")
controller_name = node.get("name")
if controller_name is None:
# build a controller name, from the config
controller_name = f"{controller_class_name}_{node.md5hash()}"
controller_class = find_class(node, "bliss.controllers.motors")
controller_module = sys.modules[controller_class.__module__]
axes = dict()
......
......@@ -51,6 +51,7 @@ import types
import pickle
import weakref
import operator
import hashlib
from collections import defaultdict
from collections.abc import MutableMapping, MutableSequence
......@@ -296,6 +297,14 @@ class ConfigNode(MutableMapping):
def encode(self):
return self._data
def md5hash(self):
"""Return md5 hex digest of the config node
Uses internal config dict to build the hash, so
two nodes with same digest represent the exact same config
"""
return hashlib.md5(str(self._data).encode()).hexdigest()
def reparent(self, new_parent_node):
self._parent = new_parent_node
......
......@@ -284,7 +284,7 @@ def test_global_map(beacon, s1hg, roby):
# now check if expected links match the map
expected_links = {
roby.controller: {"s1f", "s1b", "s1u", "s1d", "roby", "hooked_m0"},
roby.controller.name: {"s1f", "s1b", "s1u", "s1d", "roby", "hooked_m0"},
"primary_slit": {"s1vg", "s1vo", "s1hg", "s1ho", "s1f", "s1d", "s1u", "s1b"},
heater.controller: {"thermo_sample", "heater", "sample_regulation"},
"axes": {
......@@ -302,7 +302,7 @@ def test_global_map(beacon, s1hg, roby):
"hook0": {"hooked_m0"},
"controllers": {
"primary_slit",
roby.controller,
roby.controller.name,
heater.controller,
"motion_hooks",
},
......
......@@ -94,10 +94,7 @@ def test_add_motor_m0(params):
assert isinstance(get_logger(m0), logging.Logger)
all_loggers = logging.getLogger().manager.loggerDict
assert (
f"global.controllers.{m0.controller.__class__.__name__}.m0"
in all_loggers.keys()
)
assert f"global.controllers.{m0.controller.name}.m0" in all_loggers.keys()
def test_m0_logger_debugon(params, caplog):
......
......@@ -172,3 +172,23 @@ def test_encoder_disable_broken_init(default_session):
enc.enable()
assert enc.raw_read == 0.0
assert not enc.disabled
def test_initialized_cache(beacon):
roby = beacon.get("roby")
llbend1 = beacon.get("llbend1")
# /!\ check roby and llbend1 are on 2 different mockup controller instances
assert type(roby.controller) == type(llbend1.controller)
assert roby.controller != llbend1.controller
roby_controller_init_cache = channels.Cache(roby.controller, "initialized")
llbend1_controller_init_cache = channels.Cache(llbend1.controller, "initialized")
assert roby_controller_init_cache != llbend1_controller_init_cache
assert roby_controller_init_cache.name != llbend1_controller_init_cache.name
# check that another motor on the same controller has the same 'initialized' cache
m1 = beacon.get("m1")
assert roby.controller == m1.controller
m1_controller_init_cache = channels.Cache(m1.controller, "initialized")
assert m1_controller_init_cache == roby_controller_init_cache
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment