コード例 #1
0
 def test_success(self, mock_named_file):
     mock_file = mock.MagicMock()
     mock_file.name = "mock_file_name"
     mock_file.read.return_value = "<cib/>"
     mock_named_file.return_value = mock_file
     self.mock_runner.run.return_value = ("", "", 0)
     assert_xml_equal(
         "<cib/>",
         etree.tostring(
             lib.upgrade_cib(etree.XML("<old_cib/>"), self.mock_runner)
         ).decode()
     )
     mock_named_file.assert_called_once_with("w+", suffix=".pcs")
     mock_file.write.assert_called_once_with("<old_cib/>")
     mock_file.flush.assert_called_once_with()
     self.mock_runner.run.assert_called_once_with(
         [
             join(settings.pacemaker_binaries, "cibadmin"),
             "--upgrade",
             "--force"
         ],
         env_extend={"CIB_file": "mock_file_name"}
     )
     mock_file.seek.assert_called_once_with(0)
     mock_file.read.assert_called_once_with()
コード例 #2
0
ファイル: test_lib_env.py プロジェクト: HideoYamauchi/pcs
 def test_get_cluster_conf(self):
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     facade_obj = env.get_cluster_conf()
     self.assertTrue(isinstance(facade_obj, ClusterConfFacade))
     assert_xml_equal(
         '<cluster/>', etree.tostring(facade_obj._config).decode()
     )
コード例 #3
0
 def test_returns_cib_from_cib_data(self):
     cib_filename = "cib-empty.xml"
     (self.config
      #Value of cib_data is unimportant here. See details in sibling test.
      .env.set_cib_data("whatever").runner.cib.load(filename=cib_filename))
     assert_xml_equal(etree_to_str(self.env_assist.get_env().get_cib()),
                      open(rc(cib_filename)).read())
コード例 #4
0
 def test_not_useful_with_attributes(self):
     element = etree.Element("new", attr="test")
     lib.append_when_useful(self.parent, element, attribs_important=False)
     assert_xml_equal(
         self.tree_str,
         etree_to_str(self.tree)
     )
コード例 #5
0
ファイル: test_alert.py プロジェクト: HideoYamauchi/pcs
    def test_upgrade_needed(self, mock_ensure_cib_version):
        original_cib_xml = """
            <cib validate-with="pacemaker-2.4.1">
                <configuration>
                </configuration>
            </cib>
        """
        self.mock_env._push_cib_xml(original_cib_xml)
        mock_ensure_cib_version.return_value = etree.XML(
            """
            <cib validate-with="pacemaker-2.5.0">
                <configuration>
                </configuration>
            </cib>
            """
        )
        cmd_alert.create_alert(
            self.mock_env,
            "my-alert",
            "/my/path",
            {
                "instance": "value",
                "another": "val"
            },
            {"meta1": "val1"},
            "my description"
        )
        assert_xml_equal(
            """
<cib validate-with="pacemaker-2.5.0">
    <configuration>
        <alerts>
            <alert id="my-alert" path="/my/path" description="my description">
                <meta_attributes id="my-alert-meta_attributes">
                    <nvpair
                        id="my-alert-meta_attributes-meta1"
                        name="meta1"
                        value="val1"
                    />
                </meta_attributes>
                <instance_attributes id="my-alert-instance_attributes">
                    <nvpair
                        id="my-alert-instance_attributes-another"
                        name="another"
                        value="val"
                    />
                    <nvpair
                        id="my-alert-instance_attributes-instance"
                        name="instance"
                        value="value"
                    />
                </instance_attributes>
            </alert>
        </alerts>
    </configuration>
</cib>
            """,
            self.mock_env._get_cib_xml()
        )
        self.assertEqual(1, mock_ensure_cib_version.call_count)
コード例 #6
0
 def test_different_parent_not_useful(self):
     element = self.tree.find(".//element-B2")
     lib.append_when_useful(self.parent, element)
     assert_xml_equal(
         self.tree_str,
         etree_to_str(self.tree)
     )
コード例 #7
0
 def test_not_useful(self):
     element = etree.Element("new")
     lib.append_when_useful(self.parent, element)
     assert_xml_equal(
         self.tree_str,
         etree_to_str(self.tree)
     )
コード例 #8
0
 def test_already_appended(self):
     element = self.tree.find(".//element-A2")
     lib.append_when_useful(self.parent, element)
     assert_xml_equal(
         self.tree_str,
         etree_to_str(self.tree)
     )
コード例 #9
0
 def test_success(self):
     lib.remove_device_from_all_levels(self.tree, "d3")
     assert_xml_equal(
         """
         <fencing-topology>
             <fencing-level
                 id="fl1" index="1" devices="d1,d2" target="nodeA"
             />
             <fencing-level
                 id="fl3" index="1" devices="d2,d1" target="nodeB"
             />
             <fencing-level
                 id="fl5" index="1" devices="d4" target-pattern="node\d+"
             />
             <fencing-level
                 id="fl6" index="2" devices="d1" target-pattern="node\d+"
             />
             <fencing-level
                 id="fl7" index="3" devices="d4"
                 target-attribute="fencing" target-value="improved"
             />
             <fencing-level
                 id="fl8" index="4" devices="d5"
                 target-attribute="fencing" target-value="improved"
             />
             <fencing-level
                 id="fl9" index="3" devices="dR" target-pattern="node-R.*"
             />
             <fencing-level
                 id="fl10" index="4" devices="dR-special"
                 target-attribute="fencing" target-value="remote-special"
             />
         </fencing-topology>
         """, etree_to_str(self.tree))
コード例 #10
0
 def _assert_move_last_from_cloned_group(self, clone_type):
     # pylint: disable=no-self-use
     cib_before = f"""
         <resources>
             <group id="G">
                 <primitive id="RG1" />
                 <primitive id="RG2" />
                 <primitive id="RG3" />
             </group>
             <{clone_type} id="X-{clone_type}">
                 <group id="X">
                     <primitive id="R1" />
                 </group>
             </{clone_type}>
             <primitive id="R3" />
         </resources>
     """
     cib_after = """
         <resources>
             <group id="G">
                 <primitive id="RG1" />
                 <primitive id="RG2" />
                 <primitive id="RG3" />
                 <primitive id="R1" />
             </group>
             <primitive id="R3" />
         </resources>
     """
     cib = etree.fromstring(cib_before)
     relation.move_resources_to_group(
         _resource(cib, "G"),
         _resources(cib, "R1"),
     )
     assert_xml_equal(cib_after, etree_to_str(cib))
コード例 #11
0
ファイル: test_node.py プロジェクト: HideoYamauchi/pcs
 def test_node_missing_and_gets_created(self):
     assert_xml_equal(
         etree_to_str(
             node._ensure_node_exists(self.nodes, "name-test2", self.state)
         ),
         etree_to_str(self.node2)
     )
コード例 #12
0
    def test_remove_tickets_constraints_for_resource(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t1" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t3" ticket="tA" rsc="rA"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)

        self.assertTrue(
            ticket.remove_plain(
                constraint_section,
                ticket_key="tA",
                resource_id="rA",
            ))

        assert_xml_equal(
            etree.tostring(constraint_section).decode(), """
            <constraints>
                <rsc_ticket id="t2" ticket="tA" rsc="rB"/>
                <rsc_ticket id="t4" ticket="tB" rsc="rA"/>
                <rsc_ticket id="t5" ticket="tB" rsc="rB"/>
            </constraints>
        """)
