Skip to content

Commit

Permalink
Control leapp report format
Browse files Browse the repository at this point in the history
Leapp-repository part of PR686 which contains appropriate changes for
the leapp preupgrade and upgrade commands.

Depends-On: oamg/leapp#686
  • Loading branch information
fernflower committed Sep 13, 2021
1 parent f10556f commit 1a0c3fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion commands/preupgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
' with Red Hat Subscription Manager')
@command_opt('enablerepo', action='append', metavar='<repoid>',
help='Enable specified repository. Can be used multiple times.')
@command_opt('report-schema', help='Specify report schema version for leapp-report.json', choices=['1.0.0', '1.1.0'],
default=get_config().get('report', 'schema'))
def preupgrade(args):
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')
report_schema = util.process_report_schema(args, cfg)

if os.getuid():
raise CommandError('This command has to be run under the root user.')
Expand All @@ -50,7 +53,7 @@ def preupgrade(args):

logger.info("Answerfile will be created at %s", answerfile_path)
workflow.save_answers(answerfile_path, userchoices_path)
util.generate_report_files(context)
util.generate_report_files(context, report_schema)
report_errors(workflow.errors)
report_inhibitors(context)
report_files = util.get_cfg_files('report', cfg)
Expand Down
6 changes: 5 additions & 1 deletion commands/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
' with Red Hat Subscription Manager')
@command_opt('enablerepo', action='append', metavar='<repoid>',
help='Enable specified repository. Can be used multiple times.')
@command_opt('report-schema', help='Specify report schema version for leapp-report.json', choices=['1.0.0', '1.1.0'],
default=get_config().get('report', 'schema'))
def upgrade(args):
skip_phases_until = None
context = str(uuid.uuid4())
Expand All @@ -39,6 +41,8 @@ def upgrade(args):
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.')

Expand Down Expand Up @@ -82,7 +86,7 @@ def upgrade(args):
workflow.save_answers(answerfile_path, userchoices_path)
report_errors(workflow.errors)
report_inhibitors(context)
util.generate_report_files(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)
Expand Down
14 changes: 11 additions & 3 deletions commands/upgrade/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def check_env_and_conf(env_var, conf_var, configuration):
return os.getenv(env_var, '0') == '1' or configuration.get(conf_var, '0') == '1'


def generate_report_files(context):
def generate_report_files(context, report_schema):
"""
Generates all report files for specific leapp run (txt and json format)
"""
Expand All @@ -112,8 +112,8 @@ def generate_report_files(context):
'leapp-report.{}'.format(f)) for f in ['txt', 'json']]
# fetch all report messages as a list of dicts
messages = fetch_upgrade_report_messages(context)
generate_report_file(messages, context, report_json)
generate_report_file(messages, context, report_txt)
generate_report_file(messages, context, report_json, report_schema)
generate_report_file(messages, context, report_txt, report_schema)


def get_cfg_files(section, cfg, must_exist=True):
Expand Down Expand Up @@ -178,3 +178,11 @@ def process_whitelist_experimental(repositories, workflow, configuration, logger
if logger:
logger.error(msg)
raise CommandError(msg)


def process_report_schema(args, configuration):
default_report_schema = configuration.get('report', 'schema')
if args.report_schema and args.report_schema > default_report_schema:
raise CommandError('--report-schema version can not be greater that the '
'actual {} one.'.format(default_report_schema))
return args.report_schema or default_report_schema

0 comments on commit 1a0c3fc

Please sign in to comment.