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 1dbd49f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from leapp.actors import Actor
from leapp.libraries.actor.trackcustommodifications import check_for_modifications
from leapp.models import CustomModifications
from leapp.reporting import Report
from leapp.tags import ChecksPhaseTag, 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, Report)
tags = (IPUWorkflowTag, ChecksPhaseTag)

def process(self):
check_for_modifications()
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

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{}toel{}'.format(get_source_major_version(), get_target_major_version())]
DIRS_TO_SCAN = ['/usr/share/leapp-repository']


def check_for_modifications(dirs=DIRS_TO_SCAN, rpms=RPMS_TO_CHECK):
"""
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.
"""
source_of_truth = []
for rpm in RPMS_TO_CHECK:
get_rpm_files_command = ['rpm', '-ql', rpm]
try:
rpm_files = run(get_rpm_files_command)
source_of_truth.append(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:
except CalledProcessError:
api.current_logger().warning(
'Could not get list of leapp files in %s'.format(directory)
)
raise StopActorExecution()

10 changes: 10 additions & 0 deletions repos/system_upgrade/common/models/custommodifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from leapp.models import fields, Model
from leapp.topics import SystemFactsTopic


class CustomModifications(Model):
"""Model to store any custom\changed files that are discovered in leapp directories"""
topic = SystemFactsTopic

filename = fields.String()
actor_name = fields.String()

0 comments on commit 1dbd49f

Please sign in to comment.