Example #1
0
    def test_error(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = "expected stderr"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.replace_cib_configuration(
                    mock_runner,
                    XmlManipulation.from_str(xml).tree
                )
            ,
            (
                Severity.ERROR,
                report_codes.CIB_PUSH_ERROR,
                {
                    "reason": expected_stderr,
                    "pushed_cib": expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [
                self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe",
                "--scope", "configuration"
            ],
            stdin_string=xml
        )
Example #2
0
    def test_error(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = "expected stderr"
        expected_retval = 1
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (
            expected_stdout,
            expected_stderr,
            expected_retval
        )

        assert_raise_library_error(
            lambda: lib.replace_cib_configuration(
                    mock_runner,
                    XmlManipulation.from_str(xml).tree
                )
            ,
            (
                Severity.ERROR,
                report_codes.CIB_PUSH_ERROR,
                {
                    "reason": expected_stderr,
                    "pushed_cib": expected_stdout,
                }
            )
        )

        mock_runner.run.assert_called_once_with(
            [
                self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe",
                "--scope", "configuration"
            ],
            stdin_string=xml
        )
Example #3
0
 def setUp(self):
     self.env_assist, self.config = get_env_tools(self)
     self.config.env.set_known_hosts_dests(KNOWN_HOSTS_DESTS)
     cib_xml_man = XmlManipulation.from_file(rc("cib-empty.xml"))
     cib_xml_man.append_to_first_tag_name(
         "resources", """
             <primitive class="ocf" id="{0}"
                 provider="heartbeat" type="VirtualDomain"
             />
         """.format(VIRTUAL_MACHINE_ID))
     self.config.env.set_cib_data(str(cib_xml_man))
Example #4
0
    def test_success(self):
        metadata = """
            <resource-agent>
                <shortdesc>stonithd test metadata</shortdesc>
            </resource-agent>
        """
        self.mock_runner.run.return_value = (metadata, "", 0)

        assert_xml_equal(str(XmlManipulation(self.agent._get_metadata())),
                         metadata)

        self.mock_runner.run.assert_called_once_with(
            ["/usr/libexec/pacemaker/stonithd", "metadata"])
Example #5
0
    def test_cib_upgraded(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_stdout, expected_stderr,
                                        expected_retval)

        lib.replace_cib_configuration(mock_runner,
                                      XmlManipulation.from_str(xml).tree, True)

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe"],
            stdin_string=xml)
Example #6
0
    def test_cib_upgraded(self):
        xml = "<xml/>"
        expected_output = "expected output"
        expected_retval = 0
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = (expected_output, expected_retval)

        lib.replace_cib_configuration(
            mock_runner, XmlManipulation.from_str(xml).tree, True
        )

        mock_runner.run.assert_called_once_with(
            [self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe"],
            stdin_string=xml
        )
Example #7
0
    def test_success(self):
        xml = "<xml/>"
        expected_stdout = "expected output"
        expected_stderr = ""
        expected_retval = 0
        mock_runner = get_runner(expected_stdout, expected_stderr,
                                 expected_retval)

        lib.replace_cib_configuration(mock_runner,
                                      XmlManipulation.from_str(xml).tree)

        mock_runner.run.assert_called_once_with([
            self.path("cibadmin"), "--replace", "--verbose", "--xml-pipe",
            "--scope", "configuration"
        ],
                                                stdin_string=xml)
Example #8
0
    def test_success(self):
        metadata = """
            <resource-agent>
                <shortdesc>crm agent test metadata</shortdesc>
            </resource-agent>
        """
        self.mock_runner.run.return_value = (metadata, "", 0)

        assert_xml_equal(str(XmlManipulation(self.agent._get_metadata())),
                         metadata)

        self.mock_runner.run.assert_called_once_with(
            ["/usr/sbin/crm_resource", "--show-metadata", self.agent_name],
            env_extend={
                "PATH": "/usr/sbin/:/bin/:/usr/bin/",
            })
Example #9
0
 def fixture_status_xml(self, nodes, resources):
     xml_man = XmlManipulation.from_file(rc("crm_mon.minimal.xml"))
     doc = xml_man.tree.getroottree()
     doc.find("/summary/nodes_configured").set("number", str(nodes))
     doc.find("/summary/resources_configured").set("number", str(resources))
     return str(XmlManipulation(doc))
Example #10
0
 def setUp(self):
     self.status = XmlManipulation.from_file(rc("crm_mon.minimal.xml"))
Example #11
0
 def fixture_status_xml(self, nodes, resources):
     xml_man = XmlManipulation.from_file(rc("crm_mon.minimal.xml"))
     doc = xml_man.tree.getroottree()
     doc.find("/summary/nodes_configured").set("number", str(nodes))
     doc.find("/summary/resources_configured").set("number", str(resources))
     return str(XmlManipulation(doc))
Example #12
0
 def setUp(self):
     self.status = XmlManipulation.from_file(rc("crm_mon.minimal.xml"))
Example #13
0
 def test_success(self):
     xml = "<xml />"
     assert_xml_equal(xml, str(XmlManipulation((lib.get_cib(xml)))))