def test_select_only_actions_for_cib_stonith(self): self.assertEqual( agent.get_default_operations( self.fixture_stonith_agent(self.fixture_actions) ), [self.op_fixture("monitor", "10s", "30s")], )
def test_select_only_necessary_actions_for_cib(self): self.assertEqual( agent.get_default_operations( self.fixture_agent(self.fixture_actions), necessary_only=True ), [self.op_fixture("monitor", "10s", "30s")], )
def _agent_metadata_to_dict( agent: ResourceAgentMetadata, describe: bool = False ) -> Dict[str, str]: agent_dto = agent.to_dto() agent_dict = to_dict(agent_dto) del agent_dict["name"] agent_dict["name"] = agent.name.full_name agent_dict["standard"] = agent.name.standard agent_dict["provider"] = agent.name.provider agent_dict["type"] = agent.name.type agent_dict["actions"] = [ _action_to_operation(action) for action in agent_dto.actions ] operations_defaults = { "OCF_CHECK_LEVEL": None, "automatic": False, "on_target": False, } agent_dict["default_actions"] = ( [ operation_dto_to_legacy_dict(op, operations_defaults) for op in get_default_operations(agent) ] if describe else [] ) return agent_dict
def test_complete_monitor_stonith(self): self.assertEqual( agent.get_default_operations( self.fixture_stonith_agent(self.fixture_actions_meta_only), necessary_only=True, ), [self.op_fixture("monitor", "60s", None)], )
def test_select_only_actions_for_cib(self): self.assertEqual( agent.get_default_operations( self.fixture_agent(self.fixture_actions) ), [ self.op_fixture("custom1", "0s", "40s"), self.op_fixture("custom2", "25s", "60s"), self.op_fixture("monitor", "10s", "30s"), self.op_fixture("start", "40s", None), ], )
def test_select_only_actions_for_cib_stonith(self): self.assertEqual( agent.get_default_operations( self.fixture_stonith_agent(self.fixture_actions)), [{ "interval": "10s", "name": "monitor", "OCF_CHECK_LEVEL": None, "role": None, "start-delay": None, "timeout": "30s", }], )
def get_agent_default_operations( lib_env: LibraryEnvironment, agent_name: ResourceAgentNameDto, necessary_only: bool = False, ) -> ListCibResourceOperationDto: report_list, operation_list = uniquify_operations_intervals( get_default_operations( _get_agent_metadata(lib_env.cmd_runner(), lib_env.report_processor, agent_name), necessary_only, )) lib_env.report_processor.report_list(report_list) return ListCibResourceOperationDto(operations=operation_list)
def test_complete_monitor_stonith(self): self.assertEqual( agent.get_default_operations( self.fixture_stonith_agent(self.fixture_actions_meta_only), necessary_only=True, ), [{ "interval": None, "name": "monitor", "OCF_CHECK_LEVEL": None, "role": None, "start-delay": None, "timeout": None, }], )
def _agent_metadata_to_dict(agent: ResourceAgentMetadata, describe: bool = False) -> Dict[str, str]: agent_dto = agent.to_dto() agent_dict = to_dict(agent_dto) del agent_dict["name"] agent_dict["name"] = agent.name.full_name agent_dict["standard"] = agent.name.standard agent_dict["provider"] = agent.name.provider agent_dict["type"] = agent.name.type agent_dict["actions"] = [ action_to_operation(action, keep_extra_keys=True) for action in agent_dto.actions ] agent_dict["default_actions"] = (complete_operations_options( get_default_operations(agent, keep_extra_keys=True)) if describe else []) return agent_dict
def create( report_processor: reports.ReportProcessor, resources_section: _Element, id_provider: IdProvider, resource_id: str, resource_agent_facade: ResourceAgentFacade, raw_operation_list: Optional[Iterable[ResourceOperationIn]] = None, meta_attributes: Optional[Mapping[str, str]] = None, instance_attributes: Optional[Mapping[str, str]] = None, allow_invalid_operation: bool = False, allow_invalid_instance_attributes: bool = False, use_default_operations: bool = True, resource_type: str = "resource", # TODO remove this arg do_not_report_instance_attribute_server_exists: bool = False, ): # pylint: disable=too-many-arguments # pylint: disable=too-many-locals """ Prepare all parts of primitive resource and append it into cib. report_processor -- a tool for warning/info/error reporting resources_section -- a place where the new resource will be appended id_provider -- elements' ids generator resource_id -- id of the new resource resource_agent_facade -- resource agent raw_operation_list -- specifies operations of the resource meta_attributes -- specifies meta attributes of the resource instance_attributes -- specifies instance attributes of the resource allow_invalid_operation -- flag for skipping validation of operations allow_invalid_instance_attributes -- flag for skipping validation of instance_attributes use_default_operations -- flag for completion operations with default actions specified in resource agent resource_type -- describes the resource for reports do_not_report_instance_attribute_server_exists -- dirty fix due to suboptimal architecture, TODO: fix the architecture and remove the param """ if raw_operation_list is None: raw_operation_list = [] if meta_attributes is None: meta_attributes = {} if instance_attributes is None: instance_attributes = {} filtered_raw_operation_list = [] for op in raw_operation_list: filtered_raw_operation_list.append( {name: "" if value is None else value for name, value in op.items()} ) if does_id_exist(resources_section, resource_id): raise LibraryError( reports.ReportItem.error( reports.messages.IdAlreadyExists(resource_id) ) ) validate_id(resource_id, "{0} name".format(resource_type)) agent_metadata = resource_agent_facade.metadata operation_list = prepare_operations( report_processor, filtered_raw_operation_list, get_default_operations( agent_metadata, necessary_only=not use_default_operations ), [operation.name for operation in agent_metadata.actions], are_new_role_names_supported(resources_section), allow_invalid=allow_invalid_operation, ) report_items = validate_resource_instance_attributes_create( resource_agent_facade, instance_attributes, resources_section, force=allow_invalid_instance_attributes, ) # TODO remove this "if", see pcs.lib.cib.remote_node.create for details if do_not_report_instance_attribute_server_exists: for report_item in report_items: if isinstance(report_item.message, reports.messages.InvalidOptions): report_msg = cast( reports.messages.InvalidOptions, report_item.message ) report_item.message = reports.messages.InvalidOptions( report_msg.option_names, sorted( [ value for value in report_msg.allowed if value != "server" ] ), report_msg.option_type, report_msg.allowed_patterns, ) report_processor.report_list(report_items) if report_processor.has_errors: raise LibraryError() return append_new( resources_section, id_provider, resource_id, agent_metadata.name.standard, agent_metadata.name.provider, agent_metadata.name.type, instance_attributes=instance_attributes, meta_attributes=meta_attributes, operation_list=operation_list, )