예제 #1
0
파일: test_utils.py 프로젝트: krig/pcs
    def testDomGetResources(self):
        def test_dom_get(method, dom, ok_ids, bad_ids):
            for element_id in ok_ids:
                self.assert_element_id(method(dom, element_id), element_id)
            for element_id in bad_ids:
                self.assertFalse(method(dom, element_id))

        cib_dom = self.get_cib_empty()
        self.assertFalse(utils.dom_get_resource(cib_dom, "myResource"))
        self.assertFalse(
            utils.dom_get_resource_clone(cib_dom, "myClonedResource")
        )
        self.assertFalse(
            utils.dom_get_resource_masterslave(cib_dom, "myMasteredResource")
        )
        self.assertFalse(utils.dom_get_group(cib_dom, "myGroup"))
        self.assertFalse(utils.dom_get_group_clone(cib_dom, "myClonedGroup"))
        self.assertFalse(
            utils.dom_get_group_masterslave(cib_dom, "myMasteredGroup")
        )
        self.assertFalse(utils.dom_get_clone(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_master(cib_dom, "myMaster"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myMaster"))
        self.assertFalse(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myClonedResource")
        )
        self.assertFalse(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myMasteredResource")
        )

        cib_dom = self.get_cib_resources()
        all_ids = set([
            "none", "myResource",
            "myClone", "myClonedResource",
            "myMaster", "myMasteredResource",
            "myGroup", "myGroupedResource",
            "myGroupClone", "myClonedGroup", "myClonedGroupedResource",
            "myGroupMaster", "myMasteredGroup", "myMasteredGroupedResource",
        ])

        resource_ids = set([
            "myResource",
            "myClonedResource", "myGroupedResource", "myMasteredResource",
            "myClonedGroupedResource", "myMasteredGroupedResource"
        ])
        test_dom_get(
            utils.dom_get_resource, cib_dom,
            resource_ids, all_ids - resource_ids
        )

        cloned_ids = set(["myClonedResource", "myClonedGroupedResource"])
        test_dom_get(
            utils.dom_get_resource_clone, cib_dom,
            cloned_ids, all_ids - cloned_ids
        )

        mastered_ids = set(["myMasteredResource", "myMasteredGroupedResource"])
        test_dom_get(
            utils.dom_get_resource_masterslave, cib_dom,
            mastered_ids, all_ids - mastered_ids
        )

        group_ids = set(["myGroup", "myClonedGroup", "myMasteredGroup"])
        test_dom_get(
            utils.dom_get_group, cib_dom, group_ids, all_ids - group_ids
        )

        cloned_group_ids = set(["myClonedGroup"])
        test_dom_get(
            utils.dom_get_group_clone, cib_dom,
            cloned_group_ids, all_ids - cloned_group_ids
        )

        clone_ids = set(["myClone", "myGroupClone"])
        test_dom_get(
            utils.dom_get_clone, cib_dom,
            clone_ids, all_ids - clone_ids
        )

        mastered_group_ids = set(["myMasteredGroup"])
        test_dom_get(
            utils.dom_get_group_masterslave, cib_dom,
            mastered_group_ids, all_ids - mastered_group_ids
        )

        master_ids = set(["myMaster", "myGroupMaster"])
        test_dom_get(
            utils.dom_get_master, cib_dom,
            master_ids, all_ids - master_ids
        )


        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myClone"),
            "myClonedResource"
        )
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupClone"),
            "myClonedGroup"
        )
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myMaster"),
            "myMasteredResource"
        )
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupMaster"),
            "myMasteredGroup"
        )

        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myClonedResource"),
            "myClone"
        )
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myClonedGroup"),
            "myGroupClone"
        )
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(
                cib_dom, "myClonedGroupedResource"
            ),
            "myGroupClone"
        )
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(
                cib_dom, "myMasteredResource"
            ),
            "myMaster"
        )
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(
                cib_dom, "myMasteredGroup"
            ),
            "myGroupMaster"
        )
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(
                cib_dom, "myMasteredGroupedResource"
            ),
            "myGroupMaster"
        )
        self.assertEquals(
            None,
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myResource")
        )
        self.assertEquals(
            None,
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myGroup")
        )
        self.assertEquals(
            None,
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myGroupedResource")
        )
