From 476c6edfaaabeb608f36df7ed577cc1595c35929 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Thu, 21 Sep 2023 12:41:02 +0200 Subject: [PATCH] improve the implementation --- nxsrecconfig/ProfileManager.py | 13 +++ nxsrecconfig/Selector.py | 6 +- nxsrecconfig/Utils.py | 6 +- test/MacroServerPools_test.py | 142 ++++++++++++++++++++++++--------- test/Selector_test.py | 13 ++- test/Utils_test.py | 2 +- 6 files changed, 134 insertions(+), 48 deletions(-) diff --git a/nxsrecconfig/ProfileManager.py b/nxsrecconfig/ProfileManager.py index a86d710..15df68f 100644 --- a/nxsrecconfig/ProfileManager.py +++ b/nxsrecconfig/ProfileManager.py @@ -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() diff --git a/nxsrecconfig/Selector.py b/nxsrecconfig/Selector.py index af8ef33..2fa0bd1 100644 --- a/nxsrecconfig/Selector.py +++ b/nxsrecconfig/Selector.py @@ -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 diff --git a/nxsrecconfig/Utils.py b/nxsrecconfig/Utils.py index 41545ce..eb52fde 100644 --- a/nxsrecconfig/Utils.py +++ b/nxsrecconfig/Utils.py @@ -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` """ @@ -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 diff --git a/test/MacroServerPools_test.py b/test/MacroServerPools_test.py index e26608d..fc51999 100644 --- a/test/MacroServerPools_test.py +++ b/test/MacroServerPools_test.py @@ -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, "") @@ -1058,8 +1061,11 @@ 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, "") @@ -1067,11 +1073,17 @@ def test_getMacroServer(self): 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 @@ -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, "") @@ -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, "") @@ -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 @@ -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, "") @@ -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, "") @@ -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() @@ -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, "") @@ -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, "") @@ -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() diff --git a/test/Selector_test.py b/test/Selector_test.py index 090d152..542d744 100644 --- a/test/Selector_test.py +++ b/test/Selector_test.py @@ -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, "") @@ -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") diff --git a/test/Utils_test.py b/test/Utils_test.py index 104467c..5648aaf 100644 --- a/test/Utils_test.py +++ b/test/Utils_test.py @@ -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 = [