Exemplo n.º 1
0
def describe_agent(
    lib_env: LibraryEnvironment, agent_name: str
) -> Dict[str, Any]:
    """
    Get agent's description (metadata) in a structure

    agent_name -- name of the agent
    """
    runner = lib_env.cmd_runner()
    report_processor = lib_env.report_processor
    agent_factory = ResourceAgentFacadeFactory(runner, report_processor)
    try:
        found_name = (
            split_resource_agent_name(agent_name)
            if ":" in agent_name
            else find_one_resource_agent_by_type(
                runner, report_processor, agent_name
            )
        )
        return _agent_metadata_to_dict(
            agent_factory.facade_from_parsed_name(found_name).metadata,
            describe=True,
        )
    except ResourceAgentError as e:
        lib_env.report_processor.report(resource_agent_error_to_report_item(e))
        raise LibraryError() from e
Exemplo n.º 2
0
def get_structured_agent_name(lib_env: LibraryEnvironment,
                              agent_name: str) -> ResourceAgentNameDto:
    # This is a temporary solution and should never be available via pcsd REST
    # API. The code for splitting an agent name will be eventually moved to cli
    # once all old commands that require this will be replaced and removed.
    try:
        return split_resource_agent_name(agent_name).to_dto()
    except ResourceAgentError as e:
        lib_env.report_processor.report(resource_agent_error_to_report_item(e))
        raise LibraryError() from e
Exemplo n.º 3
0
 def test_refuses_service_agent_name_with_provider_and_instance(self):
     self.assertRaises(
         InvalidResourceAgentName,
         lambda: split_resource_agent_name(
             "service:provider:lvm2-pvscan252@252:2"),
     )
Exemplo n.º 4
0
 def test_refuses_systemd_agent_name_with_provider(self):
     self.assertRaises(
         InvalidResourceAgentName,
         lambda: split_resource_agent_name("sytemd:provider:lvm2-pvscan252"
                                           ),
     )
Exemplo n.º 5
0
 def test_returns_resource_agent_containing_systemd_instance_short(self):
     self.assertEqual(
         ResourceAgentName("service", None, "getty@tty1"),
         split_resource_agent_name("service:getty@tty1"),
     )
Exemplo n.º 6
0
 def test_returns_resource_agent_containing_service_instance(self):
     self.assertEqual(
         ResourceAgentName("service", None, "lvm2-pvscan@252:2"),
         split_resource_agent_name("service:lvm2-pvscan@252:2"),
     )
Exemplo n.º 7
0
 def test_returns_resource_agent_containing_sytemd(self):
     self.assertEqual(
         ResourceAgentName("systemd", None, "lvm2-pvscan"),
         split_resource_agent_name("systemd:lvm2-pvscan"),
     )
Exemplo n.º 8
0
 def test_refuses_non_ocf_agent_name_with_provider(self):
     self.assertRaises(
         InvalidResourceAgentName,
         lambda: split_resource_agent_name("lsb:provider:Dummy"),
     )
Exemplo n.º 9
0
 def test_refuses_with_unknown_standard(self):
     self.assertRaises(
         InvalidResourceAgentName,
         lambda: split_resource_agent_name("unknown:Dummy"),
     )
Exemplo n.º 10
0
 def test_refuses_string_if_is_not_valid(self):
     self.assertRaises(
         InvalidResourceAgentName,
         lambda: split_resource_agent_name("invalid:resource:agent:string"),
     )
Exemplo n.º 11
0
 def test_returns_resource_agent_name_when_is_valid(self):
     self.assertEqual(
         ResourceAgentName("ocf", "heartbeat", "Dummy"),
         split_resource_agent_name("ocf:heartbeat:Dummy"),
     )