예제 #2
0
    def testDomGetResources(self):
        def test_dom_get(method, dom, ok_ids, bad_ids):
            for element_id in ok_ids:
                self.assert_element_id(method(dom, element_id), element_id)
            for element_id in bad_ids:
                self.assertFalse(method(dom, element_id))

        cib_dom = self.get_cib_empty()
        self.assertFalse(utils.dom_get_resource(cib_dom, "myResource"))
        self.assertFalse(
            utils.dom_get_resource_clone(cib_dom, "myClonedResource"))
        self.assertFalse(
            utils.dom_get_resource_masterslave(cib_dom, "myMasteredResource"))
        self.assertFalse(utils.dom_get_group(cib_dom, "myGroup"))
        self.assertFalse(utils.dom_get_group_clone(cib_dom, "myClonedGroup"))
        self.assertFalse(
            utils.dom_get_group_masterslave(cib_dom, "myMasteredGroup"))
        self.assertFalse(utils.dom_get_clone(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_master(cib_dom, "myMaster"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myMaster"))
        self.assertFalse(
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myClonedResource"))
        self.assertFalse(
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myMasteredResource"))

        cib_dom = self.get_cib_resources()
        all_ids = set([
            "none",
            "myResource",
            "myClone",
            "myClonedResource",
            "myMaster",
            "myMasteredResource",
            "myGroup",
            "myGroupedResource",
            "myGroupClone",
            "myClonedGroup",
            "myClonedGroupedResource",
            "myGroupMaster",
            "myMasteredGroup",
            "myMasteredGroupedResource",
        ])

        resource_ids = set([
            "myResource", "myClonedResource", "myGroupedResource",
            "myMasteredResource", "myClonedGroupedResource",
            "myMasteredGroupedResource"
        ])
        test_dom_get(utils.dom_get_resource, cib_dom, resource_ids,
                     all_ids - resource_ids)

        cloned_ids = set(["myClonedResource", "myClonedGroupedResource"])
        test_dom_get(utils.dom_get_resource_clone, cib_dom, cloned_ids,
                     all_ids - cloned_ids)

        mastered_ids = set(["myMasteredResource", "myMasteredGroupedResource"])
        test_dom_get(utils.dom_get_resource_masterslave, cib_dom, mastered_ids,
                     all_ids - mastered_ids)

        group_ids = set(["myGroup", "myClonedGroup", "myMasteredGroup"])
        test_dom_get(utils.dom_get_group, cib_dom, group_ids,
                     all_ids - group_ids)

        cloned_group_ids = set(["myClonedGroup"])
        test_dom_get(utils.dom_get_group_clone, cib_dom, cloned_group_ids,
                     all_ids - cloned_group_ids)

        clone_ids = set(["myClone", "myGroupClone"])
        test_dom_get(utils.dom_get_clone, cib_dom, clone_ids,
                     all_ids - clone_ids)

        mastered_group_ids = set(["myMasteredGroup"])
        test_dom_get(utils.dom_get_group_masterslave, cib_dom,
                     mastered_group_ids, all_ids - mastered_group_ids)

        master_ids = set(["myMaster", "myGroupMaster"])
        test_dom_get(utils.dom_get_master, cib_dom, master_ids,
                     all_ids - master_ids)

        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myClone"),
            "myClonedResource")
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupClone"),
            "myClonedGroup")
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myMaster"),
            "myMasteredResource")
        self.assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupMaster"),
            "myMasteredGroup")

        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myClonedResource"),
            "myClone")
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myClonedGroup"),
            "myGroupClone")
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myClonedGroupedResource"),
            "myGroupClone")
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myMasteredResource"),
            "myMaster")
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myMasteredGroup"),
            "myGroupMaster")
        self.assert_element_id(
            utils.dom_get_resource_clone_ms_parent(
                cib_dom, "myMasteredGroupedResource"), "myGroupMaster")
        self.assertEquals(
            None,
            utils.dom_get_resource_clone_ms_parent(cib_dom, "myResource"))
        self.assertEquals(
            None, utils.dom_get_resource_clone_ms_parent(cib_dom, "myGroup"))
        self.assertEquals(
            None,
            utils.dom_get_resource_clone_ms_parent(cib_dom,
                                                   "myGroupedResource"))
