def _ticket_operation(operation, env, ticket, site_ip): if not env.is_cib_live: raise LibraryError(reports.live_environment_required(["CIB"])) if not site_ip: site_ip_list = resource.find_bound_ip( get_resources(env.get_cib()), get_config_file_name(env.booth.name) ) if len(site_ip_list) != 1: raise LibraryError( booth_reports.booth_cannot_determine_local_site_ip() ) site_ip = site_ip_list[0] stdout, stderr, return_code = env.cmd_runner().run([ settings.booth_binary, operation, "-s", site_ip, ticket ]) if return_code != 0: raise LibraryError( booth_reports.booth_ticket_operation_failed( operation, join_multilines([stderr, stdout]), site_ip, ticket ) )
def ticket_operation(operation, env, name, ticket, site_ip): if not site_ip: site_ip_list = resource.find_bound_ip( get_resources(env.get_cib()), get_config_file_name(name) ) if len(site_ip_list) != 1: raise LibraryError( booth_reports.booth_cannot_determine_local_site_ip() ) site_ip = site_ip_list[0] command_output, return_code = env.cmd_runner().run([ settings.booth_binary, operation, "-s", site_ip, ticket ]) if return_code != 0: raise LibraryError( booth_reports.booth_ticket_operation_failed( operation, command_output, site_ip, ticket ) )
def test_refuse_when_name_starts_with_slash(self, mock_path_exists): mock_path_exists.return_value = True assert_raise_library_error( lambda: env.get_config_file_name("/booth"), (severities.ERROR, report_codes.BOOTH_INVALID_NAME, { "name": "/booth", "reason": "contains illegal character '/'", }), )
def config_destroy(env, ignore_config_load_problems=False): env.booth.command_expect_live_env() if not env.is_cib_live: raise LibraryError(reports.live_environment_required(["CIB"])) name = env.booth.name config_is_used = partial(booth_reports.booth_config_is_used, name) report_list = [] if resource.find_for_config( get_resources(env.get_cib()), get_config_file_name(name), ): report_list.append(config_is_used("in cluster resource")) #Only systemd is currently supported. Initd does not supports multiple #instances (here specified by name) if external.is_systemctl(): if external.is_service_running(env.cmd_runner(), "booth", name): report_list.append(config_is_used("(running in systemd)")) if external.is_service_enabled(env.cmd_runner(), "booth", name): report_list.append(config_is_used("(enabled in systemd)")) if report_list: raise LibraryError(*report_list) authfile_path = None try: authfile_path = config_structure.get_authfile( parse(env.booth.get_config_content()) ) except LibraryError: if not ignore_config_load_problems: raise LibraryError(booth_reports.booth_cannot_identify_keyfile()) #if content not received, not valid,... still remove config needed env.report_processor.process( booth_reports.booth_cannot_identify_keyfile( severity=ReportItemSeverity.WARNING ) ) if( authfile_path and os.path.dirname(authfile_path) == settings.booth_config_dir ): env.booth.set_key_path(authfile_path) env.booth.remove_key() env.booth.remove_config()
def test_refuse_when_name_starts_with_slash(self, mock_path_exists): mock_path_exists.return_value = True assert_raise_library_error( lambda: env.get_config_file_name("/booth"), ( severities.ERROR, report_codes.BOOTH_INVALID_NAME, { "name": "/booth", "reason": "contains illegal character '/'", } ), )
def create_in_cluster(env, ip, allow_absent_resource_agent=False): """ Create group with ip resource and booth resource LibraryEnvironment env provides all for communication with externals string ip determines float ip for the operation of the booth bool allow_absent_resource_agent is flag allowing create booth resource even if its agent is not installed """ resources_section = get_resources(env.get_cib()) id_provider = IdProvider(resources_section) name = env.booth.name booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) create_id = partial( resource.create_resource_id, resources_section, name ) get_agent = partial( find_valid_resource_agent_by_name, env.report_processor, env.cmd_runner(), allowed_absent=allow_absent_resource_agent ) create_primitive = partial( primitive.create, env.report_processor, resources_section, id_provider ) into_booth_group = partial( group.place_resource, group.provide_group(resources_section, create_id("group")), ) into_booth_group(create_primitive( create_id("ip"), get_agent("ocf:heartbeat:IPaddr2"), instance_attributes={"ip": ip}, )) into_booth_group(create_primitive( create_id("service"), get_agent("ocf:pacemaker:booth-site"), instance_attributes={"config": booth_config_file_path}, )) env.push_cib()
def create_in_cluster(env, name, ip, resource_create, resource_remove): #TODO resource_create is provisional hack until resources are not moved to #lib resources_section = get_resources(env.get_cib()) booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) resource.get_creator(resource_create, resource_remove)( ip, booth_config_file_path, create_id=partial(resource.create_resource_id, resources_section, name))
def create_in_cluster(env, name, ip, resource_create): #TODO resource_create is provisional hack until resources are not moved to #lib resources_section = get_resources(env.get_cib()) booth_config_file_path = get_config_file_name(name) if resource.find_for_config(resources_section, booth_config_file_path): raise LibraryError(booth_reports.booth_already_in_cib(name)) resource.get_creator(resource_create)( ip, booth_config_file_path, create_id = partial( resource.create_resource_id, resources_section, name ) )
def _find_resource_elements_for_operation(env, name, allow_multiple): booth_element_list = resource.find_for_config( get_resources(env.get_cib()), get_config_file_name(name), ) if not booth_element_list: raise LibraryError(booth_reports.booth_not_exists_in_cib(name)) if len(booth_element_list) > 1: if not allow_multiple: raise LibraryError(booth_reports.booth_multiple_times_in_cib(name)) env.report_processor.process( booth_reports.booth_multiple_times_in_cib( name, severity=ReportItemSeverity.WARNING, )) return booth_element_list
def remove_from_cluster(env, name, resource_remove): #TODO resource_remove is provisional hack until resources are not moved to #lib try: num_of_removed_booth_resources = resource.get_remover(resource_remove)( get_resources(env.get_cib()), get_config_file_name(name), ) if num_of_removed_booth_resources > 1: env.report_processor.process( booth_reports.booth_multiple_times_in_cib( name, severity=ReportItemSeverity.WARNING, ) ) except resource.BoothNotFoundInCib: raise LibraryError(booth_reports.booth_not_exists_in_cib(name)) except resource.BoothMultipleOccurenceFoundInCib: raise LibraryError(booth_reports.booth_multiple_times_in_cib(name))
def _find_resource_elements_for_operation(env, name, allow_multiple): booth_element_list = resource.find_for_config( get_resources(env.get_cib()), get_config_file_name(name), ) if not booth_element_list: raise LibraryError(booth_reports.booth_not_exists_in_cib(name)) if len(booth_element_list) > 1: if not allow_multiple: raise LibraryError(booth_reports.booth_multiple_times_in_cib(name)) env.report_processor.process( booth_reports.booth_multiple_times_in_cib( name, severity=ReportItemSeverity.WARNING, ) ) return booth_element_list