Skip to content

Commit 63f6979

Browse files
committed
CLOS-3205: Rework the clearpackageconflicts actor with set definitoon to work for el8to9 upgrades
Seems like the InstalledRPM model was modified at some point, and the previous construction could not be utilized. The logic was changed to process only package names (which is essentially already how the data was used) into the set, which is then used for package lookup. This sidesteps the problem with the InstalledRPM type not being hashable.
1 parent 47d9065 commit 63f6979

File tree

3 files changed

+112
-85
lines changed

3 files changed

+112
-85
lines changed
Lines changed: 11 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,28 @@
1-
import os
2-
import errno
3-
import shutil
4-
51
from leapp.actors import Actor
62
from leapp.models import InstalledRPM
73
from leapp.tags import DownloadPhaseTag, IPUWorkflowTag
84
from leapp.libraries.common.cllaunch import run_on_cloudlinux
5+
from leapp.libraries.actor import clearpackageconflicts
96

107

118
class ClearPackageConflicts(Actor):
129
"""
13-
Remove several python package files manually to resolve conflicts between versions of packages to be upgraded.
10+
Remove several Python package files manually to resolve conflicts
11+
between versions of packages to be upgraded.
12+
13+
When the corresponding packages are detected,
14+
the conflicting files are removed to allow for an upgrade to the new package versions.
15+
16+
While most packages are handled automatically by the package manager,
17+
some specific packages require direct intervention to resolve conflicts
18+
between their own versions on different OS releases.
1419
"""
1520

1621
name = "clear_package_conflicts"
1722
consumes = (InstalledRPM,)
1823
produces = ()
1924
tags = (DownloadPhaseTag.Before, IPUWorkflowTag)
20-
rpm_lookup = None
21-
22-
def has_package(self, name):
23-
"""
24-
Check whether the package is installed.
25-
Looks only for the package name, nothing else.
26-
"""
27-
if self.rpm_lookup:
28-
return name in self.rpm_lookup
29-
30-
def problem_packages_installed(self, problem_packages):
31-
"""
32-
Check whether any of the problem packages are present in the system.
33-
"""
34-
for pkg in problem_packages:
35-
if self.has_package(pkg):
36-
self.log.debug("Conflicting package {} detected".format(pkg))
37-
return True
38-
return False
39-
40-
def clear_problem_files(self, problem_files, problem_dirs):
41-
"""
42-
Go over the list of problem files and directories and remove them if they exist.
43-
They'll be replaced by the new packages.
44-
"""
45-
for p_dir in problem_dirs:
46-
try:
47-
if os.path.isdir(p_dir):
48-
shutil.rmtree(p_dir)
49-
self.log.debug("Conflicting directory {} removed".format(p_dir))
50-
except OSError as e:
51-
if e.errno != errno.ENOENT:
52-
raise
53-
54-
for p_file in problem_files:
55-
try:
56-
if os.path.isfile(p_file):
57-
os.remove(p_file)
58-
self.log.debug("Conflicting file {} removed".format(p_file))
59-
except OSError as e:
60-
if e.errno != errno.ENOENT:
61-
raise
62-
63-
def alt_python37_handle(self):
64-
"""
65-
These alt-python37 packages are conflicting with their own builds for EL8.
66-
"""
67-
problem_packages = [
68-
"alt-python37-six",
69-
"alt-python37-pytz",
70-
]
71-
problem_files = []
72-
problem_dirs = [
73-
"/opt/alt/python37/lib/python3.7/site-packages/six-1.15.0-py3.7.egg-info",
74-
"/opt/alt/python37/lib/python3.7/site-packages/pytz-2017.2-py3.7.egg-info",
75-
]
76-
77-
if self.problem_packages_installed(problem_packages):
78-
self.clear_problem_files(problem_files, problem_dirs)
79-
80-
def lua_cjson_handle(self):
81-
"""
82-
lua-cjson package is conflicting with the incoming lua-cjson package for EL8.
83-
"""
84-
problem_packages = [
85-
"lua-cjson"
86-
]
87-
problem_files = [
88-
"/usr/lib64/lua/5.1/cjson.so",
89-
"/usr/share/lua/5.1/cjson/tests/bench.lua",
90-
"/usr/share/lua/5.1/cjson/tests/genutf8.pl",
91-
"/usr/share/lua/5.1/cjson/tests/test.lua",
92-
]
93-
problem_dirs = []
94-
95-
if self.problem_packages_installed(problem_packages):
96-
self.clear_problem_files(problem_files, problem_dirs)
9725

