Exemplo n.º 1
0
def test_checkpoints():
    checkpoint(actor=_ACTOR_NAME, phase=_PHASE_NAME, context=_CONTEXT_NAME, hostname=_HOSTNAME)
    result = get_checkpoints(_CONTEXT_NAME)
    assert result and len(result) == 1
    assert result[0]['id']
    assert result[0]['actor'] == _ACTOR_NAME
    assert result[0]['phase'] == _PHASE_NAME
    assert result[0]['stamp'].endswith('Z')
Exemplo n.º 2
0
def get_last_phase(context):
    checkpoints = get_checkpoints(context=context)
    if checkpoints:
        return checkpoints[-1]['phase']
Exemplo n.º 3
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 = fetch_last_upgrade_context()
    if args.from_phase not in set(
        [chkpt['phase'] for chkpt in get_checkpoints(context=last_context)]):
        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, ))

    archive_logfiles()
    upgrade(
        Namespace(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,
                  whitelist_experimental=[],
                  enablerepo=[]))