コード例 #13
0
 def test_without_id(self):
     assert_xml_equal(
         '<recipient id="alert-recipient-1" value="value1"/>',
         etree.tostring(
             alert.add_recipient(
                 self.mock_reporter, self.tree, "alert", "value1"
             )
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #14
0
ファイル: test_nvpair.py プロジェクト: dchirikov/pcs
 def test_new(self):
     root = etree.Element("root", id="root")
     assert_xml_equal(
         """
         <nvset id="root-nvset">
             <nvpair id="root-nvset-attr" name="attr" value="10"/>
             <nvpair id="root-nvset-new_one" name="new_one" value="20"/>
             <nvpair id="root-nvset-test" name="test" value="0"/>
         </nvset>
         """,
         etree.tostring(nvpair.update_nvset("nvset", root, root, {
             "attr": "10",
             "new_one": "20",
             "test": "0",
             "attr2": ""
         })).decode()
     )
     assert_xml_equal(
         """
         <root id="root">
             <nvset id="root-nvset">
                 <nvpair id="root-nvset-attr" name="attr" value="10"/>
                 <nvpair id="root-nvset-new_one" name="new_one" value="20"/>
                 <nvpair id="root-nvset-test" name="test" value="0"/>
             </nvset>
         </root>
         """,
         etree.tostring(root).decode()
     )
コード例 #15
0
ファイル: test_ticket.py プロジェクト: norbertoaquino/pcs
    def test_sucess_create(self):
        resource_xml = '<primitive id="resourceA" class="service" type="exim"/>'
        cib = (
            self.create_cib()
                .append_to_first_tag_name('resources', resource_xml)
        )

        env = Env(self.mock_logger, self.mock_reporter, cib_data=str(cib))
        ticket_command.create(env, "ticketA", "resourceA", {
            "loss-policy": "fence",
            "rsc-role": "master"
        })

        assert_xml_equal(
            env.get_cib_xml(),
            str(cib.append_to_first_tag_name(
                'constraints', """
                    <rsc_ticket
                        id="ticket-ticketA-resourceA-Master"
                        rsc="resourceA"
                        rsc-role="Master"
                        ticket="ticketA"
                        loss-policy="fence"
                    />
                """
            ))
        )
コード例 #16
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
 def test_update_same_value_duplicity_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient" value="test_val"/>',
         etree.tostring(alert.update_recipient(
             self.mock_reporter, self.tree, "alert-recipient",
             recipient_value="test_val", allow_same_value=True
         )).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #17
0
 def test_no_alerts(self):
     tree = etree.XML(
         """
         <cib>
             <configuration/>
         </cib>
         """
     )
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path"/>',
         etree.tostring(
             alert.create_alert(tree, "my-alert", "/test/path")
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="my-alert" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(tree).decode()
     )
コード例 #18
0
 def test_duplicity_of_value_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient-1" value="test_val"/>',
         etree.tostring(
             alert.add_recipient(self.mock_reporter,
                                 self.tree,
                                 "alert",
                                 "test_val",
                                 allow_same_value=True)).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="test_val"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
     assert_report_item_list_equal(
         self.mock_reporter.report_item_list,
         [(severities.WARNING,
           report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS, {
               "alert": "alert",
               "recipient": "test_val"
           })])
コード例 #19
0
ファイル: test_lib_cib_tools.py プロジェクト: idevat/pcs
 def test_success(self, mock_named_file):
     mock_file = mock.MagicMock()
     mock_file.name = "mock_file_name"
     mock_file.read.return_value = "<cib/>"
     mock_named_file.return_value = mock_file
     self.mock_runner.run.return_value = ("", "", 0)
     assert_xml_equal(
         "<cib/>",
         etree.tostring(
             lib.upgrade_cib(etree.XML("<old_cib/>"), self.mock_runner)
         ).decode()
     )
     mock_named_file.assert_called_once_with("w+", suffix=".pcs")
     mock_file.write.assert_called_once_with("<old_cib/>")
     mock_file.flush.assert_called_once_with()
     self.mock_runner.run.assert_called_once_with(
         [
             join(settings.pacemaker_binaries, "cibadmin"),
             "--upgrade",
             "--force"
         ],
         env_extend={"CIB_file": "mock_file_name"}
     )
     mock_file.seek.assert_called_once_with(0)
     mock_file.read.assert_called_once_with()
コード例 #20
0
 def test_update_same_value_duplicity_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient" value="test_val"/>',
         etree.tostring(
             alert.update_recipient(self.mock_reporter,
                                    self.tree,
                                    "alert-recipient",
                                    recipient_value="test_val",
                                    allow_same_value=True)).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #21
0
 def test_get_cluster_conf(self):
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     facade_obj = env.get_cluster_conf()
     self.assertTrue(isinstance(facade_obj, ClusterConfFacade))
     assert_xml_equal(
         '<cluster/>', etree.tostring(facade_obj._config).decode()
     )
コード例 #22
0
    def push_cib(lib_env, custom_cib=None, wait=False):
        i, expected_call = call_queue.take(CALL_TYPE_PUSH_CIB)

        if custom_cib is None and expected_call.custom_cib:
            raise AssertionError(
                ("Trying to call env.push_cib (call no. {0}) without "
                 "a custom cib but a custom cib was expected").format(i))
        if custom_cib is not None and not expected_call.custom_cib:
            raise AssertionError(
                ("Trying to call env.push_cib (call no. {0}) with a custom "
                 "cib but no custom cib was expected").format(i))

        assert_xml_equal(
            expected_call.cib_xml, etree_to_str(lib_env.cib),
            ("Trying to call env.push_cib (call no. {0}) but cib in env does"
             " not match\n\n").format(i))

        if wait != expected_call.wait:
            raise AssertionError(
                ("Trying to call env.push_cib (call no. {0}) with 'wait' == "
                 "{1} but it was expected 'wait' == {2}").format(
                     i, wait, expected_call.wait))

        if expected_call.exception:
            raise expected_call.exception
コード例 #23
0
 def assert_resources_xml_in_cib(self, expected_xml_resources):
     xml = get_cib_part(self.temp_cib)
     try:
         assert_xml_equal(expected_xml_resources, xml.decode())
     except AssertionError as e:
         raise AssertionError("{0}\n\nCopy format ;)\n{1}".format(
             e.args[0], xml_format(xml.decode())))
コード例 #24
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
 def test_remove_description(self):
     assert_xml_equal(
         """
             <recipient id="alert-recipient-1" value="value1"/>
         """,
         etree.tostring(
            alert.update_recipient(
                self.mock_reporter, self.tree, "alert-recipient-1",
                description=""
            )
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #25
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
 def test_without_id(self):
     assert_xml_equal(
         '<recipient id="alert-recipient-1" value="value1"/>',
         etree.tostring(
             alert.add_recipient(
                 self.mock_reporter, self.tree, "alert", "value1"
             )
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #26
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
 def test_no_alerts(self):
     tree = etree.XML(
         """
         <cib>
             <configuration/>
         </cib>
         """
     )
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path"/>',
         etree.tostring(
             alert.create_alert(tree, "my-alert", "/test/path")
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="my-alert" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(tree).decode()
     )
コード例 #27
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
 def test_exist(self):
     assert_xml_equal(
         '<recipient id="rec-1" value="value1"/>',
         etree.tostring(
             alert.get_recipient_by_id(self.xml, "rec-1")
         ).decode()
     )
コード例 #28
0
 def test_remove_description(self):
     assert_xml_equal(
         """
             <recipient id="alert-recipient-1" value="value1"/>
         """,
         etree.tostring(
             alert.update_recipient(self.mock_reporter,
                                    self.tree,
                                    "alert-recipient-1",
                                    description="")).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
     self.assertEqual([], self.mock_reporter.report_item_list)
コード例 #29
0
ファイル: test_nvpair.py プロジェクト: HideoYamauchi/pcs
 def test_append_new_nvpair_to_given_element(self):
     nvset_element = etree.fromstring('<nvset id="a"/>')
     nvpair._append_new_nvpair(nvset_element, "b", "c")
     assert_xml_equal(etree.tostring(nvset_element).decode(), """
         <nvset id="a">
             <nvpair id="a-b" name="b" value="c"></nvpair>
         </nvset>
     """)
コード例 #30
0
ファイル: test_node.py プロジェクト: junaruga/pcs
 def test_with_type(self):
     node._create_node(self.nodes, "id-test", "name-test", "type-test")
     assert_xml_equal(
         """
         <nodes>
             <node id="id-test" uname="name-test" type="type-test" />
         </nodes>
         """, etree_to_str(self.nodes))
コード例 #31
0
 def assert_clone_effect(self, options, xml):
     clone.append_new(
         clone.TAG_CLONE,
         self.resources,
         self.primitive,
         options
     )
     assert_xml_equal(etree.tostring(self.cib).decode(), xml)
コード例 #32
0
 def assert_clone_effect(self, options, xml):
     clone.append_new(
         clone.TAG_CLONE,
         self.resources,
         self.primitive,
         options
     )
     assert_xml_equal(etree.tostring(self.cib).decode(), xml)
コード例 #33
0
 def test_get_cib_no_version_live(self, mock_get_cib_xml,
                                  mock_ensure_cib_version):
     mock_get_cib_xml.return_value = '<cib/>'
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     assert_xml_equal('<cib/>', etree.tostring(env.get_cib()).decode())
     self.assertEqual(1, mock_get_cib_xml.call_count)
     self.assertEqual(0, mock_ensure_cib_version.call_count)
     self.assertFalse(env.cib_upgraded)
コード例 #34
0
ファイル: cib.py プロジェクト: HideoYamauchi/pcs
 def assert_resources_xml_in_cib(self, expected_xml_resources):
     xml = get_cib_part(self.temp_cib)
     try:
         assert_xml_equal(expected_xml_resources, xml.decode())
     except AssertionError as e:
         raise AssertionError(
             "{0}\n\nCopy format ;)\n{1}".format(e.message, xml_format(xml))
         )
コード例 #35
0
    def assert_find_meta_attributes(self, xml, meta_attributes_xml_list):
        get_node = self.setup_patch("get_node", return_value=None)

        self.assertEquals([None] * len(meta_attributes_xml_list),
                          guest_node.find_node_list(etree.fromstring(xml)))

        for i, call in enumerate(get_node.mock_calls):
            assert_xml_equal(meta_attributes_xml_list[i],
                             etree.tostring(call[1][0]).decode())
コード例 #36
0
ファイル: test_lib_env.py プロジェクト: HideoYamauchi/pcs
 def test_get_cib_no_version_live(
         self, mock_get_cib_xml, mock_ensure_cib_version
 ):
     mock_get_cib_xml.return_value = '<cib/>'
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     assert_xml_equal('<cib/>', etree.tostring(env.get_cib()).decode())
     self.assertEqual(1, mock_get_cib_xml.call_count)
     self.assertEqual(0, mock_ensure_cib_version.call_count)
     self.assertFalse(env.cib_upgraded)
コード例 #37
0
 def test_append_new_nvpair_to_given_element(self):
     nvset_element = etree.fromstring('<nvset id="a"/>')
     nvpair._append_new_nvpair(nvset_element, "b", "c")
     assert_xml_equal(
         etree_to_str(nvset_element), """
         <nvset id="a">
             <nvpair id="a-b" name="b" value="c"></nvpair>
         </nvset>
         """)
コード例 #38
0
ファイル: integration_lib.py プロジェクト: HideoYamauchi/pcs
 def stdin_xml_check(stdin, command, order_num):
     assert_xml_equal(
         expected_stdin.decode(),
         stdin,
         (
             "Trying to run command no. {0}"
             "\n\n    '{1}'\n\nwith expected xml stdin.\n"
         ).format(order_num,  command)
     )
コード例 #39
0
 def test_remove(self):
     nvpair.set_nvpair_in_nvset(self.nvset, "attr2", "")
     assert_xml_equal(
         """
         <nvset id="nvset">
             <nvpair id="nvset-attr" name="attr" value="1"/>
             <notnvpair id="nvset-test" name="test" value="0"/>
         </nvset>
         """, etree_to_str(self.nvset))
コード例 #40
0
 def test_upgraded_higher_version(self, mock_upgrade, mock_get_cib):
     upgraded_cib = '<cib validate-with="pacemaker-2.3.6"/>'
     mock_get_cib.return_value = upgraded_cib
     assert_xml_equal(
         upgraded_cib,
         etree.tostring(
             lib.ensure_cib_version(self.mock_runner, self.cib,
                                    (2, 3, 5))).decode())
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
コード例 #41
0
 def test_get_cib_upgrade_live(self, mock_get_cib_xml,
                               mock_ensure_cib_version):
     mock_get_cib_xml.return_value = '<cib/>'
     mock_ensure_cib_version.return_value = etree.XML('<new_cib/>')
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     assert_xml_equal('<new_cib/>',
                      etree.tostring(env.get_cib((1, 2, 3))).decode())
     self.assertEqual(1, mock_get_cib_xml.call_count)
     self.assertEqual(1, mock_ensure_cib_version.call_count)
     self.assertTrue(env.cib_upgraded)
コード例 #42
0
ファイル: test_xml_tools.py プロジェクト: cwjenkins/pcs
 def test_new_last(self):
     lib.get_sub_element(self.root, "new_element", "new_id", None)
     assert_xml_equal(
         """
         <root>
             <sub_element/>
             <new_element id="new_id"/>
         </root>
         """,
         etree.tostring(self.root).decode())
コード例 #43
0
ファイル: test_nvpair.py プロジェクト: thulyacloud/pcs
 def test_remove_not_existing(self):
     nvpair.set_nvpair_in_nvset(self.nvset, "attr3", "", self.id_provider)
     assert_xml_equal(
         """
         <nvset id="nvset">
             <nvpair id="nvset-attr" name="attr" value="1"/>
             <nvpair id="nvset-attr2" name="attr2" value="2"/>
             <notnvpair id="nvset-test" name="test" value="0"/>
         </nvset>
         """, etree_to_str(self.nvset))
コード例 #44
0
 def test_empty_value_has_no_effect(self):
     nvpair.arrange_first_nvset("nvset", self.root, {})
     assert_xml_equal(
         """
             <nvset id="nvset">
                 <nvpair id="nvset-attr" name="attr" value="1"/>
                 <nvpair id="nvset-attr2" name="attr2" value="2"/>
                 <notnvpair id="nvset-test" name="test" value="0"/>
             </nvset>
         """, etree_to_str(self.nvset))
コード例 #45
0
ファイル: test_node.py プロジェクト: HideoYamauchi/pcs
 def test_with_type(self):
     node._create_node(self.nodes, "id-test", "name-test", "type-test")
     assert_xml_equal(
         """
         <nodes>
             <node id="id-test" uname="name-test" type="type-test" />
         </nodes>
         """,
         etree_to_str(self.nodes)
     )
コード例 #46
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
    def test_update_all(self):
        cmd_alert.update_recipient(
            self.mock_env,
            "alert-recipient-1",
            {"attr1": "value"},
            {
                "attr1": "",
                "attr3": "new_val"
            },
            recipient_value="new_val",
            description="desc"
        )
        assert_xml_equal(
            """
<cib validate-with="pacemaker-2.5">
    <configuration>
        <alerts>
            <alert id="alert" path="path">
                <recipient id="alert-recipient" value="value1"/>
                <recipient
                    id="alert-recipient-1"
                    value="new_val"
                    description="desc"
                >
                    <meta_attributes
                        id="alert-recipient-1-meta_attributes"
                    >
                        <nvpair
                            id="alert-recipient-1-meta_attributes-attr2"
                            name="attr2"
                            value="val2"
                        />
                        <nvpair
                            id="alert-recipient-1-meta_attributes-attr3"
                            name="attr3"
                            value="new_val"
                        />
                    </meta_attributes>
                    <instance_attributes
                        id="alert-recipient-1-instance_attributes"
                    >
                        <nvpair
                            id="alert-recipient-1-instance_attributes-attr1"
                            name="attr1"
                            value="value"
                        />
                    </instance_attributes>
                </recipient>
            </alert>
        </alerts>
    </configuration>
</cib>
            """,
            self.mock_env._get_cib_xml()
        )
コード例 #47
0
 def test_with_id_provider(self):
     nvset_element = etree.fromstring('<nvset id="a"/>')
     provider = IdProvider(nvset_element)
     provider.book_ids("a-b")
     nvpair._append_new_nvpair(nvset_element, "b", "c", provider)
     assert_xml_equal(
         etree_to_str(nvset_element), """
         <nvset id="a">
             <nvpair id="a-b-1" name="b" value="c"></nvpair>
         </nvset>
         """)
コード例 #48
0
 def test_empty_value_has_no_effect(self):
     xml = """
         <instance_attributes id="iattrs">
             <nvpair id="1" name="a" value="b"/>
             <nvpair id="2" name="c" value="d"/>
             <nvpair id="3" name="e" value="f"/>
         </instance_attributes>
     """
     nvset_element = etree.fromstring(xml)
     nvpair.update_nvset(nvset_element, {})
     assert_xml_equal(xml, etree_to_str(nvset_element))
コード例 #49
0
ファイル: test_nvpair.py プロジェクト: idevat/pcs
 def test_empty_value_has_no_effect(self):
     xml = """
         <instance_attributes id="iattrs">
             <nvpair id="1" name="a" value="b"/>
             <nvpair id="2" name="c" value="d"/>
             <nvpair id="3" name="e" value="f"/>
         </instance_attributes>
     """
     nvset_element = etree.fromstring(xml)
     nvpair.update_nvset(nvset_element, {})
     assert_xml_equal(xml, etree.tostring(nvset_element).decode())
コード例 #50
0
    def test_remove_resource_references_and_empty_remaining_parents(self):
        constraint_section = etree.fromstring("""
            <constraints>
                <rsc_ticket id="t1" ticket="tA">
                    <resource_set id="rs1">
                        <resource_ref id="rA"/>
                    </resource_set>
                    <resource_set id="rs2">
                        <resource_ref id="rA"/>
                    </resource_set>
                </rsc_ticket>

                <rsc_ticket id="t2" ticket="tA">
                    <resource_set id="rs3">
                        <resource_ref id="rA"/>
                        <resource_ref id="rB"/>
                    </resource_set>
                    <resource_set id="rs4">
                        <resource_ref id="rA"/>
                    </resource_set>
                </rsc_ticket>

                <rsc_ticket id="t3" ticket="tB">
                    <resource_set id="rs5">
                        <resource_ref id="rA"/>
                    </resource_set>
                </rsc_ticket>
            </constraints>
        """)

        self.assertTrue(ticket.remove_with_resource_set(
            constraint_section,
            ticket_key="tA",
            resource_id="rA"
        ))

        assert_xml_equal(
            """
                <constraints>
                    <rsc_ticket id="t2" ticket="tA">
                        <resource_set id="rs3">
                            <resource_ref id="rB"/>
                        </resource_set>
                    </rsc_ticket>

                    <rsc_ticket id="t3" ticket="tB">
                        <resource_set id="rs5">
                            <resource_ref id="rA"/>
                        </resource_set>
                    </rsc_ticket>
                </constraints>
            """,
            etree.tostring(constraint_section).decode()
        )
コード例 #51
0
ファイル: test_lib_resource_agent.py プロジェクト: idevat/pcs
    def test_success(self, mock_obj):
        agent = "agent"
        xml = "<xml />"
        mock_obj.return_value = etree.ElementTree(etree.XML(xml))
        out_dom = lib_ra._get_nagios_resource_agent_metadata(agent)
        metadata_path = os.path.join(
            settings.nagios_metadata_path, agent + ".xml"
        )

        mock_obj.assert_called_once_with(metadata_path)
        assert_xml_equal(xml, str(XmlMan(out_dom)))
コード例 #52
0
 def test_success(self):
     xml = """
     <xml>
         <acl_role id="role-id"/>
         <role id="role-id"/>
     </xml>
     """
     assert_xml_equal(
         '<acl_role id="role-id"/>',
         etree.tostring(lib.find_role(etree.XML(xml), "role-id")).decode()
     )
コード例 #53
0
ファイル: test_tools.py プロジェクト: HideoYamauchi/pcs
 def test_new_last(self):
     lib.get_sub_element(self.root, "new_element", "new_id", None)
     assert_xml_equal(
         """
         <root>
             <sub_element/>
             <new_element id="new_id"/>
         </root>
         """,
         etree.tostring(self.root).decode()
     )
コード例 #54
0
ファイル: test_nvpair.py プロジェクト: idevat/pcs
 def test_remove(self):
     nvpair.set_nvpair_in_nvset(self.nvset, "attr2", "")
     assert_xml_equal(
         """
         <nvset id="nvset">
             <nvpair id="nvset-attr" name="attr" value="1"/>
             <notnvpair id="nvset-test" name="test" value="0"/>
         </nvset>
         """,
         etree.tostring(self.nvset).decode(),
     )
コード例 #55
0
ファイル: test_nvpair.py プロジェクト: idevat/pcs
 def test_empty_value_has_no_effect(self):
     nvpair.arrange_first_nvset("nvset", self.root, {})
     assert_xml_equal(
         """
             <nvset id="nvset">
                 <nvpair id="nvset-attr" name="attr" value="1"/>
                 <nvpair id="nvset-attr2" name="attr2" value="2"/>
                 <notnvpair id="nvset-test" name="test" value="0"/>
             </nvset>
         """,
         etree.tostring(self.nvset).decode(),
     )
コード例 #56
0
ファイル: test_lib_env.py プロジェクト: idevat/pcs
 def test_get_cib_upgrade_live(
     self, mock_get_cib_xml, mock_ensure_cib_version
 ):
     mock_get_cib_xml.return_value = '<cib/>'
     mock_ensure_cib_version.return_value = etree.XML('<new_cib/>')
     env = LibraryEnvironment(self.mock_logger, self.mock_reporter)
     assert_xml_equal(
         '<new_cib/>', etree.tostring(env.get_cib((1, 2, 3))).decode()
     )
     self.assertEqual(1, mock_get_cib_xml.call_count)
     self.assertEqual(1, mock_ensure_cib_version.call_count)
     self.assertTrue(env.cib_upgraded)
コード例 #57
0
ファイル: test_live.py プロジェクト: HideoYamauchi/pcs
 def test_upgraded_higher_version(self, mock_upgrade, mock_get_cib):
     upgraded_cib = '<cib validate-with="pacemaker-2.3.6"/>'
     mock_get_cib.return_value = upgraded_cib
     assert_xml_equal(
         upgraded_cib,
         etree.tostring(
             lib.ensure_cib_version(
                 self.mock_runner, self.cib, (2, 3, 5)
             )
         ).decode()
     )
     mock_upgrade.assert_called_once_with(self.mock_runner)
     mock_get_cib.assert_called_once_with(self.mock_runner)
コード例 #58
0
ファイル: test_nvpair.py プロジェクト: idevat/pcs
 def test_update_existing_nvset(self):
     nvpair.arrange_first_nvset("nvset", self.root, {"attr": "10", "new_one": "20", "test": "0", "attr2": ""})
     assert_xml_equal(
         """
             <nvset id="nvset">
                 <nvpair id="nvset-attr" name="attr" value="10"/>
                 <notnvpair id="nvset-test" name="test" value="0"/>
                 <nvpair id="nvset-new_one" name="new_one" value="20"/>
                 <nvpair id="nvset-test-1" name="test" value="0"/>
             </nvset>
         """,
         etree.tostring(self.nvset).decode(),
     )
コード例 #59
0
ファイル: test_alert.py プロジェクト: dchirikov/pcs
    def test_with_id(self):
        cmd_alert.add_recipient(
            self.mock_env,
            "alert",
            "value",
            {"attr1": "val1"},
            {
                "attr2": "val2",
                "attr1": "val1"
            },
            recipient_id="my-recipient"
        )
        assert_xml_equal(
            """
<cib validate-with="pacemaker-2.5">
    <configuration>
        <alerts>
            <alert id="alert" path="path">
                <recipient id="alert-recipient" value="value1"/>
                <recipient id="my-recipient" value="value">
                    <meta_attributes
                        id="my-recipient-meta_attributes"
                    >
                        <nvpair
                            id="my-recipient-meta_attributes-attr1"
                            name="attr1"
                            value="val1"
                        />
                        <nvpair
                            id="my-recipient-meta_attributes-attr2"
                            name="attr2"
                            value="val2"
                        />
                    </meta_attributes>
                    <instance_attributes
                        id="my-recipient-instance_attributes"
                    >
                        <nvpair
                            id="my-recipient-instance_attributes-attr1"
                            name="attr1"
                            value="val1"
                        />
                    </instance_attributes>
                </recipient>
            </alert>
        </alerts>
    </configuration>
</cib>
            """,
            self.mock_env._get_cib_xml()
        )
コード例 #60
0
 def test_success(self):
     expected_xml = """
     <cib>
         <configuration>
             <acls>
                 <acl_role id="role-id">
                     <acl_permission id="role-permission"/>
                 </acl_role>
             </acls>
         </configuration>
     </cib>
     """
     lib.remove_permission(self.tree, "permission-id")
     assert_xml_equal(expected_xml, etree.tostring(self.tree).decode())