Esempio n. 1
0
 def test_higher_version(self, mock_upgrade, mock_get_cib):
     actual_cib, was_upgraded = lib.ensure_cib_version(
         self.mock_runner, self.cib, Version(2, 3, 3))
     self.assertEqual(self.cib, actual_cib)
     self.assertFalse(was_upgraded)
     mock_upgrade.assert_not_called()
     mock_get_cib.assert_not_called()
Esempio n. 2
0
File: env.py Progetto: junaruga/pcs
 def get_cib(self, minimal_version=None):
     if self.__loaded_cib_diff_source is not None:
         raise AssertionError("CIB has already been loaded")
     self.__loaded_cib_diff_source = get_cib_xml(self.cmd_runner())
     self.__loaded_cib_to_modify = get_cib(self.__loaded_cib_diff_source)
     if minimal_version is not None:
         upgraded_cib = ensure_cib_version(
             self.cmd_runner(),
             self.__loaded_cib_to_modify,
             minimal_version
         )
         if upgraded_cib is not None:
             self.__loaded_cib_to_modify = upgraded_cib
             self.__loaded_cib_diff_source = etree_to_str(upgraded_cib)
             if not self._cib_upgrade_reported:
                 self.report_processor.process(
                     reports.cib_upgrade_successful()
                 )
             self._cib_upgrade_reported = True
     self.__loaded_cib_diff_source_feature_set = (
         get_cib_crm_feature_set(
             self.__loaded_cib_to_modify,
             none_if_missing=True
         )
         or
         Version(0, 0, 0)
     )
     return self.__loaded_cib_to_modify
Esempio n. 3
0
 def get_cib(self, minimal_version=None):
     if self.__loaded_cib_diff_source is not None:
         raise AssertionError("CIB has already been loaded")
     self.__loaded_cib_diff_source = get_cib_xml(self.cmd_runner())
     self.__loaded_cib_to_modify = get_cib(self.__loaded_cib_diff_source)
     if minimal_version is not None:
         upgraded_cib = ensure_cib_version(
             self.cmd_runner(),
             self.__loaded_cib_to_modify,
             minimal_version
         )
         if upgraded_cib is not None:
             self.__loaded_cib_to_modify = upgraded_cib
             self.__loaded_cib_diff_source = etree_to_str(upgraded_cib)
             if not self._cib_upgrade_reported:
                 self.report_processor.process(
                     reports.cib_upgrade_successful()
                 )
             self._cib_upgrade_reported = True
     self.__loaded_cib_diff_source_feature_set = (
         get_cib_crm_feature_set(
             self.__loaded_cib_to_modify,
             none_if_missing=True
         )
         or
         Version(0, 0, 0)
     )
     return self.__loaded_cib_to_modify
Esempio n. 4
0
 def test_higher_version(self, mock_upgrade, mock_get_cib):
     self.assertTrue(
         lib.ensure_cib_version(
             self.mock_runner, self.cib, Version(2, 3, 3)
         ) is None
     )
     mock_upgrade.assert_not_called()
     mock_get_cib.assert_not_called()
Esempio n. 5
0
 def test_higher_version(self, mock_upgrade, mock_get_cib):
     self.assertTrue(
         lib.ensure_cib_version(
             self.mock_runner, self.cib, (2, 3, 3)
         ) is None
     )
     mock_upgrade.assert_not_called()
     mock_get_cib.assert_not_called()
