def test_nvset_not_found(self): self.config.runner.cib.load( filename="cib-empty-1.2.xml", optional_in_conf=f""" <{self.tag}> <meta_attributes id="set1" /> <instance_attributes id="set2" /> <not_an_nvset id="set3" /> <meta_attributes id="set4" /> <instance_attributes id="set5" /> </{self.tag}> """, ) self.env_assist.assert_raise_library_error( lambda: self.command( self.env_assist.get_env(), ["set2", "set3", "setX"] ) ) self.env_assist.assert_reports( [ fixture.report_unexpected_element( "set3", "not_an_nvset", ["options set"] ), fixture.report_not_found( "setX", context_type=self.tag, expected_types=["options set"], ), ] )
def test_success(self): xml = etree.fromstring( """ <parent> <meta_attributes id="set1" /> <instance_attributes id="set2" /> <not_an_nvset id="set3" /> <meta_attributes id="set4" /> </parent> """ ) element_list, report_list = nvpair_multi.find_nvsets_by_ids( xml, ["set1", "set2", "set3", "setX"] ) self.assertEqual( ["set1", "set2"], [el.get("id") for el in element_list], ) assert_report_item_list_equal( report_list, [ fixture.report_unexpected_element( "set3", "not_an_nvset", ["options set"] ), fixture.report_not_found( "setX", context_type="parent", expected_types=["options set"], ), ], )
def test_not_a_tag_id(self): self.env_assist.assert_raise_library_error( lambda: cmd_tag.config(self.env_assist.get_env(), ["id1"])) self.env_assist.assert_reports([ fixture.report_unexpected_element( "id1", "primitive", expected_types=["tag"], ), ])
def test_add_ids_errors(self): assert_report_item_list_equal( self._validate( "tag", [ "new1", "new1", "none", "none", "other_id", "other_id", "e1", "e1", "status_id", "status_id", "e2", "e2", ], [], ), [ fixture.error( reports.codes.TAG_ADD_REMOVE_IDS_DUPLICATION, duplicate_ids_list=[ "e1", "e2", "new1", "none", "other_id", "status_id", ], add_or_not_remove=True, ), fixture.report_not_found( "none", context_type="resources", expected_types=self.OBJ_REF_EXPECTED_TYPES, ), fixture.report_unexpected_element( "other_id", "meta_attributes", self.OBJ_REF_EXPECTED_TYPES ), fixture.report_not_found( "status_id", context_type="resources", expected_types=self.OBJ_REF_EXPECTED_TYPES, ), fixture.error( # pylint: disable=line-too-long reports.codes.TAG_CANNOT_ADD_REFERENCE_IDS_ALREADY_IN_THE_TAG, idref_list=["e1", "e2"], tag_id="tag", ), ], )
def fixture_unexpected_element_reports(id_list, expected_types=None): return [ fixture.report_unexpected_element( _id, ValidateCommonTestData.id_to_context_type_map[_id], expected_types=["bundle", "clone", "group", "master", "primitive",] if expected_types is None else expected_types, ) for _id in id_list ]
def test_not_tag_ids(self): self.config.runner.cib.load( resources=fixture_resources_for_ids(), tags=fixture_tags_xml(TAG_DEFINITIONS), ) self.env_assist.assert_raise_library_error( lambda: cmd_tag.remove(self.env_assist.get_env(), ["id1", "id2"])) self.env_assist.assert_reports([ fixture.report_unexpected_element( _id, "primitive", expected_types=["tag"], ) for _id in ["id1", "id2"] ])
def test_not_existing_tag_id_and_bad_add_ids(self): assert_report_item_list_equal( self._validate("none_tag", ["none", "other_id"], []), [ fixture.report_not_found( "none_tag", context_type="tags", expected_types=["tag"], ), fixture.report_not_found( "none", context_type="resources", expected_types=self.OBJ_REF_EXPCTED_TYPES, ), fixture.report_unexpected_element( "other_id", "node_state", self.OBJ_REF_EXPCTED_TYPES ), ], )
def test_mixed_ids(self): self.config.runner.cib.load( resources=fixture_resources_for_ids(), tags=fixture_tags_xml(TAG_DEFINITIONS), ) self.env_assist.assert_raise_library_error(lambda: cmd_tag.remove( self.env_assist.get_env(), ["tag1", "nonexistent_tag1", "id1"], )) self.env_assist.assert_reports([ fixture.report_not_found( "nonexistent_tag1", expected_types=["tag"], context_type="tags", ), fixture.report_unexpected_element( "id1", "primitive", expected_types=["tag"], ), ])
def test_tag_id_not_a_tag(self): assert_report_item_list_equal( self._validate("new1", ["new1"], ["none"], adjacent="none"), [fixture.report_unexpected_element("new1", "primitive", ["tag"])], )