Skip to content

Commit

Permalink
improve the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotan committed Sep 21, 2023
1 parent 888bcc6 commit 476c6ed
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 48 deletions.
13 changes: 13 additions & 0 deletions nxsrecconfig/ProfileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ def updateProfile(self, sync=False):
conf = Utils.tostr(dpmg.configuration)
self.__selector['MntGrpConfiguration'] = conf
mginfo['configuration'] = conf
door = self.__selector["Door"]
if door:
if ":" in door.split("/")[0] and len(door.split("/")) > 1:
host, port = door.split("/")[0].split(":")
db = tango.Database(host, int(port))
macroserver = MSUtils.getMacroServer(db, door, False)
else:
macroserver = MSUtils.getMacroServer(
tango.Database(), door, False)
if not macroserver:
door = ""
if not door:
self.__selector["Door"] = ""
if sync:
self.__setFromMntGrpConf(conf, componentdatasources)
self.__selector.storeSelection()
Expand Down
6 changes: 1 addition & 5 deletions nxsrecconfig/Selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,7 @@ def __postSetDoor(self, changed=True):
self.__db, "Door")
changed = True
if changed:
ms = self.__msp.updateMacroServer(self.__selection["Door"])
if not ms:
self.__selection["Door"] = TangoUtils.getDeviceName(
self.__db, "Door")
self.__msp.updateMacroServer(self.__selection["Door"])
self.__msp.updateMacroServer(self.__selection["Door"])

