Skip to content

Commit deb73c0

Browse files
authored
Merge pull request #36 from prilr/cldeploy-repos
CLOS-3344: Add a check for leftover cldeploy package repository files
2 parents 0923e68 + 130df25 commit deb73c0

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
3+
from leapp.models import Report, RepositoriesFacts
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
from leapp.libraries.actor import checkcldeployrepofile
6+
7+
8+
class CheckCldeployRepofile(Actor):
9+
"""
10+
Check for leftover repository configuration files from a cldeploy conversion.
11+
12+
These repofiles, also known as "base repos" in the cldeploy context, are
13+
used to bootstrap the CL systems during the conversion process.
14+
Normally, they are removed by the cldeploy tool itself, but in some
15+
cases, they may be left behind.
16+
If that happens, they can cause problems with the upgrade process,
17+
since neither leapp nor the upgrade process itself expect them to be present.
18+
19+
This actor checks for the presence of these files and warns the user to remove them if found.
20+
21+
The files are located in the /etc/yum.repos.d directory and have names based on
22+
the URL of the repository they point to. For example:
23+
repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_.repo
24+
"""
25+
26+
name = "check_cldeploy_repofile"
27+
consumes = (RepositoriesFacts,)
28+
produces = (Report,)
29+
tags = (ChecksPhaseTag, IPUWorkflowTag)
30+
31+
@run_on_cloudlinux
32+
def process(self):
33+
checkcldeployrepofile.process()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
3+
from leapp import reporting
4+
from leapp.libraries.stdlib import api
5+
from leapp.models import RepositoriesFacts
6+
7+
8+
def get_cldeploy_repo_files(repo_file_paths):
9+
"""
10+
Get the list of cldeploy repository files.
11+
12+
Keep in mind that the incoming repository file paths are absolute paths to the repository files.
13+
"""
14+
# Base path for repo files
15+
repo_base_path = "/etc/yum.repos.d/"
16+
# Name prefix for cldeploy repo files
17+
repo_prefix = "repo.cloudlinux.com_"
18+
expected_startswith = repo_base_path + repo_prefix
19+
20+
return [repo_file for repo_file in repo_file_paths if repo_file.startswith(expected_startswith)]
21+
22+
23+
def create_report(cldeploy_repo_files):
24+
title = "Leftover cldeploy repository files found"
25+
summary = (
26+
"The following leftover cldeploy repository files were found on the system. "
27+
"If not removed, they will cause issues with the upgrade process."
28+
)
29+
30+
for repo_file in cldeploy_repo_files:
31+
summary += "\n- {}".format(repo_file)
32+
33+
remediation = "Remove the leftover cldeploy repository files before running Leapp again."
34+
reporting.create_report(
35+
[
36+
reporting.Title(title),
37+
reporting.Summary(summary),
38+
reporting.Severity(reporting.Severity.HIGH),
39+
reporting.Groups([reporting.Groups.OS_FACTS, reporting.Groups.REPOSITORY]),
40+
reporting.Groups([reporting.Groups.INHIBITOR]),
41+
reporting.Remediation(hint=remediation),
42+
reporting.RelatedResource('directory', '/etc/yum.repos.d')
43+
]
44+
)
45+
46+
47+
def process():
48+
repository_file_paths = []
49+
# RepositoriesFacts.repositories is a list of RepositoryFile objects
50+
for repos_facts in api.consume(RepositoriesFacts):
51+
# The file field of RepositoryFile objects is an absolute path to the repository file
52+
for repo_file in repos_facts.repositories:
53+
repository_file_paths.append(repo_file.file)
54+
55+
cldeploy_repo_files = get_cldeploy_repo_files(repository_file_paths)
56+
57+
if cldeploy_repo_files:
58+
create_report(cldeploy_repo_files)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
# from leapp import reporting
4+
from leapp.libraries.actor import checkcldeployrepofile
5+
6+
7+
@pytest.mark.parametrize(
8+
"repo_file_paths,expected_res",
9+
(
10+
(
11+
[
12+
"/etc/yum.repos.d/almalinux-appstream.repo",
13+
"/etc/yum.repos.d/cloudlinux.repo",
14+
"/etc/yum.repos.d/cloudlinux-rollout.repo",
15+
"/etc/yum.repos.d/repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_",
16+
],
17+
[
18+
"/etc/yum.repos.d/repo.cloudlinux.com_cloudlinux_8_BaseOS_x86_64_os_",
19+
],
20+
),
21+
(
22+
[
23+
"/etc/yum.repos.d/almalinux-appstream.repo",
24+
"/etc/yum.repos.d/cloudlinux.repo",
25+
"/etc/yum.repos.d/cloudlinux-rollout.repo",
26+
],
27+
[],
28+
),
29+
),
30+
)
31+
def test_problem_packages_installed(repo_file_paths, expected_res):
32+
assert expected_res == checkcldeployrepofile.get_cldeploy_repo_files(repo_file_paths)

0 commit comments

Comments
 (0)