oamg / leapp

Leapp - Application & OS Modernization Framework (For in-place upgrades, follow leapp-repository)
https://oamg.github.io/leapp/
Apache License 2.0
87 stars 70 forks source link

Generate empty report correctly #828

Closed pirat89 closed 1 year ago

pirat89 commented 1 year ago

On Python2, the json.dumps library can produce either unicode or str output. Nowadays, the unicode is required, however in case the input for json.dumps function does not contain any unicode objects (e.g. when no report entry exists), it produces str type.

Also ensure the generated json file has the empty newline in the end of the file.

Relates: #821 JIRA: OAMG-8996

Additional info:

(Pdb) json.dumps({'entries': [], 'leapp_run_id': context}, indent=2, ensure_ascii=False)
'{\n  "leapp_run_id": "c6aa7f2a-7aaf-4fc0-9bd3-667f81395e9f", \n  "entries": []\n}'
(Pdb) json.dumps({'entries': ["foo"], 'leapp_run_id': context}, indent=2, ensure_ascii=False)
'{\n  "leapp_run_id": "c6aa7f2a-7aaf-4fc0-9bd3-667f81395e9f", \n  "entries": [\n    "foo"\n  ]\n}'
(Pdb) json.dumps({'entries': [u"foo"], 'leapp_run_id': context}, indent=2, ensure_ascii=False)
u'{\n  "leapp_run_id": "c6aa7f2a-7aaf-4fc0-9bd3-667f81395e9f", \n  "entries": [\n    "foo"\n  ]\n}'
(Pdb) 

Original issue when an empty report has been generated:

Traceback (most recent call last):
  File "/usr/bin/leapp", line 9, in <module>
    load_entry_point('leapp==0.15.1', 'console_scripts', 'leapp')()
  File "/usr/lib/python2.7/site-packages/leapp/cli/__init__.py", line 45, in main
    cli.command.execute('leapp version {}'.format(VERSION))
  File "/usr/lib/python2.7/site-packages/leapp/utils/clicmd.py", line 111, in execute
    args.func(args)
  File "/usr/lib/python2.7/site-packages/leapp/utils/clicmd.py", line 133, in called
    self.target(args)
  File "/usr/lib/python2.7/site-packages/leapp/cli/commands/upgrade/breadcrumbs.py", line 163, in wrapper
    return f(*args, breadcrumbs=breadcrumbs, **kwargs)
  File "/usr/lib/python2.7/site-packages/leapp/cli/commands/preupgrade/__init__.py", line 78, in preupgrade
    util.generate_report_files(context, report_schema)
  File "/usr/lib/python2.7/site-packages/leapp/cli/commands/upgrade/util.py", line 147, in generate_report_files
    generate_report_file(messages, context, report_json, report_schema)
  File "/usr/lib/python2.7/site-packages/leapp/utils/report.py", line 168, in generate_report_file
    f.write(data)
TypeError: must be unicode, not str
github-actions[bot] commented 1 year ago

Thank you for contributing to the Leapp project!

Please note that every PR needs to comply with the Leapp Guidelines and must pass all tests in order to be mergeable. If you want to request a review or rebuild a package in copr, you can use following commands as a comment:

To launch regression testing public members of oamg organization can leave the following comment:

Please open ticket in case you experience technical problem with the CI. (RH internal only)

Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please consider rerunning the CI by commenting leapp-ci build (might require several comments). If the problem persists, contact leapp-infra.

fernflower commented 1 year ago

/rerun

github-actions[bot] commented 1 year ago

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/5890445

pirat89 commented 1 year ago

@fernflower aah. copy&paste error /o\ should be fixed now

pirat89 commented 1 year ago

/rerun

github-actions[bot] commented 1 year ago

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/5890572

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-7.9-rhui/5886104;5890445 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-8.6-rhui/5886104;5890572 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-7.9-rhui/5886104;5890572 regression testing has been created. Once finished, results should be available here. Full pipeline log.

fernflower commented 1 year ago

/rerun

github-actions[bot] commented 1 year ago

Copr build succeeded: https://copr.fedorainfracloud.org/coprs/build/5900120

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-8.6-rhui/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-7.9-rhui/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-8.6.0-Nightly/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-8.8.0-Nightly/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-7.9-ZStream/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.

github-actions[bot] commented 1 year ago

Testing Farm request for RHEL-7.9-ZStream/5886104;5900120 regression testing has been created. Once finished, results should be available here. Full pipeline log.