Esempio n. 6
0
 def test_upgraded_higher_version(self, mock_upgrade, mock_get_cib):
     expected_cib = '<cib validate-with="pacemaker-2.3.6"/>'
     mock_get_cib.return_value = expected_cib
     actual_cib, was_upgraded = lib.ensure_cib_version(
         self.mock_runner, self.cib, Version(2, 3, 5))
     assert_xml_equal(expected_cib, etree.tostring(actual_cib).decode())
     self.assertTrue(was_upgraded)
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 7
0
 def test_upgraded_higher_version(self, mock_upgrade, mock_get_cib):
     upgraded_cib = '<cib validate-with="pacemaker-2.3.6"/>'
     mock_get_cib.return_value = upgraded_cib
     assert_xml_equal(
         upgraded_cib,
         etree.tostring(
             lib.ensure_cib_version(self.mock_runner, self.cib,
                                    Version(2, 3, 5))).decode())
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 8
0
 def test_cib_parse_error(self, mock_upgrade, mock_get_cib):
     mock_get_cib.return_value = "not xml"
     assert_raise_library_error(
         lambda: lib.ensure_cib_version(self.mock_runner, self.cib,
                                        Version(2, 3, 5)),
         (Severity.ERROR, report_codes.CIB_UPGRADE_FAILED, {
             "reason": start_tag_error_text(),
         }))
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 9
0
 def test_upgraded_lower_version(self, mock_upgrade, mock_get_cib):
     mock_get_cib.return_value = etree.tostring(self.cib).decode()
     assert_raise_library_error(
         lambda: lib.ensure_cib_version(self.mock_runner, self.cib,
                                        Version(2, 3, 5)),
         (Severity.ERROR,
          report_codes.CIB_UPGRADE_FAILED_TO_MINIMAL_REQUIRED_VERSION, {
              "required_version": "2.3.5",
              "current_version": "2.3.4"
          }))
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 10
0
 def get_cib(self, minimal_version=None):
     cib = get_cib(self._get_cib_xml())
     if minimal_version is not None:
         upgraded_cib = ensure_cib_version(self.cmd_runner(), cib,
                                           minimal_version)
         if upgraded_cib is not None:
             cib = upgraded_cib
             if self.is_cib_live and not self._cib_upgraded:
                 self.report_processor.process(
                     reports.cib_upgrade_successful())
             self._cib_upgraded = True
     return cib
Esempio n. 11
0
 def test_upgraded_higher_version(self, mock_upgrade, mock_get_cib):
     upgraded_cib = '<cib validate-with="pacemaker-2.3.6"/>'
     mock_get_cib.return_value = upgraded_cib
     assert_xml_equal(
         upgraded_cib,
         etree.tostring(
             lib.ensure_cib_version(
                 self.mock_runner, self.cib, (2, 3, 5)
             )
         ).decode()
     )
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 12
0
 def test_upgraded_lower_version_dont_fail(self, mock_upgrade, mock_get_cib):
     expected_cib = '<cib validate-with="pacemaker-2.3.4"/>'
     mock_get_cib.return_value = expected_cib
     actual_cib, was_upgraded = lib.ensure_cib_version(
         self.mock_runner,
         self.cib,
         Version(2, 3, 5),
         fail_if_version_not_met=False,
     )
     assert_xml_equal(expected_cib, etree.tostring(actual_cib).decode())
     self.assertFalse(was_upgraded)
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 13
0
 def get_cib(self, minimal_version=None):
     cib = get_cib(self._get_cib_xml())
     if minimal_version is not None:
         upgraded_cib = ensure_cib_version(
             self.cmd_runner(),
             cib,
             minimal_version
         )
         if upgraded_cib is not None:
             cib = upgraded_cib
             if self.is_cib_live and not self._cib_upgraded:
                 self.report_processor.process(
                     reports.cib_upgrade_successful()
                 )
             self._cib_upgraded = True
     return cib
Esempio n. 14
0
 def test_cib_parse_error(self, mock_upgrade, mock_get_cib):
     mock_get_cib.return_value = "not xml"
     assert_raise_library_error(
         lambda: lib.ensure_cib_version(
             self.mock_runner, self.cib, (2, 3, 5)
         ),
         (
             Severity.ERROR,
             report_codes.CIB_UPGRADE_FAILED,
             {
                 "reason":
                     "Start tag expected, '<' not found, line 1, column 1",
             }
         )
     )
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 15
0
 def test_upgraded_lower_version(self, mock_upgrade, mock_get_cib):
     mock_get_cib.return_value = etree.tostring(self.cib).decode()
     assert_raise_library_error(
         lambda: lib.ensure_cib_version(
             self.mock_runner, self.cib, (2, 3, 5)
         ),
         (
             Severity.ERROR,
             report_codes.CIB_UPGRADE_FAILED_TO_MINIMAL_REQUIRED_VERSION,
             {
                 "required_version": "2.3.5",
                 "current_version": "2.3.4"
             }
         )
     )
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 16
0
 def test_cib_parse_error(self, mock_upgrade, mock_get_cib):
     mock_get_cib.return_value = "not xml"
     assert_raise_library_error(
         lambda: lib.ensure_cib_version(
             self.mock_runner, self.cib, (2, 3, 5)
         ),
         (
             Severity.ERROR,
             report_codes.CIB_UPGRADE_FAILED,
             {
                 "reason":
                     start_tag_error_text(),
             }
         )
     )
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
Esempio n. 17
0
    def get_cib(
        self,
        minimal_version: Optional[Version] = None,
        nice_to_have_version: Optional[Version] = None,
    ) -> _Element:
        if self.__loaded_cib_diff_source is not None:
            raise AssertionError("CIB has already been loaded")

        self.__loaded_cib_diff_source = get_cib_xml(self.cmd_runner())
        self.__loaded_cib_to_modify = get_cib(self.__loaded_cib_diff_source)

        if (
            nice_to_have_version is not None
            and minimal_version is not None
            and minimal_version >= nice_to_have_version
        ):
            nice_to_have_version = None

        for version, mandatory in (
            (nice_to_have_version, False),
            (minimal_version, True),
        ):
            if version is not None:
                upgraded_cib, was_upgraded = ensure_cib_version(
                    self.cmd_runner(),
                    self.__loaded_cib_to_modify,
                    version,
                    fail_if_version_not_met=mandatory,
                )
                if was_upgraded:
                    self.__loaded_cib_to_modify = upgraded_cib
                    self.__loaded_cib_diff_source = etree_to_str(upgraded_cib)
                    if not self._cib_upgrade_reported:
                        self.report_processor.report(
                            ReportItem.info(
                                reports.messages.CibUpgradeSuccessful()
                            )
                        )
                    self._cib_upgrade_reported = True

        self.__loaded_cib_diff_source_feature_set = get_cib_crm_feature_set(
            self.__loaded_cib_to_modify, none_if_missing=True
        ) or Version(0, 0, 0)
        return self.__loaded_cib_to_modify
Esempio n. 18
0
File: env.py Progetto: nrwahl2/pcs
 def get_cib(self, minimal_version: Optional[Version] = None) -> Element:
     if self.__loaded_cib_diff_source is not None:
         raise AssertionError("CIB has already been loaded")
     self.__loaded_cib_diff_source = get_cib_xml(self.cmd_runner())
     self.__loaded_cib_to_modify = get_cib(self.__loaded_cib_diff_source)
     if minimal_version is not None:
         upgraded_cib = ensure_cib_version(self.cmd_runner(),
                                           self.__loaded_cib_to_modify,
                                           minimal_version)
         if upgraded_cib is not None:
             self.__loaded_cib_to_modify = upgraded_cib
             self.__loaded_cib_diff_source = etree_to_str(upgraded_cib)
             if not self._cib_upgrade_reported:
                 self.report_processor.report(
                     ReportItem.info(
                         reports.messages.CibUpgradeSuccessful()))
             self._cib_upgrade_reported = True
     self.__loaded_cib_diff_source_feature_set = get_cib_crm_feature_set(
         self.__loaded_cib_to_modify, none_if_missing=True) or Version(
             0, 0, 0)
     return self.__loaded_cib_to_modify