예제 #1
0
def main():
    """Automated reimaging of a list of hosts."""
    # Setup
    args = parse_args()
    lib.ensure_shell_mode()
    user = lib.get_running_user()
    log_path = setup_logging(user)
    if args.debug:
        logger.setLevel(logging.DEBUG)

    logger.info('wmf-auto-reimage called with args: {args}'.format(args=args))
    lib.print_line('START. To monitor the full log:')
    lib.print_line('sudo tail -F {log}'.format(log=log_path), skip_time=True)

    try:
        retcode = run(args, user, log_path)
    except BaseException as e:
        message = 'Unable to run wmf-auto-reimage'
        lib.print_line('{message}: {error}'.format(message=message, error=e))
        logger.exception(message)
        retcode = 2
    finally:
        lib.print_line('END')

    return retcode
예제 #2
0
def main():
    """Run the automated reimaging of a single host."""
    # Setup
    phab_client = None
    args = parse_args()
    lib.ensure_shell_mode()
    user = lib.get_running_user()
    log_path = setup_logging(user, args.host)
    cumin_output_path = log_path.replace('.log', '_cumin.out')
    if args.debug:
        logger.setLevel(logging.DEBUG)

    logger.info('wmf-auto-reimage-host called with args: {args}'.format(args=args))
    lib.print_line('REIMAGE START | To monitor the full log and cumin output:', host=args.host)
    lib.print_line('sudo tail -F {log}'.format(log=log_path), skip_time=True)
    lib.print_line('sudo tail -F {log}'.format(log=cumin_output_path), skip_time=True)

    try:
        lib.ensure_ipmi_password()
        lib.check_remote_ipmi(args.mgmt)
        if args.rename_mgmt:
            lib.check_remote_ipmi(args.rename_mgmt)

        if args.phab_task_id is not None:
            phab_client = lib.get_phabricator_client()
            lib.phabricator_task_update(
                phab_client, args.phab_task_id, lib.PHAB_COMMENT_PRE.format(
                    user=user, hostname=socket.getfqdn(), hosts=args.host, log=log_path))

        try:
            # This is needed due to a bug in tqdm and a limitation in Cumin
            with open(cumin_output_path, 'w', 1) as cumin_output:
                stderr = sys.stderr
                stdout = sys.stdout
                sys.stderr = cumin_output
                sys.stdout = cumin_output
                run(args, user, log_path)
                retcode = 0
        finally:
            sys.stderr = stderr
            sys.stdout = stdout
    except BaseException as e:
        message = 'Unable to run wmf-auto-reimage-host'
        lib.print_line('{message}: {error}'.format(message=message, error=e), host=args.host)
        logger.exception(message)
        retcode = 2
    finally:
        lib.print_line('REIMAGE END | retcode={ret}'.format(ret=retcode), host=args.host)

    # Comment on the Phabricator task
    if args.phab_task_id is not None and phab_client is not None:
        phabricator_message = lib.get_phabricator_post_message({retcode: [args.host]})
        lib.phabricator_task_update(phab_client, args.phab_task_id, phabricator_message)

    return retcode