Skip to content

Commit

Permalink
POC of check custom modifications
Browse files Browse the repository at this point in the history
This commit introduces an actor that processes the
CustomModification messages and produces report entries.
Some basic unit tests added as well.

RHEL-1774
  • Loading branch information
fernflower committed Dec 4, 2023
1 parent ad42184 commit 1dc9922
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from leapp.actors import Actor
from leapp.libraries.actor import checkcustommodifications
from leapp.models import CustomModifications, Report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class CheckCustomModificationsActor(Actor):
"""
Checks CustomModifications messages and produces a report about files in leapp directories that have been
modified or newly added.
"""

name = 'check_custom_modifications_actor'
consumes = (CustomModifications,)
produces = (Report,)
tags = (IPUWorkflowTag, ChecksPhaseTag)

def process(self):
checkcustommodifications.report_any_modifications()
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from leapp import reporting
from leapp.libraries.stdlib import api
from leapp.models import CustomModifications


def _create_report(msgs):
if not msgs:
# Nothing to report
return
report_type = msgs[0].type
discovered_files = '\n'.join(
['- {filename}{actor}'.format(filename=m.filename,
actor=' ({} Actor)'.format(m.actor_name) if m.actor_name else '')
for m in msgs])
title = '{report_type} files were discovered on your system in leapp directories'
summary = ('Apparently some {report_type} files have been found in leapp installation directories.\n'
'Please consult the list of discovered files for more information:\n'
'{discovered_files}')
report_parts = [
reporting.Title(title.format(report_type=report_type.capitalize())),
reporting.Summary(summary.format(report_type=report_type, discovered_files=discovered_files)),
reporting.Severity(reporting.Severity.HIGH),
reporting.Groups([reporting.Groups.REPOSITORY]),
]
reporting.create_report(report_parts)


def report_any_modifications():
modifications = list(api.consume(CustomModifications))
_create_report([m for m in modifications if m.type == 'custom'])
_create_report([m for m in modifications if m.type == 'modified'])
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from leapp.libraries.actor import checkcustommodifications
from leapp.models import CustomModifications, Report


def test_report_any_modifications(current_actor_context):
discovered_msgs = [CustomModifications(filename='some/changed/leapp/actor/file',
type='modified',
actor_name='an_actor'),
CustomModifications(filename='some/new/actor/in/leapp/dir',
type='custom',
actor_name='a_new_actor'),
CustomModifications(filename='some/new/file/unrelated/to/any/actor', type='custom',
actor_name='')]
for msg in discovered_msgs:
current_actor_context.feed(msg)
current_actor_context.run()
reports = current_actor_context.consume(Report)
custom_files_report = next((r.report for r in reports if 'Custom' in r.report['title']), None)
modified_files_report = next((r.report for r in reports if 'Modified' in r.report['title']), None)
assert (custom_files_report['title'] ==
'Custom files were discovered on your system in leapp directories')
assert 'some/new/actor/in/leapp/dir (a_new_actor Actor)' in custom_files_report['summary']
assert 'some/new/file/unrelated/to/any/actor' in custom_files_report['summary']
assert (modified_files_report['title'] ==
'Modified files were discovered on your system in leapp directories')
assert 'some/changed/leapp/actor/file (an_actor Actor)' in modified_files_report['summary']

0 comments on commit 1dc9922

Please sign in to comment.