Exemple #1
0
 def test_validation(self):
     resources_before = """
         <resources>
             <group id="G">
                 <primitive id="RG1" />
             </group>
             <primitive id="R1">
                 <meta_attributes id="R1-meta_attributes" />
             </primitive>
             <primitive id="R2">
                 <meta_attributes id="R2-meta_attributes" />
             </primitive>
             <clone id="RC1-clone">
                 <primitive id="RC1" />
             </clone>
         </resources>
     """
     (self.config.runner.cib.load(resources=resources_before))
     self.env_assist.assert_raise_library_error(
         lambda: resource.group_add(
             self.env_assist.get_env(),
             "R1-meta_attributes",
             ["R2", "R4", "R3", "R2-meta_attributes", "RC1-clone", "RC1"],
         )
     )
     self.env_assist.assert_reports(
         [
             fixture.error(
                 report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE,
                 id="R1-meta_attributes",
                 expected_types=["group"],
                 current_type="meta_attributes",
             ),
             fixture.report_not_found("R4", context_type="resources"),
             fixture.report_not_found("R3", context_type="resources"),
             fixture.error(
                 report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE,
                 id="R2-meta_attributes",
                 expected_types=[
                     "bundle",
                     "clone",
                     "group",
                     "master",
                     "primitive",
                 ],
                 current_type="meta_attributes",
             ),
             fixture.error(
                 report_codes.CANNOT_GROUP_RESOURCE_WRONG_TYPE,
                 resource_id="RC1-clone",
                 resource_type="clone",
             ),
             fixture.error(
                 report_codes.CANNOT_GROUP_RESOURCE_WRONG_TYPE,
                 resource_id="RC1",
                 resource_type="clone",
             ),
         ]
     )
 def test_missing_resources_specified(self):
     assert_report_item_list_equal(
         self._validate("G", ["RX1", "RX2"]),
         [
             fixture.report_not_found("RX1", context_type="resources"),
             fixture.report_not_found("RX2", context_type="resources"),
         ]
     )
Exemple #3
0
 def test_missing_resources_specified(self):
     assert_report_item_list_equal(
         self._validate("G", ["RX1", "RX2"]),
         [
             fixture.report_not_found("RX1", context_type="resources"),
             fixture.report_not_found("RX2", context_type="resources"),
         ],
     )
Exemple #4
0
 def test_validation(self):
     resources_before = """
         <resources>
             <group id="G">
                 <primitive id="RG1" />
             </group>
             <primitive id="R1">
                 <meta_attributes id="R1-meta_attributes" />
             </primitive>
             <primitive id="R2">
                 <meta_attributes id="R2-meta_attributes" />
             </primitive>
             <clone id="RC1-clone">
                 <primitive id="RC1" />
             </clone>
         </resources>
     """
     (self.config
         .runner.cib.load(resources=resources_before)
     )
     self.env_assist.assert_raise_library_error(
         lambda: resource.group_add(
             self.env_assist.get_env(),
             "R1-meta_attributes",
             ["R2", "R4", "R3", "R2-meta_attributes", "RC1-clone", "RC1"]
         ),
         [
             fixture.error(
                 report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE,
                 id="R1-meta_attributes",
                 expected_types=["group"],
                 current_type="meta_attributes",
             ),
             fixture.report_not_found("R4", context_type="resources"),
             fixture.report_not_found("R3", context_type="resources"),
             fixture.error(
                 report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE,
                 id="R2-meta_attributes",
                 expected_types=[
                     "clone", "master", "group", "primitive", "bundle"
                 ],
                 current_type="meta_attributes",
             ),
             fixture.error(
                 report_codes.CANNOT_GROUP_RESOURCE_WRONG_TYPE,
                 resource_id="RC1-clone",
                 resource_type="clone",
             ),
             fixture.error(
                 report_codes.CANNOT_GROUP_RESOURCE_WRONG_TYPE,
                 resource_id="RC1",
                 resource_type="clone",
             ),
         ],
     )
Exemple #5
0
 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",
             ),
         ],
     )
Exemple #6
0
 def test_more_some_missing(self):
     report_list = []
     resource_list = common.find_resources_and_report(
         self.cib, ["R1", "R2", "RY1", "RY2"], report_list)
     self.assertEqual(
         ["R1", "R2"],
         [resource.attrib.get("id") for resource in resource_list])
     assert_report_item_list_equal(report_list, [
         fixture.report_not_found("RY1", context_type="resources"),
         fixture.report_not_found("RY2", context_type="resources"),
     ])
Exemple #7
0
 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"],
             ),
         ]
     )
Exemple #8
0
 def test_multiple_errors(self):
     self.env_assist.assert_raise_library_error(
         lambda: cmd_tag.create(
             self.env_assist.get_env(),
             "",
             ["", ""],
         )
     )
     self.env_assist.assert_reports(
         [
             fixture.error(
                 reports.codes.INVALID_ID_IS_EMPTY,
                 id_description="id",
             ),
             fixture.error(reports.codes.TAG_CANNOT_CONTAIN_ITSELF),
             *[
                 fixture.report_not_found(_id, context_type="resources")
                 for _id in ["", ""]
             ],
             fixture.error(
                 reports.codes.TAG_ADD_REMOVE_IDS_DUPLICATION,
                 duplicate_ids_list=[""],
                 add_or_not_remove=True,
             ),
         ]
     )
Exemple #9
0
 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_resource_not_found(self):
     self.config.runner.cib.load(resources=resources_primitive)
     self.env_assist.assert_raise_library_error(
         lambda: self.lib_action(self.env_assist.get_env(), "B"))
     self.env_assist.assert_reports([
         fixture.report_not_found("B", context_type="resources"),
     ])
