Skip to content

Commit

Permalink
Add configuration change tracking
Browse files Browse the repository at this point in the history
If any change to leapp or leapp-repository configuration files
happens this will be reported separately.
  • Loading branch information
fernflower committed Jan 11, 2024
1 parent 7071262 commit c78774d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ def report_any_modifications():
modifications = list(api.consume(CustomModifications))
_create_report(modifications, report_type='custom')
_create_report(modifications, report_type='modified', component='repository')
_create_report(modifications, report_type='modified', component='configuration')
_create_report(modifications, report_type='modified', component='framework',
hint='Reinstall leapp to get rid of these changes.')
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,30 @@ def check_for_modifications(component):
custom_files = sorted(set(leapp_files) - set(source_of_truth))
# Now let's check for modifications
modified_files = []
modified_configs = []
for rpm in rpms:
res = _run_command(
['rpm', '-V', '--nomtime', rpm], 'Could not check authenticity of the files from {}'.format(rpm),
# NOTE(ivasilev) check is False here as in case of any changes found exit code will be 1
checked=False)
if res:
api.current_logger().warning('Modifications to leapp files detected!\n%s', res)
modified_files.extend([tuple(x.split()) for x in res])
for modification_str in res:
modification = tuple(modification_str.split())
if len(modification) == 3 and modification[1] == 'c':
# Dealing with a configuration that will be displayed as ('S.5......', 'c', '/file/path')
modified_configs.append(modification)
else:
# Modification of any other rpm file detected
modified_files.append(modification)
return ([_modification_model(filename=f[1], component=component, rpm_checks_str=f[0], change_type='modified')
# Let's filter out pyc files not to clutter the output as pyc will be present even in case of
# a plain open & save-not-changed that we agreed not to react upon.
for f in modified_files if not f[1].endswith('.pyc')] +
[_modification_model(filename=f, component=component, change_type='custom')
for f in custom_files])
for f in custom_files] +
[_modification_model(filename=f[2], component='configuration', rpm_checks_str=f[0], change_type='modified')
for f in modified_configs])


def scan():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
VERIFIED_FILES = """
.......T. repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py
S.5....T. repos/system_upgrade/el8toel9/actors/anotheractor/actor.py
S.5....T. c etc/leapp/files/pes-events.json
"""


Expand Down Expand Up @@ -76,8 +77,13 @@ def test_check_for_modifications(monkeypatch):
modifications = scancustommodifications.check_for_modifications('repository')
modified = [m for m in modifications if m.type == 'modified']
custom = [m for m in modifications if m.type == 'custom']
configurations = [m for m in modifications if m.component == 'configuration']
assert len(modified) == 3
assert modified[0].filename == 'repos/system_upgrade/el8toel9/actors/xorgdrvfact/libraries/xorgdriverlib.py'
assert modified[0].rpm_checks_str == '.......T.'
assert len(custom) == 3
assert custom[0].filename == '/some/unrelated/to/leapp/file'
assert custom[0].rpm_checks_str == ''
assert len(configurations) == 1
assert configurations[0].filename == 'etc/leapp/files/pes-events.json'
assert configurations[0].rpm_checks_str == 'S.5....T.'

0 comments on commit c78774d

Please sign in to comment.