Skip to content

Commit

Permalink
[WIP] [DEBUG] POC of custom modifications tracking
Browse files Browse the repository at this point in the history
Please do NOT review until marked as ready.
All custom modifications ideas will be put there.
  • Loading branch information
fernflower committed Nov 16, 2023
1 parent 64ec2ec commit ceb0a78
Show file tree
Hide file tree
Showing 3 changed files with 92 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.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)
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])
11 changes: 11 additions & 0 deletions repos/system_upgrade/common/models/custommodifications.py
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'])

0 comments on commit ceb0a78

Please sign in to comment.