def upgrade(args): skip_phases_until = None context = str(uuid.uuid4()) cfg = get_config() configuration = prepare_configuration(args) answerfile_path = cfg.get('report', 'answerfile') userchoices_path = cfg.get('report', 'userchoices') if os.getuid(): raise CommandError('This command has to be run under the root user.') handle_output_level(args) if args.resume: context, configuration = fetch_last_upgrade_context() if not context: raise CommandError('No previous upgrade run to continue, remove `--resume` from leapp invocation to' 'start a new upgrade flow') os.environ['LEAPP_DEBUG'] = '1' if check_env_and_conf('LEAPP_DEBUG', 'debug', configuration) else '0' if os.environ['LEAPP_DEBUG'] == '1' or check_env_and_conf('LEAPP_VERBOSE', 'verbose', configuration): os.environ['LEAPP_VERBOSE'] = '1' else: os.environ['LEAPP_VERBOSE'] = '0' skip_phases_until = get_last_phase(context) logger = configure_logger() else: e = Execution(context=context, kind='upgrade', configuration=configuration) e.store() archive_logfiles() logger = configure_logger('leapp-upgrade.log') os.environ['LEAPP_EXECUTION_ID'] = context if args.resume: logger.info("Resuming execution after phase: %s", skip_phases_until) try: repositories = load_repositories() except LeappError as exc: raise CommandError(exc.message) workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot) process_whitelist_experimental(repositories, workflow, configuration, logger) warn_if_unsupported(configuration) with beautify_actor_exception(): logger.info("Using answerfile at %s", answerfile_path) workflow.load_answers(answerfile_path, userchoices_path) workflow.run(context=context, skip_phases_until=skip_phases_until, skip_dialogs=True) logger.info("Answerfile will be created at %s", answerfile_path) workflow.save_answers(answerfile_path, userchoices_path) report_errors(workflow.errors) report_inhibitors(context) generate_report_files(context) report_files = get_cfg_files('report', cfg) log_files = get_cfg_files('logs', cfg) report_info(report_files, log_files, answerfile_path, fail=workflow.failure) if workflow.failure: sys.exit(1)
def preupgrade(args): if os.getuid(): raise CommandError('This command has to be run under the root user.') if args.whitelist_experimental: args.whitelist_experimental = list( itertools.chain( *[i.split(',') for i in args.whitelist_experimental])) context = str(uuid.uuid4()) configuration = { 'debug': os.getenv('LEAPP_DEBUG', '0'), 'verbose': os.getenv('LEAPP_VERBOSE', '0'), 'whitelist_experimental': args.whitelist_experimental or () } e = Execution(context=context, kind='preupgrade', configuration=configuration) e.store() archive_logfiles() logger = configure_logger('leapp-preupgrade.log') os.environ['LEAPP_EXECUTION_ID'] = context try: repositories = load_repositories() except LeappError as exc: raise CommandError(exc.message) workflow = repositories.lookup_workflow('IPUWorkflow')() for actor_name in configuration.get('whitelist_experimental', ()): actor = repositories.lookup_actor(actor_name) if actor: workflow.whitelist_experimental_actor(actor) else: msg = 'No such Actor: {}'.format(actor_name) logger.error(msg) raise CommandError(msg) with beautify_actor_exception(): until_phase = 'ReportsPhase' logger.info('Executing workflow until phase: %s', until_phase) workflow.run(context=context, until_phase=until_phase, skip_dialogs=True) cfg = get_config() answerfile = args.save_answerfile or cfg.get('report', 'answerfile') logger.info("Answerfile will be created at %s", answerfile) workflow._answer_store.generate_for_workflow(workflow, answerfile) generate_report_files(context) report_errors(workflow.errors) report_files = [ os.path.join(cfg.get('report', 'dir'), r) for r in cfg.get('report', 'files').split(',') ] report_info([rf for rf in report_files if os.path.isfile(rf)], fail=workflow.failure) if workflow.failure: sys.exit(1)
def preupgrade(args, breadcrumbs): context = str(uuid.uuid4()) cfg = get_config() util.handle_output_level(args) configuration = util.prepare_configuration(args) answerfile_path = cfg.get('report', 'answerfile') userchoices_path = cfg.get('report', 'userchoices') if os.getuid(): raise CommandError('This command has to be run under the root user.') e = Execution(context=context, kind='preupgrade', configuration=configuration) e.store() util.archive_logfiles() logger = configure_logger('leapp-preupgrade.log') os.environ['LEAPP_EXECUTION_ID'] = context try: repositories = util.load_repositories() except LeappError as exc: raise CommandError(exc.message) workflow = repositories.lookup_workflow('IPUWorkflow')() util.warn_if_unsupported(configuration) util.process_whitelist_experimental(repositories, workflow, configuration, logger) with beautify_actor_exception(): workflow.load_answers(answerfile_path, userchoices_path) until_phase = 'ReportsPhase' logger.info('Executing workflow until phase: %s', until_phase) # Set the locale, so that the actors parsing command outputs that might be localized will not fail os.environ['LC_ALL'] = 'en_US.UTF-8' os.environ['LANG'] = 'en_US.UTF-8' workflow.run(context=context, until_phase=until_phase, skip_dialogs=True) logger.info("Answerfile will be created at %s", answerfile_path) workflow.save_answers(answerfile_path, userchoices_path) util.generate_report_files(context) report_errors(workflow.errors) report_inhibitors(context) report_files = util.get_cfg_files('report', cfg) log_files = util.get_cfg_files('logs', cfg) report_info(report_files, log_files, answerfile_path, fail=workflow.failure) if workflow.failure: sys.exit(1)
def preupgrade(args): if os.getuid(): raise CommandError('This command has to be run under the root user.') if args.whitelist_experimental: args.whitelist_experimental = list(itertools.chain(*[i.split(',') for i in args.whitelist_experimental])) context = str(uuid.uuid4()) configuration = { 'debug': os.getenv('LEAPP_DEBUG', '0'), 'verbose': os.getenv('LEAPP_VERBOSE', '0'), 'whitelist_experimental': args.whitelist_experimental or () } e = Execution(context=context, kind='preupgrade', configuration=configuration) e.store() archive_logfiles() logger = configure_logger('leapp-preupgrade.log') os.environ['LEAPP_EXECUTION_ID'] = context try: repositories = load_repositories() except LeappError as exc: raise CommandError(exc.message) workflow = repositories.lookup_workflow('IPUWorkflow')() for actor_name in configuration.get('whitelist_experimental', ()): actor = repositories.lookup_actor(actor_name) if actor: workflow.whitelist_experimental_actor(actor) else: msg = 'No such Actor: {}'.format(actor_name) logger.error(msg) raise CommandError(msg) with beautify_actor_exception(): until_phase = 'ReportsPhase' logger.info('Executing workflow until phase: %s', until_phase) workflow.run(context=context, until_phase=until_phase) report_errors(workflow.errors) report_txt, report_json = [os.path.join(get_config().get('report', 'dir'), 'leapp-report.{}'.format(f)) for f in ['txt', 'json']] report_info([report_txt, report_json], fail=workflow.errors) # fetch all report messages as a list of dicts messages = fetch_upgrade_report_raw(context, renderers=False) with open(report_json, 'w+') as f: json.dump({'entries': messages}, f, indent=2) if workflow.failure: sys.exit(1)
def upgrade(args, breadcrumbs): skip_phases_until = None context = str(uuid.uuid4()) cfg = get_config() util.handle_output_level(args) answerfile_path = cfg.get('report', 'answerfile') userchoices_path = cfg.get('report', 'userchoices') # Processing of parameters passed by the rerun call, these aren't actually command line arguments # therefore we have to assume that they aren't even in `args` as they are added only by rerun. only_with_tags = args.only_with_tags if 'only_with_tags' in args else None resume_context = args.resume_context if 'resume_context' in args else None report_schema = util.process_report_schema(args, cfg) if os.getuid(): raise CommandError('This command has to be run under the root user.') if args.resume: context, configuration = util.fetch_last_upgrade_context(resume_context) if not context: raise CommandError('No previous upgrade run to continue, remove `--resume` from leapp invocation to' ' start a new upgrade flow') os.environ['LEAPP_DEBUG'] = '1' if util.check_env_and_conf('LEAPP_DEBUG', 'debug', configuration) else '0' if os.environ['LEAPP_DEBUG'] == '1' or util.check_env_and_conf('LEAPP_VERBOSE', 'verbose', configuration): os.environ['LEAPP_VERBOSE'] = '1' else: os.environ['LEAPP_VERBOSE'] = '0' util.restore_leapp_env_vars(context) skip_phases_until = util.get_last_phase(context) else: util.disable_database_sync() configuration = util.prepare_configuration(args) e = Execution(context=context, kind='upgrade', configuration=configuration) e.store() util.archive_logfiles() logger = configure_logger('leapp-upgrade.log') os.environ['LEAPP_EXECUTION_ID'] = context if args.resume: logger.info("Resuming execution after phase: %s", skip_phases_until) try: repositories = util.load_repositories() except LeappError as exc: raise CommandError(exc.message) workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot) util.process_whitelist_experimental(repositories, workflow, configuration, logger) util.warn_if_unsupported(configuration) with beautify_actor_exception(): logger.info("Using answerfile at %s", answerfile_path) workflow.load_answers(answerfile_path, userchoices_path) # Set the locale, so that the actors parsing command outputs that might be localized will not fail os.environ['LC_ALL'] = 'en_US.UTF-8' os.environ['LANG'] = 'en_US.UTF-8' workflow.run(context=context, skip_phases_until=skip_phases_until, skip_dialogs=True, only_with_tags=only_with_tags) logger.info("Answerfile will be created at %s", answerfile_path) workflow.save_answers(answerfile_path, userchoices_path) report_errors(workflow.errors) report_inhibitors(context) util.generate_report_files(context, report_schema) report_files = util.get_cfg_files('report', cfg) log_files = util.get_cfg_files('logs', cfg) report_info(report_files, log_files, answerfile_path, fail=workflow.failure) if workflow.failure: sys.exit(1)