-
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.
[WIP] [DEBUG] POC of custom modifications tracking
Please do NOT review until marked as ready. All custom modifications ideas will be put there.
- Loading branch information
1 parent
64ec2ec
commit ceb0a78
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/common/actors/trackcustommodifications/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.trackcustommodifications import check_for_modifications | ||
from leapp.models import CustomModifications | ||
from leapp.tags import FactsPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class TrackCustomModificationsActor(Actor): | ||
""" | ||
Collects information about files in leapp directories that have been modified or newly added. | ||
""" | ||
|
||
name = 'track_custom_modifications_actor' | ||
produces = (CustomModifications,) | ||
tags = (IPUWorkflowTag, FactsPhaseTag) | ||
|
||
def process(self): | ||
changed, custom = check_for_modifications() | ||
for msg in changed + custom: | ||
self.produce(msg) |
62 changes: 62 additions & 0 deletions
62
...stem_upgrade/common/actors/trackcustommodifications/libraries/trackcustommodifications.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,62 @@ | ||
import os | ||
|
||
from leapp.exceptions import StopActorExecution | ||
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version | ||
from leapp.libraries.stdlib import api, CalledProcessError, run | ||
from leapp.models import CustomModifications | ||
|
||
|
||
RPMS_TO_CHECK = ['leapp-upgrade-el{source}toel{target}'] | ||
DIRS_TO_SCAN = ['/usr/share/leapp-repository'] | ||
|
||
|
||
def _get_rpms_to_check(): | ||
return [rpm.format(source=get_source_major_version(), target=get_target_major_version()) for rpm in RPMS_TO_CHECK] | ||
|
||
|
||
def check_for_modifications(dirs=DIRS_TO_SCAN): | ||
""" | ||
This will return a tuple (changes, custom) is case any untypical files or changes to shipped leapp files are | ||
discovered. | ||
(None, None) means that no modifications have been found. | ||
""" | ||
rpms = _get_rpms_to_check() | ||
source_of_truth = [] | ||
for rpm in rpms: | ||
get_rpm_files_command = ['rpm', '-ql', rpm] | ||
try: | ||
rpm_files = run(get_rpm_files_command) | ||
source_of_truth.extend(rpm_files['stdout'].strip().split()) | ||
except CalledProcessError: | ||
api.current_logger().warning( | ||
'Could not get list of installed files from rpm %s'.format(rpm) | ||
) | ||
raise StopActorExecution() | ||
leapp_files = [] | ||
for directory in dirs: | ||
get_files_command = ['find', directory, '-type', 'f'] | ||
try: | ||
files = run(get_files_command) | ||
leapp_files.extend(files['stdout'].strip().split()) | ||
except CalledProcessError: | ||
api.current_logger().warning( | ||
'Could not get list of leapp files in %s'.format(directory) | ||
) | ||
raise StopActorExecution() | ||
custom_files = set(leapp_files) - set(source_of_truth) | ||
# Now let's check for modifications | ||
modified_files = [] | ||
for rpm in rpms: | ||
try: | ||
modified = run(['rpm', '-V', rpm]) | ||
modified_files.extend(modified['stdout'].strip().split()) | ||
except CalledProcessError: | ||
api.current_logger().warning( | ||
'Could not check authenticity of the files from %s'.format(rpm) | ||
) | ||
raise StopActorExecution() | ||
# NOTE(ivasilev) Now the fun part TBD - the mapping between actor file / library and actor's | ||
# name | ||
# XXX Leaving blank atm as it's tbd | ||
return ([CustomModifications(actor_name='', filename=f, type='modified') for f in modified_files], | ||
[CustomModifications(actor_name='', filename=f, type='custom') for f in custom_files]) |
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,11 @@ | ||
from leapp.models import fields, Model | ||
from leapp.topics import SystemFactsTopic | ||
|
||
|
||
class CustomModifications(Model): | ||
"""Model to store any custom or modified files that are discovered in leapp directories""" | ||
topic = SystemFactsTopic | ||
|
||
filename = fields.String() | ||
actor_name = fields.String() | ||
type = fields.StringEnum(choices=['custom', 'modified']) |