예제 #3
0
파일: test_utils.py 프로젝트: BoydYang/pcs
    def testDomGetResources(self):
        def assert_element_id(node, node_id):
            self.assertTrue(
                isinstance(node, xml.dom.minidom.Element),
                "element with id '%s' not found" % node_id
            )
            self.assertEquals(node.getAttribute("id"), node_id)

        def test_dom_get(method, dom, ok_ids, bad_ids):
            for element_id in ok_ids:
                assert_element_id(method(dom, element_id), element_id)
            for element_id in bad_ids:
                self.assertFalse(method(dom, element_id))

        cib_dom = xml.dom.minidom.parse("empty.xml")
        self.assertFalse(utils.dom_get_resource(cib_dom, "myResource"))
        self.assertFalse(
            utils.dom_get_resource_clone(cib_dom, "myClonedResource")
        )
        self.assertFalse(
            utils.dom_get_resource_masterslave(cib_dom, "myMasteredResource")
        )
        self.assertFalse(utils.dom_get_group(cib_dom, "myGroup"))
        self.assertFalse(utils.dom_get_group_clone(cib_dom, "myClonedGroup"))
        self.assertFalse(utils.dom_get_clone(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_master(cib_dom, "myMaster"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myMaster"))

        new_resources = xml.dom.minidom.parseString("""
            <resources>
                  <primitive id="myResource"
                        class="ocf" provider="heartbeat" type="Dummy">
                  </primitive>
                  <clone id="myClone">
                      <primitive id="myClonedResource"
                          class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </clone>
                  <master id="myMaster">
                      <primitive id="myMasteredResource"
                            class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </master>
                  <group id="myGroup">
                      <primitive id="myGroupedResource"
                            class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </group>
                  <clone id="myGroupClone">
                      <group id="myClonedGroup">
                          <primitive id="myClonedGroupedResource"
                                class="ocf" provider="heartbeat" type="Dummy">
                          </primitive>
                      </group>
                  </clone>
                  <master id="myGroupMaster">
                      <group id="myMasteredGroup">
                          <primitive id="myMasteredGroupedResource"
                                class="ocf" provider="heartbeat" type="Dummy">
                          </primitive>
                      </group>
                  </master>
            </resources>
        """).documentElement
        resources = cib_dom.getElementsByTagName("resources")[0]
        resources.parentNode.replaceChild(new_resources, resources)

        all_ids = set([
            "none", "myResource",
            "myClone", "myClonedResource",
            "myMaster", "myMasteredResource",
            "myGroup", "myGroupedResource",
            "myGroupClone", "myClonedGroup", "myClonedGroupedResource",
            "myGroupMaster", "myMasteredGroup", "myMasteredGroupedResource",
        ])

        resource_ids = set([
            "myResource",
            "myClonedResource", "myGroupedResource", "myMasteredResource",
            "myClonedGroupedResource", "myMasteredGroupedResource"
        ])
        test_dom_get(
            utils.dom_get_resource, cib_dom,
            resource_ids, all_ids - resource_ids
        )

        cloned_ids = set(["myClonedResource", "myClonedGroupedResource"])
        test_dom_get(
            utils.dom_get_resource_clone, cib_dom,
            cloned_ids, all_ids - cloned_ids
        )

        mastered_ids = set(["myMasteredResource", "myMasteredGroupedResource"])
        test_dom_get(
            utils.dom_get_resource_masterslave, cib_dom,
            mastered_ids, all_ids - mastered_ids
        )

        group_ids = set(["myGroup", "myClonedGroup", "myMasteredGroup"])
        test_dom_get(
            utils.dom_get_group, cib_dom, group_ids, all_ids - group_ids
        )

        cloned_group_ids = set(["myClonedGroup"])
        test_dom_get(
            utils.dom_get_group_clone, cib_dom,
            cloned_group_ids, all_ids - cloned_group_ids
        )

        clone_ids = set(["myClone", "myGroupClone"])
        test_dom_get(
            utils.dom_get_clone, cib_dom,
            clone_ids, all_ids - clone_ids
        )

        master_ids = set(["myMaster", "myGroupMaster"])
        test_dom_get(
            utils.dom_get_master, cib_dom,
            master_ids, all_ids - master_ids
        )


        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myClone"),
            "myClonedResource"
        )
        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupClone"),
            "myClonedGroup"
        )
        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myMaster"),
            "myMasteredResource"
        )
        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupMaster"),
            "myMasteredGroup"
        )
