Esempio n. 1
0
 def test_not_runnable(self, mock_is_runnable):
     mock_is_runnable.return_value = False
     provider = "provider"
     agent = "agent"
     self.assert_raise_library_error(
         lambda: lib_ra._get_ocf_resource_agent_metadata(provider, agent),
         (
             Severities.ERROR,
             error_codes.INVALID_RESOURCE_NAME,
             {"agent_name": "ocf::{0}:{1}".format(provider, agent)}
         )
     )
Esempio n. 2
0
 def test_invalid_xml(self, mock_run, mock_is_runnable):
     provider = "provider"
     agent = "agent"
     mock_run.return_value = ("not xml", 0)
     mock_is_runnable.return_value = True
     self.assert_raise_library_error(
         lambda: lib_ra._get_ocf_resource_agent_metadata(provider, agent),
         (
             Severities.ERROR,
             error_codes.UNABLE_TO_GET_AGENT_METADATA,
             {"agent_name": "ocf::{0}:{1}".format(provider, agent)}
         )
     )
Esempio n. 3
0
    def test_success(self, mock_run, mock_is_runnable):
        provider = "provider"
        agent = "agent"
        xml = "<xml />"
        mock_run.return_value = (xml, 0)
        mock_is_runnable.return_value = True
        out_dom = lib_ra._get_ocf_resource_agent_metadata(provider, agent)
        script_path = os.path.join(settings.ocf_resources, provider, agent)

        mock_run.assert_called_once_with(
            [script_path, "meta-data"],
            env_extend={"OCF_ROOT": settings.ocf_root}
        )
        assert_xml_equal(xml, str(XmlMan(out_dom)))
Esempio n. 4
0
    def test_not_runnable(self, mock_is_runnable):
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_is_runnable.return_value = False
        provider = "provider"
        agent = "agent"

        self.assert_raises(
            lib_ra.AgentNotFound,
            lambda: lib_ra._get_ocf_resource_agent_metadata(
                mock_runner, provider, agent
            ),
            {"agent": "ocf:{0}:{1}".format(provider, agent)}
        )

        mock_runner.run.assert_not_called()
Esempio n. 5
0
    def test_invalid_xml(self, mock_is_runnable):
        provider = "provider"
        agent = "agent"
        mock_runner = mock.MagicMock(spec_set=CommandRunner)
        mock_runner.run.return_value = ("not xml", "", 0)
        mock_is_runnable.return_value = True

        self.assert_raises(
            lib_ra.UnableToGetAgentMetadata,
            lambda: lib_ra._get_ocf_resource_agent_metadata(
                mock_runner, provider, agent
            ),
            {"agent": "ocf:{0}:{1}".format(provider, agent)}
        )

        script_path = os.path.join(settings.ocf_resources, provider, agent)
        mock_runner.run.assert_called_once_with(
            [script_path, "meta-data"],
            env_extend={"OCF_ROOT": settings.ocf_root}
        )