9826
@run_on_cloudlinux
9927
def process(self):
100-
# todo: (CLOS-3205) investigate why set is needed here
101-
self.rpm_lookup = [rpm for rpm in self.consume(InstalledRPM)]
102-
self.alt_python37_handle()
28+
clearpackageconflicts.process()
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
import errno
3+
from re import L
4+
import shutil
5+
6+
from leapp.libraries.stdlib import api
7+
from leapp.models import InstalledRPM
8+
9+
10+
def problem_packages_installed(problem_packages, lookup):
11+
"""
12+
Check whether any of the problem packages are present in the system.
13+
"""
14+
for pkg in problem_packages:
15+
if pkg in lookup:
16+
api.current_logger().debug("Conflicting package {} detected".format(pkg))
17+
return True
18+
return False
19+
20+
21+
def clear_problem_files(problem_files, problem_dirs):
22+
"""
23+
Go over the list of problem files and directories and remove them if they exist.
24+
They'll be replaced by the new packages.
25+
"""
26+
for p_dir in problem_dirs:
27+
try:
28+
if os.path.isdir(p_dir):
29+
shutil.rmtree(p_dir)
30+
api.current_logger().debug("Conflicting directory {} removed".format(p_dir))
31+
except OSError as e:
32+
if e.errno != errno.ENOENT:
33+
raise
34+
35+
for p_file in problem_files:
36+
try:
37+
if os.path.isfile(p_file):
38+
os.remove(p_file)
39+
api.current_logger().debug("Conflicting file {} removed".format(p_file))
40+
except OSError as e:
41+
if e.errno != errno.ENOENT:
42+
raise
43+
44+
45+
def alt_python37_handle(package_lookup):
46+
"""
47+
These alt-python37 packages are conflicting with their own builds for EL8.
48+
"""
49+
problem_packages = [
50+
"alt-python37-six",
51+
"alt-python37-pytz",
52+
]
53+
problem_files = []
54+
problem_dirs = [
55+
"/opt/alt/python37/lib/python3.7/site-packages/six-1.15.0-py3.7.egg-info",
56+
"/opt/alt/python37/lib/python3.7/site-packages/pytz-2017.2-py3.7.egg-info",
57+
]
58+
59+
if problem_packages_installed(problem_packages, package_lookup):
60+
clear_problem_files(problem_files, problem_dirs)
61+
62+
63+
def lua_cjson_handle(package_lookup):
64+
"""
65+
lua-cjson package is conflicting with the incoming lua-cjson package for EL8.
66+
"""
67+
problem_packages = [
68+
"lua-cjson"
69+
]
70+
problem_files = [
71+
"/usr/lib64/lua/5.1/cjson.so",
72+
"/usr/share/lua/5.1/cjson/tests/bench.lua",
73+
"/usr/share/lua/5.1/cjson/tests/genutf8.pl",
74+
"/usr/share/lua/5.1/cjson/tests/test.lua",
75+
]
76+
problem_dirs = []
77+
78+
if problem_packages_installed(problem_packages, package_lookup):
79+
clear_problem_files(problem_files, problem_dirs)
80+
81+
82+
def process():
83+
rpm_lookup = {rpm.name for rpm in api.consume(InstalledRPM)}
84+
alt_python37_handle(rpm_lookup)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
# from leapp import reporting
4+
from leapp.libraries.actor import clearpackageconflicts
5+
6+
7+
@pytest.mark.parametrize(
8+
"problem_pkgs,lookup,expected_res",
9+
(
10+
(["cagefs"], {"cagefs", "dnf"}, True),
11+
(["lve-utils"], {"lve-utils", "dnf"}, True),
12+
(["nonexistent-pkg"], {"cagefs", "dnf"}, False),
13+
(["cagefs"], {"lve-utils", "dnf"}, False),
14+
),
15+
)
16+
def test_problem_packages_installed(problem_pkgs, lookup, expected_res):
17+
assert expected_res == clearpackageconflicts.problem_packages_installed(problem_pkgs, lookup)

0 commit comments

Comments
 (0)