예제 #4
0
파일: test_utils.py 프로젝트: vincepii/pcs
    def testDomGetResources(self):
        def assert_element_id(node, node_id):
            self.assertTrue(isinstance(node, xml.dom.minidom.Element),
                            "element with id '%s' not found" % node_id)
            self.assertEquals(node.getAttribute("id"), node_id)

        def test_dom_get(method, dom, ok_ids, bad_ids):
            for element_id in ok_ids:
                assert_element_id(method(dom, element_id), element_id)
            for element_id in bad_ids:
                self.assertFalse(method(dom, element_id))

        cib_dom = xml.dom.minidom.parse("empty.xml")
        self.assertFalse(utils.dom_get_resource(cib_dom, "myResource"))
        self.assertFalse(
            utils.dom_get_resource_clone(cib_dom, "myClonedResource"))
        self.assertFalse(
            utils.dom_get_resource_masterslave(cib_dom, "myMasteredResource"))
        self.assertFalse(utils.dom_get_group(cib_dom, "myGroup"))
        self.assertFalse(utils.dom_get_group_clone(cib_dom, "myClonedGroup"))
        self.assertFalse(utils.dom_get_clone(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_master(cib_dom, "myMaster"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myClone"))
        self.assertFalse(utils.dom_get_clone_ms_resource(cib_dom, "myMaster"))

        new_resources = xml.dom.minidom.parseString("""
            <resources>
                  <primitive id="myResource"
                        class="ocf" provider="heartbeat" type="Dummy">
                  </primitive>
                  <clone id="myClone">
                      <primitive id="myClonedResource"
                          class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </clone>
                  <master id="myMaster">
                      <primitive id="myMasteredResource"
                            class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </master>
                  <group id="myGroup">
                      <primitive id="myGroupedResource"
                            class="ocf" provider="heartbeat" type="Dummy">
                      </primitive>
                  </group>
                  <clone id="myGroupClone">
                      <group id="myClonedGroup">
                          <primitive id="myClonedGroupedResource"
                                class="ocf" provider="heartbeat" type="Dummy">
                          </primitive>
                      </group>
                  </clone>
                  <master id="myGroupMaster">
                      <group id="myMasteredGroup">
                          <primitive id="myMasteredGroupedResource"
                                class="ocf" provider="heartbeat" type="Dummy">
                          </primitive>
                      </group>
                  </master>
            </resources>
        """).documentElement
        resources = cib_dom.getElementsByTagName("resources")[0]
        resources.parentNode.replaceChild(new_resources, resources)

        all_ids = set([
            "none",
            "myResource",
            "myClone",
            "myClonedResource",
            "myMaster",
            "myMasteredResource",
            "myGroup",
            "myGroupedResource",
            "myGroupClone",
            "myClonedGroup",
            "myClonedGroupedResource",
            "myGroupMaster",
            "myMasteredGroup",
            "myMasteredGroupedResource",
        ])

        resource_ids = set([
            "myResource", "myClonedResource", "myGroupedResource",
            "myMasteredResource", "myClonedGroupedResource",
            "myMasteredGroupedResource"
        ])
        test_dom_get(utils.dom_get_resource, cib_dom, resource_ids,
                     all_ids - resource_ids)

        cloned_ids = set(["myClonedResource", "myClonedGroupedResource"])
        test_dom_get(utils.dom_get_resource_clone, cib_dom, cloned_ids,
                     all_ids - cloned_ids)

        mastered_ids = set(["myMasteredResource", "myMasteredGroupedResource"])
        test_dom_get(utils.dom_get_resource_masterslave, cib_dom, mastered_ids,
                     all_ids - mastered_ids)

        group_ids = set(["myGroup", "myClonedGroup", "myMasteredGroup"])
        test_dom_get(utils.dom_get_group, cib_dom, group_ids,
                     all_ids - group_ids)

        cloned_group_ids = set(["myClonedGroup"])
        test_dom_get(utils.dom_get_group_clone, cib_dom, cloned_group_ids,
                     all_ids - cloned_group_ids)

        clone_ids = set(["myClone", "myGroupClone"])
        test_dom_get(utils.dom_get_clone, cib_dom, clone_ids,
                     all_ids - clone_ids)

        master_ids = set(["myMaster", "myGroupMaster"])
        test_dom_get(utils.dom_get_master, cib_dom, master_ids,
                     all_ids - master_ids)

        assert_element_id(utils.dom_get_clone_ms_resource(cib_dom, "myClone"),
                          "myClonedResource")
        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupClone"),
            "myClonedGroup")
        assert_element_id(utils.dom_get_clone_ms_resource(cib_dom, "myMaster"),
                          "myMasteredResource")
        assert_element_id(
            utils.dom_get_clone_ms_resource(cib_dom, "myGroupMaster"),
            "myMasteredGroup")