def send_all_config_to_node( communicator, reporter, target_list, rewrite_existing=False, skip_wrong_config=False, ): """ Send all booth configs from default booth config directory and theri authfiles to specified node. communicator -- NodeCommunicator reporter -- report processor target_list list -- list of targets to which configs should be delivered rewrite_existing -- if True rewrite existing file skip_wrong_config -- if True skip local configs that are unreadable """ # TODO adapt to new file transfer framework once it is written # TODO the function is not modular enough - it raises LibraryError file_list = [] for conf_file_name in sorted(config_files.get_all_configs_file_names()): config_file = FileInstance.for_booth_config(conf_file_name) try: booth_conf_data = config_file.raw_file.read() ( authfile_name, authfile_data, authfile_report_list, ) = config_files.get_authfile_name_and_data( config_file.raw_to_facade(booth_conf_data)) reporter.report_list(authfile_report_list) file_list.append({ "name": conf_file_name, "data": booth_conf_data.decode("utf-8"), "is_authfile": False, }) if authfile_name and authfile_data: file_list.append({ "name": authfile_name, "data": base64.b64encode(authfile_data).decode("utf-8"), "is_authfile": True, }) except RawFileError as e: reporter.report( raw_file_error_report( e, force_code=report_codes.SKIP_UNREADABLE_CONFIG, is_forced_or_warning=skip_wrong_config, )) except ParserErrorException as e: reporter.report_list( config_file.parser_exception_to_report_list( e, force_code=report_codes.SKIP_UNREADABLE_CONFIG, is_forced_or_warning=skip_wrong_config, )) if reporter.has_errors: raise LibraryError() if not file_list: # no booth configs exist, nothing to be synced return reporter.report( ReportItem.info(reports.messages.BoothConfigDistributionStarted())) com_cmd = BoothSaveFiles(reporter, file_list, rewrite_existing=rewrite_existing) com_cmd.set_targets(target_list) run(communicator, com_cmd) if reporter.has_errors: raise LibraryError()
def config_sync( env: LibraryEnvironment, instance_name=None, skip_offline_nodes=False, ): """ Send specified local booth configuration to all nodes in the local cluster. env string instance_name -- booth instance name skip_offline_nodes -- if True offline nodes will be skipped """ report_processor = env.report_processor booth_env = env.get_booth_env(instance_name) if not env.is_cib_live: raise LibraryError( ReportItem.error( reports.messages.LiveEnvironmentRequired([file_type_codes.CIB ]))) cluster_nodes_names, report_list = get_existing_nodes_names( env.get_corosync_conf()) if not cluster_nodes_names: report_list.append( ReportItem.error(reports.messages.CorosyncConfigNoNodesDefined())) report_processor.report_list(report_list) try: booth_conf_data = booth_env.config.read_raw() booth_conf = booth_env.config.raw_to_facade(booth_conf_data) if isinstance(booth_env.config.raw_file, GhostFile): authfile_data = booth_env.key.read_raw() authfile_path = booth_conf.get_authfile() authfile_name = (os.path.basename(authfile_path) if authfile_path else None) else: ( authfile_name, authfile_data, authfile_report_list, ) = config_files.get_authfile_name_and_data(booth_conf) report_processor.report_list(authfile_report_list) except RawFileError as e: report_processor.report(raw_file_error_report(e)) except ParserErrorException as e: report_processor.report_list( booth_env.config.parser_exception_to_report_list(e)) if report_processor.has_errors: raise LibraryError() com_cmd = BoothSendConfig( env.report_processor, booth_env.instance_name, booth_conf_data, authfile=authfile_name, authfile_data=authfile_data, skip_offline_targets=skip_offline_nodes, ) com_cmd.set_targets(env.get_node_target_factory().get_target_list( cluster_nodes_names, skip_non_existing=skip_offline_nodes, )) run_and_raise(env.get_node_communicator(), com_cmd)
def test_no_auth_file(self): conf = ConfigFacade.create([], []) self.assertEqual((None, None, []), config_files.get_authfile_name_and_data(conf))