Exemple #11
0
 def test_one_nonexistant(self):
     report_list = []
     resource = common.find_one_resource_and_report(self.cib, "R-missing",
                                                    report_list)
     self.assertIsNone(resource)
     assert_report_item_list_equal(report_list, [
         fixture.report_not_found("R-missing", context_type="resources"),
     ])
 def test_resource_not_found(self):
     self.config.runner.cib.load(resources=resources_primitive)
     self.env_assist.assert_raise_library_error(
         lambda: self.lib_action(self.env_assist.get_env(), "B"),
         [
             fixture.report_not_found("B", context_type="resources"),
         ]
     )
Exemple #13
0
def fixture_id_not_found_reports(id_list, expected_types=None):
    return [
        fixture.report_not_found(
            _id,
            context_type=ValidateCommonTestData.id_to_context_type_map[_id],
            expected_types=expected_types,
        ) for _id in id_list
    ]
Exemple #14
0
 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_more_some_missing(self):
     report_list = []
     resource_list = common.find_resources_and_report(
         self.cib,
         ["R1", "R2", "RY1", "RY2"],
         report_list
     )
     self.assertEqual(
         ["R1", "R2"],
         [resource.attrib.get("id") for resource in resource_list]
     )
     assert_report_item_list_equal(
         report_list,
         [
             fixture.report_not_found("RY1", context_type="resources"),
             fixture.report_not_found("RY2", context_type="resources"),
         ]
     )
Exemple #16
0
 def test_not_existing_tag(self):
     assert_report_item_list_equal(
         self._validate("none_tag", ["e1"], []),
         [
             fixture.report_not_found(
                 "none_tag", context_type="tags", expected_types=["tag"],
             ),
         ],
     )
Exemple #17
0
 def test_not_existing_resource(self):
     self.config.runner.cib.load()
     resource_id = "not_existing"
     self.env_assist.assert_raise_library_error(
         lambda: resource.get_resource_relations_tree(
             self.env_assist.get_env(),
             resource_id,
         ))
     self.env_assist.assert_reports(
         [fixture.report_not_found(resource_id, context_type="resources")])
Exemple #18
0
 def test_defaults_section_missing(self):
     self.config.runner.cib.load(filename="cib-empty-1.2.xml")
     self.env_assist.assert_raise_library_error(
         lambda: self.command(self.env_assist.get_env(), ["set1"]))
     self.env_assist.assert_reports([
         fixture.report_not_found(
             "set1",
             context_type=self.tag,
             expected_types=["options set"],
         ),
     ])
Exemple #19
0
 def test_remove_all_and_add_missing_id(self):
     assert_report_item_list_equal(
         self._validate("tag", ["none"], ["e1", "e2", "e3"]),
         [
             fixture.report_not_found(
                 "none",
                 context_type="resources",
                 expected_types=self.OBJ_REF_EXPECTED_TYPES,
             ),
         ],
     )
Exemple #20
0
 def test_nonexistent_tag_ids(self):
     self.config.runner.cib.load(tags=fixture_tags_xml(TAG_DEFINITIONS))
     self.env_assist.assert_raise_library_error(lambda: cmd_tag.remove(
         self.env_assist.get_env(),
         ["nonexistent_tag1", "nonexistent_tag2"],
     ))
     self.env_assist.assert_reports([
         fixture.report_not_found(_id,
                                  expected_types=["tag"],
                                  context_type="tags")
         for _id in ["nonexistent_tag1", "nonexistent_tag2"]
     ])
Exemple #21
0
 def test_not_existing_tag_and_no_ids(self):
     assert_report_item_list_equal(
         self._validate("none_tag", [], []),
         [
             fixture.report_not_found(
                 "none_tag", context_type="tags", expected_types=["tag"],
             ),
             fixture.error(
                 reports.codes.TAG_CANNOT_UPDATE_TAG_NO_IDS_SPECIFIED,
             ),
         ],
     )
 def test_one_nonexistant(self):
     report_list = []
     resource = common.find_one_resource_and_report(
         self.cib,
         "R-missing",
         report_list
     )
     self.assertIsNone(resource)
     assert_report_item_list_equal(
         report_list,
         [
             fixture.report_not_found("R-missing", context_type="resources"),
         ]
     )
Exemple #23
0
 def test_not_tag_ids(self):
     element_list, report_list = self.call_find_elements_by_ids(
         self.nonresource_ids, )
     assert_report_item_list_equal(
         report_list,
         fixture_unexpected_element_reports(self.nonresource_ids[:1],
                                            expected_types=["tag"]) + [
                                                fixture.report_not_found(
                                                    self.nonresource_ids[1],
                                                    context_type="tags",
                                                    expected_types=["tag"],
                                                )
                                            ],
     )
     self.assertEqual(element_list, [])
Exemple #24
0
 def test_tag_id_does_not_exist(self):
     self.env_assist.assert_raise_library_error(lambda: cmd_tag.config(
         self.env_assist.get_env(),
         [
             "nonexistent_tag1",
             "tag2",
             "nonexistent_tag2",
         ],
     ))
     self.env_assist.assert_reports([
         fixture.report_not_found(_id,
                                  expected_types=["tag"],
                                  context_type="tags")
         for _id in ["nonexistent_tag1", "nonexistent_tag2"]
     ])
Exemple #25
0
 def test_nvset_doesnt_exist(self):
     self.config.runner.cib.load(
         optional_in_conf=self.fixture_initial_defaults())
     self.env_assist.assert_raise_library_error(lambda: self.command(
         self.env_assist.get_env(),
         "wrong-nvset-id",
         {},
     ))
     self.env_assist.assert_reports([
         fixture.report_not_found(
             "wrong-nvset-id",
             context_type=self.tag,
             expected_types=["options set"],
         ),
     ])
Exemple #26
0
 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"],
         ),
     ])