-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
ad42184
commit 1dc9922
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/common/actors/checkcustommodifications/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
31 changes: 31 additions & 0 deletions
31
...stem_upgrade/common/actors/checkcustommodifications/libraries/checkcustommodifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
26 changes: 26 additions & 0 deletions
26
...tem_upgrade/common/actors/checkcustommodifications/tests/test_checkcustommodifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |