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
def __main_push_cib_diff(self, cmd_runner): cib_diff_xml = diff_cibs_xml( cmd_runner, self.report_processor, self.__loaded_cib_diff_source, etree_to_str(self.__loaded_cib_to_modify) ) if cib_diff_xml: push_cib_diff_xml(cmd_runner, cib_diff_xml)
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 return self.__loaded_cib_to_modify
def test_remove_refs_from_multiple_tags_without_removing_tag(self): lib.remove_obj_ref(get_elements_by_ids(self.cib, ["ref4", "ref5"])) assert_xml_equal( """ <tags> <tag id="tag-A"> <obj_ref id="ref1"/> <obj_ref id="ref2"/> <obj_ref id="ref3"/> </tag> <tag id="tag-B"> <obj_ref id="common"/> </tag> <tag id="tag-C"> <obj_ref id="common"/> </tag> </tags> """, etree_to_str(self.cib), )
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( 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
def test_move_both_new_and_existing_before(self): el_list = [ self.new_list[1], self.existing_list[0], self.new_list[0], self.existing_list[2], ] lib.add_obj_ref(self.tag_el, el_list, self.existing_list[1]) assert_xml_equal( """ <tag> <obj_ref id="b"/> <obj_ref id="e1"/> <obj_ref id="a"/> <obj_ref id="e3"/> <obj_ref id="e2"/> </tag> """, etree_to_str(self.tag_el), )
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 return self.__loaded_cib_to_modify
def simulate_cib(runner, cib): """ Run crm_simulate to get effects the cib would have on the live cluster CommandRunner runner -- runner etree cib -- cib tree to simulate """ cib_xml = etree_to_str(cib) try: plaintext_result, transitions_xml, new_cib_xml = simulate_cib_xml( runner, cib_xml ) return ( plaintext_result.strip(), xml_fromstring(transitions_xml), xml_fromstring(new_cib_xml), ) except (etree.XMLSyntaxError, etree.DocumentInvalid) as e: raise LibraryError( ReportItem.error(reports.messages.CibSimulateError(str(e))) ) from e
def replace_cib_configuration(runner, tree): return replace_cib_configuration_xml(runner, etree_to_str(tree))
def __main_push_cib_diff(self, cmd_runner): cib_diff_xml = diff_cibs_xml(cmd_runner, self.report_processor, self.__loaded_cib_diff_source, etree_to_str(self.__loaded_cib_to_modify)) if cib_diff_xml: push_cib_diff_xml(cmd_runner, cib_diff_xml)
def test_remove_empty_list(self): lib.remove_obj_ref([]) assert_xml_equal(FIXTURE_OBJ_REFS, etree_to_str(self.cib))
def test_remove_more_tags(self): lib.remove_tag(elem for elem in get_tags(self.cib)) assert_xml_equal( "<cib><configuration><tags/></configuration></cib>", etree_to_str(self.cib), )
def test_remove_empty_list(self): lib.remove_tag([]) assert_xml_equal(FIXTURE_TWO_TAGS, etree_to_str(self.cib))
def assert_cib_equal(self, expected_cib): assert_xml_equal(expected_cib, etree_to_str(self.cib))
def test_remove_a_tag(self): lib.remove_tag(elem for elem in get_tags(self.cib) if elem.get("id") == "second_tag") assert_xml_equal(FIXTURE_ONE_TAG, etree_to_str(self.cib))