Beispiel #1
0
def rerun(args):

    if os.environ.get('LEAPP_UNSUPPORTED') != '1':
        raise CommandError('This command requires the environment variable LEAPP_UNSUPPORTED="1" to be set!')

    if args.from_phase not in RERUN_SUPPORTED_PHASES:
        raise CommandError('This command is only supported for {}'.format(', '.join(RERUN_SUPPORTED_PHASES)))

    context = str(uuid.uuid4())
    last_context, configuration = util.fetch_last_upgrade_context()
    phases = [chkpt['phase'] for chkpt in util.get_checkpoints(context=last_context)]
    if args.from_phase not in set(phases):
        raise CommandError('Phase {} has not been executed in the last leapp upgrade execution. '
                           'Cannot rerun not executed phase'.format(args.from_phase))

    if not last_context:
        raise CommandError('No previous upgrade run to rerun - '
                           'leapp upgrade has to be run before leapp rerun can be used')

    with get_connection(None) as db:
        e = Execution(context=context, kind='rerun', configuration=configuration)

        e.store(db)

        clone_context(last_context, context, db)
        db.execute('''
            DELETE FROM audit WHERE id IN (
                SELECT
                    audit.id          AS id
                FROM
                    audit
                JOIN
                    data_source ON data_source.id = audit.data_source_id
                WHERE
                    audit.context = ? AND audit.event = 'checkpoint'
                    AND data_source.phase LIKE 'FirstBoot%'
            );
        ''', (context,))
        db.execute('''DELETE FROM message WHERE context = ? and type = 'ErrorModel';''', (context,))

    util.archive_logfiles()
    upgrade(Namespace(  # pylint: disable=no-value-for-parameter
        resume=True,
        resume_context=context,
        only_with_tags=args.only_actors_with_tag or [],
        debug=args.debug,
        verbose=args.verbose,
        reboot=False,
        no_rhsm=False,
        channel=None,
        whitelist_experimental=[],
        enablerepo=[]))
Beispiel #2
0
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)
Beispiel #3
0
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)