Exemple #1
0
    def test_full_name_success(self, mock_guess, mock_metadata):
        mock_metadata.return_value = self.metadata

        self.assertEqual(
            lib.describe_agent(self.lib_env, "ocf:test:Dummy"),
            self.description
        )

        self.assertEqual(len(mock_metadata.mock_calls), 1)
        mock_guess.assert_not_called()
Exemple #2
0
    def test_guess_success(self, mock_guess, mock_metadata):
        mock_metadata.return_value = self.metadata
        mock_guess.return_value = lib_ra.ResourceAgent(
            self.lib_env.cmd_runner(),
            "ocf:test:Dummy"
        )

        self.assertEqual(
            lib.describe_agent(self.lib_env, "dummy"),
            self.description
        )

        self.assertEqual(len(mock_metadata.mock_calls), 1)
        mock_guess.assert_called_once_with("mock_runner", "dummy")
Exemple #3
0
    def test_full_name_fail(self, mock_guess, mock_metadata):
        mock_metadata.return_value = "invalid xml"

        assert_raise_library_error(
            lambda: lib.describe_agent(self.lib_env, "ocf:test:Dummy"),
            (
                severity.ERROR,
                report_codes.UNABLE_TO_GET_AGENT_METADATA,
                {
                    "agent": "ocf:test:Dummy",
                    "reason": "Start tag expected, '<' not found, line 1, column 1",
                }
            )
        )

        self.assertEqual(len(mock_metadata.mock_calls), 1)
        mock_guess.assert_not_called()
