Example #1
0
def test_report_backwards_compatibility():
    msg1 = {
        u'groups': [u'selinux', u'security'],
        u'title': u'SElinux relabeling has been scheduled',
        'timeStamp': u'2021-02-10T13:13:40.576437Z',
        'hostname': u'ivasilev-tagsflagsgroups',
        'actor': u'check_se_linux',
        u'summary':
        u'SElinux relabeling has been scheduled as the status was permissive/enforcing.',
        u'audience': u'sysadmin',
        u'key': u'c12a05a22be0b5bc0af3f1119898ea6d8639d9c4',
        'id':
        '29279fc2e3100cfdf8ac30f48b293185192672d5a5ae9e0cfbc76cbfc919d807',
        u'severity': u'info'
    }
    report = [msg1]
    # make sure normal mode works
    for report_format in ['.json', '.txt']:
        reportfile = tempfile.NamedTemporaryFile(suffix=report_format)
        generate_report_file(report, 'leapp-run-id', reportfile.name, '1.1.0')
    # make sure report output conversion to specific version works as well
    for report_format in ['.json', '.txt']:
        reportfile = tempfile.NamedTemporaryFile(suffix=report_format)
        generate_report_file(report, 'leapp-run-id', reportfile.name, '1.0.0')
        with open(reportfile.name) as f:
            data = f.read()
        if report_format == '.json':
            a_report = json.loads(data)
            msg = a_report['entries'][0]
            assert 'key' not in msg
        else:
            assert 'Key' not in data
Example #2
0
def generate_report_files(context):
    """
    Generates all report files for specific leapp run (txt and json format)
    """
    cfg = get_config()
    report_txt, report_json = [os.path.join(cfg.get('report', 'dir'),
                                            '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)