def perform(self, file_access, logger):
     try:
         hostname = socket.gethostname()
         # IMAT want it blank as they are not using ISOBUS
         if hostname == "NDXIMAT":
             ioc_name = "ILM200"
             change_macros_in_xml = ChangeMacrosInXML(file_access, logger)
             change_macros_in_xml.add_macro(ioc_name, Macro("USE_ISOBUS", "No"), "^(Yes|No)$", "Whether to use ISOBUS for communications (default: Yes)", "Yes")
         return 0
     except Exception as e:
         logger.error("Unable to perform upgrade, caught error: {}".format(e))
         return 1
예제 #2
0
 def perform(self, file_access, logger):
     try:
         hostname = socket.gethostname()
         ioc_name = "DFKPS"
         if hostname == "NDXEMU":
             change_macros_in_xml = ChangeMacrosInXML(file_access, logger)
             change_macros_in_xml.add_macro(
                 ioc_name, Macro("DISABLE_AUTOONOFF", "0"), "^(0|1)$",
                 "Disable automatic PSU on/off feature", "1")
             change_macros_in_xml.change_macros(
                 ioc_name, [(Macro("DISABLE_AUTOONOFF"),
                             Macro("DISABLE_AUTOONOFF", "0"))])
         return 0
     except Exception as e:
         logger.error(
             "Unable to perform upgrade, caught error: {}".format(e))
         return 1
예제 #3
0
class TestAddMacro(unittest.TestCase):
    def setUp(self):
        self.file_access = FileAccessStub()
        self.logger = LoggingStub()
        self.macro_changer = ChangeMacrosInXML(self.file_access, self.logger)

    def test_GIVEN_one_ioc_THEN_add_macro(self):
        # Given:
        xml = IOC_FILE_XML.format(iocs=create_galil_ioc(1, {"GALILADDR": "0", "MTRCTRL": "0"}))
        ioc_name = "GALIL"
        macro_to_add = Macro("TEST", "1")
        pattern = "^(0|1)$"
        description = "Test description"
        default = "0"

        self.file_access.open_file = Mock(return_value=xml)
        self.file_access.write_file = Mock()
        self.file_access.get_config_files = Mock(return_value=[("file1.xml", self.file_access.open_xml_file(None))])

        # When:
        self.macro_changer.add_macro(ioc_name, macro_to_add, pattern, description, default)

        # Then:
        written_xml = ET.fromstring(self.file_access.write_file_contents)
        result_galiladdr = written_xml.findall(".//ns:macros/*[@name='GALILADDR']", {"ns": NAMESPACE})
        result_mtrctrl = written_xml.findall(".//ns:macros/*[@name='MTRCTRL']", {"ns": NAMESPACE})
        result_test = written_xml.findall(".//ns:macros/*[@name='TEST']", {"ns": NAMESPACE})

        assert_that(result_galiladdr, has_length(1), "changed macro count")
        assert_that(result_galiladdr[0].get("name"), is_("GALILADDR"))
        assert_that(result_galiladdr[0].get("value"), is_("0"))

        assert_that(result_mtrctrl, has_length(1), "changed macro count")
        assert_that(result_mtrctrl[0].get("name"), is_("MTRCTRL"))
        assert_that(result_mtrctrl[0].get("value"), is_("0"))

        assert_that(result_test, has_length(1), "changed macro count")
        assert_that(result_test[0].get("name"), is_(macro_to_add.name))
        assert_that(result_test[0].get("value"), is_(macro_to_add.value))

    def test_GIVEN_one_ioc_that_already_has_macro_THEN_dont_add_macro(self):
        # Given:
        xml = IOC_FILE_XML.format(iocs=create_galil_ioc(1, {"GALILADDR": "0", "MTRCTRL": "0", "TEST": "0"}))
        ioc_name = "GALIL"
        macro_to_add = Macro("TEST", "1")
        pattern = "^(0|1)$"
        description = "Test description"
        default = "0"

        self.file_access.open_file = Mock(return_value=xml)
        self.file_access.write_file = Mock()
        self.file_access.get_config_files = Mock(return_value=[("file1.xml", self.file_access.open_xml_file(None))])

        # When:
        self.macro_changer.add_macro(ioc_name, macro_to_add, pattern, description, default)

        # Then:
        written_xml = ET.fromstring(self.file_access.write_file_contents)
        result_galiladdr = written_xml.findall(".//ns:macros/*[@name='GALILADDR']", {"ns": NAMESPACE})
        result_mtrctrl = written_xml.findall(".//ns:macros/*[@name='MTRCTRL']", {"ns": NAMESPACE})
        result_test = written_xml.findall(".//ns:macros/*[@name='TEST']", {"ns": NAMESPACE})

        assert_that(result_galiladdr, has_length(1), "changed macro count")
        assert_that(result_galiladdr[0].get("name"), is_("GALILADDR"))
        assert_that(result_galiladdr[0].get("value"), is_("0"))

        assert_that(result_mtrctrl, has_length(1), "changed macro count")
        assert_that(result_mtrctrl[0].get("name"), is_("MTRCTRL"))
        assert_that(result_mtrctrl[0].get("value"), is_("0"))

        assert_that(result_test, has_length(1), "changed macro count")
        assert_that(result_test[0].get("name"), is_("TEST"))
        assert_that(result_test[0].get("value"), is_("0"))