def __preGetPreselectingDataSources(self):
""" get method for preselectedDataSources attribute
Expand Down
6 changes: 4 additions & 2 deletions nxsrecconfig/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,15 @@ def usetEnv(cls, var, ms):
MSUtils.writeEnvAttr(dc, dp)

@classmethod
def getMacroServer(cls, db, door):
def getMacroServer(cls, db, door, find=True):
""" provides macro server of given door
:param db: tango database
:type db: :class:`tango.Database`
:param door: given door
:type door: :obj:`str`
:param find: find new macroserver if door does not exist
:type find: :obj:`bool`
:returns: first MacroServer of the given door
:rtype: :obj:`str`
"""
Expand All @@ -575,7 +577,7 @@ def getMacroServer(cls, db, door):
if lst and door.lower() in lst:
ms = mserver
break
if not ms and mss:
if find and door != 'module' and not ms and mss:
if hasattr(dp, "DoorList"):
ms = mss[0]
return ms
Expand Down
142 changes: 106 additions & 36 deletions test/MacroServerPools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,11 @@ def test_getMacroServer(self):
print("Run: %s.%s() " % (self.__class__.__name__, fun))
msp = MacroServerPools(0)
msp = MacroServerPools(10)
self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(self._ms.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
Expand All @@ -1058,20 +1061,29 @@ def test_getMacroServer(self):
self.assertEqual(msp.getPools(list(self._ms.door.keys())[0]), [])
self.myAssertRaise(Exception, msp.getPools, "")

self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(self._ms.ms.keys())[0])
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")

self.assertEqual(msp.getPools(list(self._ms.door.keys())[0]), [])

self._ms.dps[list(self._ms.ms.keys())[0]].DoorList = []
self.myAssertRaise(Exception, msp.updateMacroServer,
list(self._ms.door.keys())[0])
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception,
msp.getPools, list(self._ms.door.keys())[0])
# self.myAssertRaise(Exception, msp.updateMacroServer,
# list(self._ms.door.keys())[0])
msp.updateMacroServer(list(self._ms.door.keys())[0])
# self.myAssertRaise(Exception, msp.getMacroServer, "")
self.assertEqual(
msp.getMacroServer(""),
list(self._ms.ms.keys())[0])
self.assertEqual(
msp.getPools(list(self._ms.door.keys())[0]), [])
# self.myAssertRaise(Exception,
# msp.getPools, list(self._ms.door.keys())[0])

# constructor test
# \brief It tests default settings
Expand All @@ -1084,8 +1096,11 @@ def test_getPool(self):
{'PoolNames': self._pool.dp.name()})
self._ms.dps[list(self._ms.ms.keys())[0]].Init()

self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(self._ms.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
Expand All @@ -1104,8 +1119,11 @@ def test_getPool(self):
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(self._ms.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")

Expand All @@ -1120,13 +1138,24 @@ def test_getPool(self):
self.assertEqual(pools[0].name(), self._pool.dp.name())

self._ms.dps[list(self._ms.ms.keys())[0]].DoorList = []
self.myAssertRaise(Exception, msp.updateMacroServer,
list(self._ms.door.keys())[0])
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")

self.myAssertRaise(Exception,
msp.getPools, list(self._ms.door.keys())[0])
self.assertEqual(
msp.updateMacroServer(list(self._ms.door.keys())[0]),
list(self._ms.ms.keys())[0])
# self.myAssertRaise(Exception, msp.updateMacroServer,
# list(self._ms.door.keys())[0])
# self.myAssertRaise(Exception, msp.getMacroServer, "")
self.assertEqual(
msp.getMacroServer(""),
list(self._ms.ms.keys())[0])
# self.myAssertRaise(Exception, msp.getPools, "")
self.assertEqual(len(msp.getPools("")), 1)
self.assertEqual(
msp.getPools("")[0].name(),
self._pool.dp.name())
self.assertEqual(len(msp.getPools(list(self._ms.door.keys())[0])), 1)
self.assertEqual(
msp.getPools(list(self._ms.door.keys())[0])[0].name(),
self._pool.dp.name())

# constructor test
# \brief It tests default settings
Expand All @@ -1152,8 +1181,11 @@ def test_getPool_1to3(self):
for i in range(3):
ms2.dps[list(ms2.ms.keys())[0]].DoorList = doors
# print "doors", doors[i]
self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(ms2.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
Expand All @@ -1173,8 +1205,11 @@ def test_getPool_1to3(self):
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(ms2.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")

Expand All @@ -1189,11 +1224,26 @@ def test_getPool_1to3(self):
self.assertEqual(pools[0].name(), self._pool.dp.name())

ms2.dps[list(ms2.ms.keys())[0]].DoorList = []
self.myAssertRaise(Exception, msp.updateMacroServer, doors[i])
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
self.assertEqual(
msp.updateMacroServer(doors[i]), list(ms2.ms.keys())[0])
self.assertEqual(
msp.getMacroServer(""), list(ms2.ms.keys())[0])
pools = msp.getPools("")
self.assertEqual(len(pools), 1)
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

self.myAssertRaise(Exception, msp.getPools, doors[i])
pools = msp.getPools(doors[i])
self.assertEqual(len(pools), 1)
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

# self.myAssertRaise(
# Exception, msp.updateMacroServer, doors[i])
# self.myAssertRaise(Exception, msp.getMacroServer, "")
# self.myAssertRaise(Exception, msp.getPools, "")

# self.myAssertRaise(Exception, msp.getPools, doors[i])
finally:
ms2.tearDown()

Expand Down Expand Up @@ -1223,8 +1273,11 @@ def test_getPool_3to3(self):
for i, ms in enumerate(mss):
ms3.dps[ms].DoorList = [doors[i]]
# print "ms", ms, "doors", doors[i]
self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(ms3.ms.keys())[0])
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
Expand All @@ -1242,8 +1295,11 @@ def test_getPool_3to3(self):
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
list(ms3.ms.keys())[0])
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")

Expand All @@ -1258,11 +1314,25 @@ def test_getPool_3to3(self):
self.assertEqual(pools[0].name(), self._pool.dp.name())

ms3.dps[ms].DoorList = []
self.myAssertRaise(Exception, msp.updateMacroServer, doors[i])
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
self.assertEqual(
msp.updateMacroServer(doors[i]), list(ms3.ms.keys())[0])
self.assertEqual(
msp.getMacroServer(""), list(ms3.ms.keys())[0])
pools = msp.getPools("")
self.assertEqual(len(pools), 1)
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())

pools = msp.getPools(doors[i])
self.assertEqual(len(pools), 1)
self.assertTrue(isinstance(pools[0], tango.DeviceProxy))
self.assertEqual(pools[0].name(), self._pool.dp.name())
# self.myAssertRaise(
# Exception, msp.updateMacroServer, doors[i])
# self.myAssertRaise(Exception, msp.getMacroServer, "")
# self.myAssertRaise(Exception, msp.getPools, "")

self.myAssertRaise(Exception, msp.getPools, doors[i])
# self.myAssertRaise(Exception, msp.getPools, doors[i])
finally:
ms3.tearDown()

Expand Down
13 changes: 9 additions & 4 deletions test/Selector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,11 @@ def test_se_getPool_1to3(self):

for i in range(3):
ms2.dps[list(ms2.ms.keys())[0]].DoorList = doors
self.myAssertRaise(Exception, msp.updateMacroServer,
"sfdsTESTdfdf/sdfsdf/sdffsf")
# self.myAssertRaise(Exception, msp.updateMacroServer,
# "sfdsTESTdfdf/sdfsdf/sdffsf")
self.assertEqual(
msp.updateMacroServer("sfdsTESTdfdf/sdfsdf/sdffsf"),
msname)
self.myAssertRaise(Exception, msp.updateMacroServer, "")
self.myAssertRaise(Exception, msp.getMacroServer, "")
self.myAssertRaise(Exception, msp.getPools, "")
Expand Down Expand Up @@ -1596,9 +1599,11 @@ def test_Door(self):
se["MntGrp"] = val["MntGrp"]
se.storeSelection()

self.myAssertRaise(Exception, self.setDoor, se, "dfd")
# self.myAssertRaise(Exception, self.setDoor, se, "dfd")
self.setDoor(se, "dfd")
self.assertTrue(se["Door"], "dfd")
self.myAssertRaise(Exception, se.getMacroServer)
# self.myAssertRaise(Exception, se.getMacroServer)
self.assertEqual(se.getMacroServer(), msname)
self.myAssertRaise(Exception, self.setDoor, se, "module")
self.myAssertRaise(Exception, se.getMacroServer)
self.assertTrue(se["Door"], "module")
Expand Down
2 changes: 1 addition & 1 deletion test/Utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def test_getMacroServer(self):
[self._simps.new_device_info_writer.name, 'test/door/1'],
[self._simps.new_device_info_writer.name, 'test/door/2'],
[self._simps2.new_device_info_writer.name, 'test/door/3'],
["", 'test/door/4'],
[self._simps.new_device_info_writer.name, 'test/door/4'],
]

self._simps2.dp.DoorList = [
Expand Down

0 comments on commit 476c6ed

Please sign in to comment.