Skip to content

Commit

Permalink
fixup! Add an ERROR report group
Browse files Browse the repository at this point in the history
  • Loading branch information
matejmatuska committed Aug 23, 2023
1 parent 0fb569e commit b30dba1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 11 additions & 7 deletions leapp/reporting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Groups(BaseListPrimitive):
INHIBITOR = 'inhibitor'
# This is used for framework error reports
# Reports indicating failure in actors should use the FAILURE group
ERROR = 'error'
_ERROR = 'error'
FAILURE = 'failure'
ACCESSIBILITY = 'accessibility'
AUTHENTICATION = 'authentication'
Expand Down Expand Up @@ -189,7 +189,11 @@ def __init__(self, *args, **kwargs):

# To allow backwards-compatibility with previous report-schema
# Groups that match _DEPRECATION_FLAGS will be shown as flags, the rest as tags
_DEPRECATION_FLAGS = [Groups.INHIBITOR, Groups.FAILURE, Groups.ERROR]
_DEPRECATION_FLAGS = [Groups.INHIBITOR, Groups.FAILURE]

# NOTE(mmatuska): this a temporary solution until Groups._ERROR in the json report-schema
# is altered to account for this addition of Groups_ERROR
_UPCOMING_DEPRECATION_FLAGS = [Groups._ERROR]


class Key(BasePrimitive):
Expand Down Expand Up @@ -383,9 +387,9 @@ def _create_report_object(entries):
entry.apply(report)

if Groups.INHIBITOR in report.get('groups', []):
if Groups.ERROR in report.get('groups', []):
if Groups._ERROR in report.get('groups', []):
# *error != inhibitor*
msg = ('Only one of Groups.ERROR and Groups.INHIBITOR can be set at once.'
msg = ('Only one of Groups._ERROR and Groups.INHIBITOR can be set at once.'
' Maybe you were looking for Groups.FAILURE?')
raise ValueError(msg)

Expand All @@ -394,9 +398,9 @@ def _create_report_object(entries):
# Currently we know that 'flags' does not exist otherwise so it's
# safe to just set it
report['flags'] = [Groups.INHIBITOR]
if Groups.ERROR in report.get('groups', []):
if Groups._ERROR in report.get('groups', []):
# see above for explanation
report['flags'] = [Groups.ERROR]
report['flags'] = [Groups._ERROR]

return Report(report=report)

Expand Down Expand Up @@ -449,7 +453,7 @@ def create_report_from_error(error_dict):
Summary(error.details or ""),
Severity('high'),
Audience('sysadmin'),
Groups([Groups.ERROR])
Groups([Groups._ERROR])
]
report = _create_report_object(entries)
return json.loads(report.dump()['report'])
4 changes: 2 additions & 2 deletions leapp/utils/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _filter_reports(reports, severity=None, has_flag=None):
from leapp.utils.report import has_flag_group # noqa; pylint: disable=import-outside-toplevel

def is_ordinary_report(report):
return not has_flag_group(report, Groups.ERROR) and not has_flag_group(report, Groups.INHIBITOR)
return not has_flag_group(report, Groups._ERROR) and not has_flag_group(report, Groups.INHIBITOR)

result = reports
if has_flag is False:
Expand All @@ -133,7 +133,7 @@ def _print_reports_summary(reports):
# The following imports are required to be here to avoid import loop problems
from leapp.reporting import Groups, Severity # noqa; pylint: disable=import-outside-toplevel

errors = _filter_reports(reports, has_flag=Groups.ERROR)
errors = _filter_reports(reports, has_flag=Groups._ERROR)
inhibitors = _filter_reports(reports, has_flag=Groups.INHIBITOR)

ordinary = _filter_reports(reports, has_flag=False)
Expand Down
9 changes: 5 additions & 4 deletions leapp/utils/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from leapp.reporting import (
_DEPRECATION_FLAGS,
_UPCOMING_DEPRECATION_FLAGS,
Groups,
Remediation,
Severity,
Expand Down Expand Up @@ -107,7 +108,7 @@ def has_flag_group(message, group):


def importance(message):
if has_flag_group(message, Groups.ERROR):
if has_flag_group(message, Groups._ERROR):
return -1
if has_flag_group(message, Groups.INHIBITOR):
return 0
Expand All @@ -121,7 +122,7 @@ def generate_report_file(messages_to_report, context, path, report_schema='1.1.0
with io.open(path, 'w', encoding='utf-8') as f:
for message in sorted(messages_to_report, key=importance):
flag = ''
if has_flag_group(message, Groups.ERROR):
if has_flag_group(message, Groups._ERROR):
flag = '(error)'
elif has_flag_group(message, Groups.INHIBITOR):
flag = '(inhibitor)'
Expand Down Expand Up @@ -158,8 +159,8 @@ def generate_report_file(messages_to_report, context, path, report_schema='1.1.0
messages_to_report = list(messages_to_report)
for msg in messages_to_report:
groups = msg.pop('groups', [])
msg['flags'] = [g for g in groups if g in _DEPRECATION_FLAGS]
msg['tags'] = [g for g in groups if g not in _DEPRECATION_FLAGS]
msg['flags'] = [g for g in groups if g in _DEPRECATION_FLAGS and g not in _UPCOMING_DEPRECATION_FLAGS]
msg['tags'] = [g for g in groups if g not in _DEPRECATION_FLAGS and g not in _UPCOMING_DEPRECATION_FLAGS]
if report_schema_tuple == (1, 2, 0):
# DEPRECATED: flags, tags
# NOTE(pstodulk): This is a temporary solution to ensure that
Expand Down

0 comments on commit b30dba1

Please sign in to comment.