예제 #1
0
파일: test_tag.py 프로젝트: CtrlZmaster/pcs
 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))
예제 #2
0
파일: test_tag.py 프로젝트: CtrlZmaster/pcs
 def _validate(self, tag, to_add, to_remove, adjacent=None):
     return lib.ValidateTagUpdateByIds(
         tag,
         to_add,
         to_remove,
         adjacent_idref=adjacent,
     ).validate(get_resources(self.test_cib), get_tags(self.test_cib))
예제 #3
0
파일: tag.py 프로젝트: zht750808/pcs
def config(
    env: LibraryEnvironment,
    tag_filter: Sequence[str],
) -> Iterable[Dict[str, Iterable[str]]]:
    """
    Get tags specified in tag_filter or if empty, then get all the tags
    configured.

    env -- provides all for communication with externals
    tag_filter -- list of tags we want to get
    """
    tags_section: _Element = get_tags(env.get_cib(REQUIRED_CIB_VERSION))
    if tag_filter:
        tag_element_list, report_list = tag.find_tag_elements_by_ids(
            tags_section,
            tag_filter,
        )
        if env.report_processor.report_list(report_list).has_errors:
            raise LibraryError()
    else:
        tag_element_list = tag.get_list_of_tag_elements(tags_section)
    return [
        tag.tag_element_to_dict(tag_element)
        for tag_element in tag_element_list
    ]
예제 #4
0
파일: test_tag.py 프로젝트: ldming/pcs
 def test_success(self):
     element_list = lib.get_list_of_tag_elements(get_tags(self.test_tree))
     self.assertEqual(
         [lib.tag_element_to_dict(element) for element in element_list],
         [
             {"tag_id": "first_tag", "idref_list": ["idref1", "idref2"],},
             {
                 "tag_id": "second_tag",
                 "idref_list": ["ref1", "ref2", "ref3"],
             },
         ],
     )
예제 #5
0
파일: test_tools.py 프로젝트: ldming/pcs
 def test_success_if_missing(self):
     tags_el = lib.get_tags(self.cib.tree)
     self.assertEqual("tags", tags_el.tag)
     self.assertEqual("configuration", tags_el.getparent().tag)
예제 #6
0
파일: test_tools.py 프로젝트: ldming/pcs
 def test_success_if_exists(self):
     self.cib.append_to_first_tag_name("configuration", "<tags/>")
     self.assertEqual("tags", lib.get_tags(self.cib.tree).tag)
예제 #7
0
파일: test_tag.py 프로젝트: CtrlZmaster/pcs
 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),
     )
예제 #8
0
파일: test_tag.py 프로젝트: CtrlZmaster/pcs
class ValidateCommonTestData(TestCase):
    tag_id = "tag_id"
    resource_ids = ["id-01", "id-02", "id-03"]
    nonresource_ids = ["no1", "no2"]
    nonexistent_ids = ["nonexistent1", "nonexistent2"]
    nonexistent_tags = ["nonexistent_tag1", "nonexistent_tag2"]
    existent_tags = ["first_tag", "second_tag"]
    id_to_context_type_map = {
        "no1": "rsc_location",
        "no2": "resources",
        "nonexistent1": "resources",
        "nonexistent2": "resources",
        "#invalid-tag-id": "resources",
        "tag_id": "resources",
        "nonexistent_tag1": "tags",
        "nonexistent_tag2": "tags",
    }
    test_tree = etree.fromstring(
        """
        <cib>
          <configuration>
            <resources>
              <primitive id="{resource_ids[0]}"/>
              <group id="G">
                <primitive id="{resource_ids[1]}"/>
              </group>
              <clone id="C">
                <primitive id="{resource_ids[2]}"/>
              </clone>
            </resources>
            <constraints>
              <rsc_location id="{nonresource_ids[0]}"/>
            </constraints>
            <tags>
              <tag id="{tags[0]}">
                <obj_ref id="idref1"/>
                <obj_ref id="idref2"/>
              </tag>
              <tag id="{tags[1]}">
                <obj_ref id="ref1"/>
                <obj_ref id="ref2"/>
                <obj_ref id="ref3"/>
              </tag>
            </tags>
          </configuration>
          <status>
            <node_state id="{nonresource_ids[1]}"/>
          </status>
        </cib>
        """.format(
            resource_ids=resource_ids,
            tags=existent_tags,
            nonresource_ids=nonresource_ids,
        )
    )
    tags_section = get_tags(test_tree)
    resources_section = get_resources(test_tree)
    id_provider = IdProvider(tags_section)

    def get_tag_elements(self, id_list):
        return [
            element
            for element in self.tags_section.findall("tag")
            if element.get("id", default="") in id_list
        ]
예제 #9
0
파일: test_tag.py 프로젝트: CtrlZmaster/pcs
 def call_create_tag(self, tag_with_refs):
     lib.create_tag(
         get_tags(self.cib),
         tag_with_refs.tag_id,
         tag_with_refs.idref_list,
     )
예제 #10
0
파일: tag.py 프로젝트: zht750808/pcs
def cib_tags_section(env: LibraryEnvironment) -> Iterator[_Element]:
    yield get_tags(env.get_cib(REQUIRED_CIB_VERSION))
    env.push_cib()
예제 #11
0
def cib_tags_section(env: LibraryEnvironment) -> Iterator[_Element]:
    yield get_tags(env.get_cib())
    env.push_cib()