forked from AlmaLinux/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 6
CLOS-3344: Add a check for leftover cldeploy package repository files #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
repos/system_upgrade/cloudlinux/actors/checkcldeployrepofile/actor.py
This file contains hidden or 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,33 @@ | ||
| from leapp.actors import Actor | ||
| from leapp.libraries.common.cllaunch import run_on_cloudlinux | ||
| from leapp.models import Report, RepositoriesFacts | ||
| from leapp.tags import ChecksPhaseTag, IPUWorkflowTag | ||
| from leapp.libraries.actor import checkcldeployrepofile | ||
|
|
||
|
|
||
| class CheckCldeployRepofile(Actor): | ||
| """ | ||
| Check for leftover repository configuration files from a cldeploy conversion. | ||
| These repofiles, also known as "base repos" in the cldeploy context, are | ||
| used to bootstrap the CL systems during the conversion process. | ||
| Normally, they are removed by the cldeploy tool itself, but in some | ||
| cases, they may be left behind. | ||
| If that happens, they can cause problems with the upgrade process, | ||
| since neither leapp nor the upgrade process itself expect them to be present. | ||
| This actor checks for the presence of these files and warns the user to remove them if found. | ||
| The files are located in the /etc/yum.repos.d directory and have names based on | ||
| the URL of the repository they point to. For example: | ||
| repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_.repo | ||
| """ | ||
|
|
||
| name = "check_cldeploy_repofile" | ||
| consumes = (RepositoriesFacts,) | ||
| produces = (Report,) | ||
| tags = (ChecksPhaseTag, IPUWorkflowTag) | ||
|
|
||
| @run_on_cloudlinux | ||
| def process(self): | ||
| checkcldeployrepofile.process() |
58 changes: 58 additions & 0 deletions
58
...system_upgrade/cloudlinux/actors/checkcldeployrepofile/libraries/checkcldeployrepofile.py
This file contains hidden or 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,58 @@ | ||
| import os | ||
|
|
||
| from leapp import reporting | ||
| from leapp.libraries.stdlib import api | ||
| from leapp.models import RepositoriesFacts | ||
|
|
||
|
|
||
| def get_cldeploy_repo_files(repo_file_paths): | ||
| """ | ||
| Get the list of cldeploy repository files. | ||
|
|
||
| Keep in mind that the incoming repository file paths are absolute paths to the repository files. | ||
| """ | ||
| # Base path for repo files | ||
| repo_base_path = "/etc/yum.repos.d/" | ||
| # Name prefix for cldeploy repo files | ||
| repo_prefix = "repo.cloudlinux.com_" | ||
| expected_startswith = repo_base_path + repo_prefix | ||
|
|
||
| return [repo_file for repo_file in repo_file_paths if repo_file.startswith(expected_startswith)] | ||
|
|
||
|
|
||
| def create_report(cldeploy_repo_files): | ||
| title = "Leftover cldeploy repository files found" | ||
| summary = ( | ||
| "The following leftover cldeploy repository files were found on the system. " | ||
| "If not removed, they will cause issues with the upgrade process." | ||
| ) | ||
|
|
||
| for repo_file in cldeploy_repo_files: | ||
| summary += "\n- {}".format(repo_file) | ||
|
|
||
| remediation = "Remove the leftover cldeploy repository files before running Leapp again." | ||
| reporting.create_report( | ||
| [ | ||
| reporting.Title(title), | ||
| reporting.Summary(summary), | ||
| reporting.Severity(reporting.Severity.HIGH), | ||
| reporting.Groups([reporting.Groups.OS_FACTS, reporting.Groups.REPOSITORY]), | ||
| reporting.Groups([reporting.Groups.INHIBITOR]), | ||
| reporting.Remediation(hint=remediation), | ||
| reporting.RelatedResource('directory', '/etc/yum.repos.d') | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| def process(): | ||
| repository_file_paths = [] | ||
| # RepositoriesFacts.repositories is a list of RepositoryFile objects | ||
| for repos_facts in api.consume(RepositoriesFacts): | ||
| # The file field of RepositoryFile objects is an absolute path to the repository file | ||
| for repo_file in repos_facts.repositories: | ||
| repository_file_paths.append(repo_file.file) | ||
|
|
||
| cldeploy_repo_files = get_cldeploy_repo_files(repository_file_paths) | ||
|
|
||
| if cldeploy_repo_files: | ||
| create_report(cldeploy_repo_files) | ||
32 changes: 32 additions & 0 deletions
32
..._upgrade/cloudlinux/actors/checkcldeployrepofile/tests/unit_test_checkcldeployrepofile.py
This file contains hidden or 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,32 @@ | ||
| import pytest | ||
|
|
||
| # from leapp import reporting | ||
| from leapp.libraries.actor import checkcldeployrepofile | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "repo_file_paths,expected_res", | ||
| ( | ||
| ( | ||
| [ | ||
| "/etc/yum.repos.d/almalinux-appstream.repo", | ||
| "/etc/yum.repos.d/cloudlinux.repo", | ||
| "/etc/yum.repos.d/cloudlinux-rollout.repo", | ||
| "/etc/yum.repos.d/repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_", | ||
| ], | ||
| [ | ||
| "/etc/yum.repos.d/repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_", | ||
| ], | ||
| ), | ||
| ( | ||
| [ | ||
| "/etc/yum.repos.d/almalinux-appstream.repo", | ||
| "/etc/yum.repos.d/cloudlinux.repo", | ||
| "/etc/yum.repos.d/cloudlinux-rollout.repo", | ||
| ], | ||
| [], | ||
| ), | ||
| ), | ||
| ) | ||
| def test_problem_packages_installed(repo_file_paths, expected_res): | ||
| assert expected_res == checkcldeployrepofile.get_cldeploy_repo_files(repo_file_paths) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.