Exemple #4
0
 def test_guess_success(self):
     self.config.runner.pcmk.list_agents_standards("\n".join(
         ["service", "ocf"]))
     self.config.runner.pcmk.list_agents_ocf_providers("\n".join(
         ["heartbeat", "pacemaker"]))
     self.config.runner.pcmk.list_agents_for_standard_and_provider(
         "ocf:heartbeat",
         "\n".join(["agent1", "Dummy", "agent2"]),
         name="runner.pcmk.list_agents_ocf_providers.heartbeat",
     )
     self.config.runner.pcmk.list_agents_for_standard_and_provider(
         "ocf:pacemaker",
         "\n".join(["agent1"]),
         name="runner.pcmk.list_agents_ocf_providers.pacemaker",
     )
     self.config.runner.pcmk.list_agents_for_standard_and_provider(
         "service",
         "\n".join(["agent1"]),
         name="runner.pcmk.list_agents_ocf_providers.service",
     )
     self.config.runner.pcmk.load_agent(
         env={"PATH": "/usr/sbin:/bin:/usr/bin"}, )
     self.assertEqual(
         lib.describe_agent(self.env_assist.get_env(), "dummy"),
         {
             "name":
             "ocf:heartbeat:Dummy",
             "standard":
             "ocf",
             "provider":
             "heartbeat",
             "type":
             "Dummy",
             "shortdesc":
             "Example stateless resource agent",
             "longdesc":
             ("This is a Dummy Resource Agent. It does absolutely nothing "
              "except \nkeep track of whether its running or not.\nIts "
              "purpose in life is for testing and to serve as a template "
              "for RA writers.\n\nNB: Please pay attention to the timeouts "
              "specified in the actions\nsection below. They should be "
              "meaningful for the kind of resource\nthe agent manages. "
              "They should be the minimum advised timeouts,\nbut they "
              "shouldn't/cannot cover _all_ possible resource\ninstances. "
              "So, try to be neither overly generous nor too stingy,\nbut "
              "moderate. The minimum timeouts should never be below 10 seconds."
              ),
             "parameters": [
                 {
                     "name": "state",
                     "shortdesc": "State file",
                     "longdesc": "Location to store the resource state in.",
                     "type": "string",
                     "default":
                     "/var/run/resource-agents/Dummy-undef.state",
                     "enum_values": None,
                     "required": False,
                     "advanced": False,
                     "deprecated": False,
                     "deprecated_by": [],
                     "deprecated_desc": None,
                     "unique_group": "_pcs_unique_group_state",
                     "reloadable": True,
                 },
                 {
                     "name":
                     "fake",
                     "shortdesc":
                     ("Fake attribute that can be changed to cause a reload"
                      ),
                     "longdesc":
                     ("Fake attribute that can be changed to cause a reload"
                      ),
                     "type":
                     "string",
                     "default":
                     "dummy",
                     "enum_values":
                     None,
                     "required":
                     False,
                     "advanced":
                     False,
                     "deprecated":
                     False,
                     "deprecated_by": [],
                     "deprecated_desc":
                     None,
                     "unique_group":
                     None,
                     "reloadable":
                     False,
                 },
             ] + self.trace_parameters,
             "actions": [
                 {
                     "name": "start",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "stop",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "monitor",
                     "timeout": "20",
                     "interval": "10",
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "reload",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "migrate_to",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "migrate_from",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "meta-data",
                     "timeout": "5",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
                 {
                     "name": "validate-all",
                     "timeout": "20",
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                 },
             ],
             "default_actions": [
                 {
                     "name": "start",
                     "timeout": "20",
                     "interval": "0s",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
                 {
                     "name": "stop",
                     "timeout": "20",
                     "interval": "0s",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
                 {
                     "name": "monitor",
                     "timeout": "20",
                     "interval": "10",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
                 {
                     "name": "reload",
                     "timeout": "20",
                     "interval": "0s",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
                 {
                     "name": "migrate_to",
                     "timeout": "20",
                     "interval": "0s",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
                 {
                     "name": "migrate_from",
                     "timeout": "20",
                     "interval": "0s",
                     "role": None,
                     "start-delay": None,
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                 },
             ],
         },
     )
     self.env_assist.assert_reports([
         fixture.info(
             report_codes.AGENT_NAME_GUESSED,
             entered_name="dummy",
             guessed_name="ocf:heartbeat:Dummy",
         )
     ])
Exemple #5
0
 def test_full_name_and_utf8_success(self):
     full_name = "ocf:heartbeat:Dummy"
     self.config.runner.pcmk.load_agent(
         agent_filename="resource_agent_ocf_heartbeat_dummy_utf8.xml",
         env={"PATH": "/usr/sbin:/bin:/usr/bin"},
     )
     self.assertEqual(
         lib.describe_agent(self.env_assist.get_env(), full_name),
         {
             "name":
             full_name,
             "standard":
             "ocf",
             "provider":
             "heartbeat",
             "type":
             "Dummy",
             "shortdesc":
             "Example stateless resource agent: ®",
             "longdesc":
             "This is a Dummy Resource Agent for testing utf-8"
             " in metadata: ®",
             "parameters": [
                 {
                     "advanced": False,
                     "default": "/var/run/resource-agents/Dummy-®.state",
                     "deprecated": False,
                     "deprecated_by": [],
                     "deprecated_desc": None,
                     "enum_values": None,
                     "longdesc":
                     ("Location to store the resource state in: ®"),
                     "name": "state-®",
                     "required": False,
                     "shortdesc": "State file: ®",
                     "type": "string",
                     "unique_group": "_pcs_unique_group_state-®",
                     "reloadable": True,
                 },
             ] + self.trace_parameters,
             "actions": [
                 {
                     "name": "start",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "stop",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "monitor",
                     "interval": "10",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "meta-data",
                     "timeout": "5",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "validate-all",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "custom-®",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "interval": None,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
             ],
             "default_actions": [
                 {
                     "name": "start",
                     "interval": "0s",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "stop",
                     "interval": "0s",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "monitor",
                     "interval": "10",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
                 {
                     "name": "custom-®",
                     "interval": "0s",
                     "timeout": "20",
                     "OCF_CHECK_LEVEL": None,
                     "automatic": False,
                     "on_target": False,
                     "role": None,
                     "start-delay": None,
                 },
             ],
         },
     )
 def test_describe(self):
     name = "ocf:heartbeat:Dummy"
     self.assertEqual(
         lib.describe_agent(self.env_assist.get_env(), name),
         {
             "name": name,
             "shortdesc": u"Example stateless resource agent: ®",
             "longdesc": u"This is a Dummy Resource Agent for testing utf-8"
                 u" in metadata: ®"
             ,
             "parameters": [
                 {
                     "advanced": False,
                     "default": u"/var/run/resource-agents/Dummy-®.state",
                     "deprecated": False,
                     "deprecated_by": [],
                     "longdesc":
                         u"Location to store the resource state in: ®",
                     "name": u"state-®",
                     "obsoletes": None,
                     "pcs_deprecated_warning": "",
                     "required": False,
                     "shortdesc": u"State file: ®",
                     "type": "string",
                     "unique": True,
                 },
                 {
                     "advanced": True,
                     "default": 0,
                     "deprecated": False,
                     "deprecated_by": [],
                     "longdesc": "Set to 1 to turn on resource agent tracing"
                         " (expect large output) The trace output will be "
                         "saved to trace_file, if set, or by default to "
                         "$HA_VARRUN/ra_trace/<type>/<id>.<action>."
                         "<timestamp> e.g. $HA_VARRUN/ra_trace/oracle/db."
                         "start.2012-11-27.08:37:08",
                     "name": "trace_ra",
                     "obsoletes": None,
                     "pcs_deprecated_warning": "",
                     "required": False,
                     "shortdesc": "Set to 1 to turn on resource agent "
                         "tracing (expect large output)",
                     "type": "integer",
                     "unique": False,
                 },
                 {
                     "advanced": True,
                     "default": "",
                     "deprecated": False,
                     "deprecated_by": [],
                     "longdesc": "Path to a file to store resource agent "
                         "tracing log",
                     "name": "trace_file",
                     "obsoletes": None,
                     "pcs_deprecated_warning": "",
                     "required": False,
                     "shortdesc": "Path to a file to store resource agent "
                         "tracing log",
                     "type": "string",
                     "unique": False,
                 }
             ],
             "actions": [
                 {"name": "start", "timeout": "20"},
                 {"name": "stop", "timeout": "20"},
                 {"name": "monitor", "interval": "10", "timeout": "20"},
                 {"name": "meta-data", "timeout": "5"},
                 {"name": "validate-all", "timeout": "20"},
                 {"name": u"custom-®", "timeout": "20"},
             ],
             "default_actions": [
                 {"name": "start", "interval": "0s", "timeout": "20"},
                 {"name": "stop", "interval": "0s", "timeout": "20"},
                 {"name": "monitor", "interval": "10", "timeout": "20"},
                 {"name": u"custom-®", "interval": "0s", "timeout": "20"},
             ],
         }
     )