Commit a7a82607 authored by Piergiorgio Pancino's avatar Piergiorgio Pancino Committed by Matias Guijarro

renamed map node name 'devices' to 'controllers'

refactor on logging

renaming of methods
parent 30b30f52
......@@ -26,7 +26,7 @@ def logging_startup(
"""
logging.basicConfig(level=log_level, format=fmt)
logging.getLogger("bliss").setLevel(log_level)
logging.getLogger("beamline").setLevel(log_level)
logging.getLogger("session").setLevel(log_level)
class LogMixin:
......@@ -365,7 +365,7 @@ class Log:
maxlen = max([len(name) for (name, _, _) in loggers])
msgfmt = "{0:{width}} {1:8} {2:5}"
print("BEAMLINE INSTANCE MAP LOGGERS")
print("SESSION INSTANCE MAP LOGGERS")
print(msgfmt.format("instance", "level", "set", width=maxlen))
print(msgfmt.format("=" * maxlen, 8 * "=", 5 * "=", width=maxlen))
for (name, efflvl, setlvl) in loggers:
......@@ -490,15 +490,15 @@ def create_logger_name(G, node_id):
"""
# TODO: implement different starting point
try:
# search before through devices
path = nx.shortest_path(G, "devices", node_id)
# search before through controllers
path = nx.shortest_path(G, "controllers", node_id)
return "session." + ".".join(
format_node(G, n, format_string="tag->name->__class__") for n in path
)
except (nx.exception.NetworkXNoPath, nx.exception.NodeNotFound):
pass
try:
# search next starting from beamline
# search next starting from session
path = nx.shortest_path(G, "session", node_id)
return ".".join(
format_node(G, n, format_string="tag->name->__class__") for n in path
......
......@@ -35,7 +35,7 @@ class Map:
self.node_attributes_list = ["name", "address", "plugin"]
self.register("session")
self.register("devices", parents_list=["session"])
self.register("controllers", parents_list=["session"])
self.register("comms", parents_list=["session"])
self.register("counters", parents_list=["session"])
self.register("axes", parents_list=["session"])
......@@ -60,13 +60,13 @@ class Map:
register(self, children_list=[self.comm]) # with the communication layer
register(self, parents_list=[self.controller]) # with parent controller
register(self, tag=f"{host}:{port}") # instance with proper name
register(self, parents_list=['devices','comms']) # two parents
register(self, parents_list=['controllers','comms']) # two parents
If no parent is attached it will be 'devices' and then eventually
If no parent is attached it will be 'controllers' and then eventually
remapped if another instance will have as a child the other instance.
There could be node parents in form of a string, system defined are:
* 'devices'
* 'controllers'
* 'counters'
* 'comms'
......@@ -126,16 +126,16 @@ class Map:
self.G.add_edge(map_id(parent), map_id(instance))
for child in children_list:
# remap children removing the parent connection to devices
if (map_id("devices"), map_id(child)) in self.G.edges:
self.G.remove_edge(map_id("devices"), map_id(child))
# remap children removing the parent connection to controllers
if (map_id("controllers"), map_id(child)) in self.G.edges:
self.G.remove_edge(map_id("controllers"), map_id(child))
# add child
self.G.add_edge(map_id(instance), map_id(child))
for parent in parents_list:
# remap parents removing the parent connection to the device
if (map_id("devices"), map_id(instance)) in self.G.edges:
self.G.remove_edge(map_id("devices"), map_id(instance))
if (map_id("controllers"), map_id(instance)) in self.G.edges:
self.G.remove_edge(map_id("controllers"), map_id(instance))
# add child
self.G.add_edge(map_id(parent), map_id(instance))
......@@ -292,14 +292,14 @@ class Map:
def add_parent_if_missing(self):
"""
Remaps nodes with missing parents to 'devices'
Remaps nodes with missing parents to 'controllers'
"""
for node in list(self.G):
if node != "session" and not len(list(self.G.predecessors(node))):
self.G.add_edge("devices", node)
self.G.add_edge("controllers", node)
logger.debug(f"Added parent to {node}")
def map_draw_matplotlib(self, format_node: str = "tag->name->id"):
def draw_matplotlib(self, format_node: str = "tag->name->id"):
"""
Simple tool to draw the map with matplotlib
"""
......@@ -326,7 +326,7 @@ class Map:
except ImportError:
logger.error("Missing pygraphviz package")
def map_draw_pygraphviz(self, filename="graph", format_node="tag->name->id"):
def draw_pygraphviz(self, filename="graph", format_node="tag->name->id"):
"""
Simple tool to draw the map into graphviz format
......
......@@ -30,10 +30,10 @@ def beamline():
map = Map()
map.register("session")
map.register("devices", parents_list=["session"])
map.register("sessions", parents_list=["session"])
map.register("controllers", parents_list=["session"])
map.register("comms", parents_list=["session"])
map.register("counters", parents_list=["session"])
map.register("axes", parents_list=["session"])
return map
......@@ -73,7 +73,7 @@ def test_path_to_non_existing_node(beamline):
def test_path_to_with_non_existing_path(beamline):
with pytest.raises(nx.exception.NetworkXNoPath):
beamline.shortest_path("sessions", "comms")
beamline.shortest_path("controllers", "comms")
def test_find_children(beamline):
......@@ -83,7 +83,7 @@ def test_find_children(beamline):
def test_find_predecessor(beamline):
predecessors = beamline.find_predecessors("sessions")
predecessors = beamline.find_predecessors("counters")
assert isinstance(predecessors, list)
_pre = list(predecessors)
assert len(_pre) == 1
......@@ -100,16 +100,16 @@ def test_find_shortest_path(beamline):
def test_find_no_path(beamline):
"""this motor0 is attached to devices, so there is no link with sessions"""
"""this motor0 is attached to controllers, so there is no link with counters"""
beamline.register("motor0")
with pytest.raises(nx.exception.NetworkXNoPath):
beamline.shortest_path("sessions", "motor0")
beamline.shortest_path("axes", "motor0")
def test_find_shortest_path_reverse_order(beamline):
"""
reverting the order of device mapping, the path should be the same
this should be: beamline -> devices -> MotorControllerForM0 -> motor0
this should be: beamline -> controllers -> MotorControllerForM0 -> motor0
"""
beamline.register("MotorControllerForM0")
beamline.register("motor0", parents_list=["MotorControllerForM0"])
......@@ -135,7 +135,7 @@ def test_find_shortest_path_parallel(beamline):
def test_remap_children(beamline):
"""
this should be: beamline -> devices -> MotorControllerForM0 -> motor0
this should be: beamline -> controllers -> MotorControllerForM0 -> motor0
creating before motor0 that will be child of devices
then adding MotorControllerForM0 that will have motor0 as a child
motor0 should remap removing the connection device -> motor0
......@@ -160,7 +160,7 @@ def test_complex_map_remove_children(complex_beamline):
"""find predecessors of Contr_1, should be devices"""
_pre = list(complex_beamline.find_predecessors("Contr_1"))
assert len(_pre) == 1
assert _pre.pop() == "devices"
assert _pre.pop() == "controllers"
# finding children of Contr_1, should be Serial, Ax1, Ax2
_children = complex_beamline.find_children("Contr_1")
assert isinstance(_children, list)
......@@ -170,7 +170,7 @@ def test_complex_map_remove_children(complex_beamline):
assert "Axis_2" in list_children
assert "Serial_1" in list_children
# deleting devices node, now should be beamline
complex_beamline.delete(id_="devices")
complex_beamline.delete(id_="controllers")
_pre = list(complex_beamline.find_predecessors("Contr_1"))
assert len(_pre) == 1
assert _pre.pop() == "session"
......
Markdown is supported
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