Skip to content

Commit 4d6305e

Browse files
committed
Add possibility to use patterns for the removal list
1 parent 000eccf commit 4d6305e

File tree

2 files changed

+219
-210
lines changed

2 files changed

+219
-210
lines changed
Lines changed: 39 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
import fnmatch
2+
3+
from leapp.exceptions import StopActorExecutionError
14
from leapp.libraries.common.config import get_source_distro_id, get_target_distro_id
25
from leapp.libraries.common.config.version import get_target_major_version
3-
from leapp.libraries.common.rpms import has_package
46
from leapp.libraries.stdlib import api
57
from leapp.models import DistributionSignedRPM, RpmTransactionTasks
68

9+
# Config for swapping distribution-specific RPMs
10+
# The keys can be in 2 "formats":
11+
# (<source_distro_id>, <target_distro_id>)
12+
# (<source_distro_id>, <target_distro_id>, <target_major_version as int>)
13+
# The "swap" dict maps packages on the source distro to their replacements on
14+
# the target distro
15+
# The "remove" set lists packages or glob pattern for matching packages from
16+
# the source distro to remove without any replacement.
717
_CONFIG = {
818
("centos", "rhel"): {
919
"swap": {
@@ -18,62 +28,7 @@
1828
"centos-gpg-keys",
1929
"centos-stream-repos",
2030
# various release packages, typically contain repofiles
21-
"centos-release-automotive",
22-
"centos-release-automotive-experimental",
23-
"centos-release-autosd",
24-
"centos-release-ceph-pacific",
25-
"centos-release-ceph-quincy",
26-
"centos-release-ceph-reef",
27-
"centos-release-ceph-squid",
28-
"centos-release-ceph-tentacle",
29-
"centos-release-cloud",
30-
"centos-release-gluster10",
31-
"centos-release-gluster11",
32-
"centos-release-gluster9",
33-
"centos-release-hyperscale",
34-
"centos-release-hyperscale-experimental",
35-
"centos-release-hyperscale-experimental-testing",
36-
"centos-release-hyperscale-spin",
37-
"centos-release-hyperscale-spin-testing",
38-
"centos-release-hyperscale-testing",
39-
"centos-release-isa-override",
40-
"centos-release-kmods",
41-
"centos-release-kmods-kernel",
42-
"centos-release-kmods-kernel-6",
43-
"centos-release-messaging",
44-
"centos-release-nfs-ganesha4",
45-
"centos-release-nfs-ganesha5",
46-
"centos-release-nfs-ganesha6",
47-
"centos-release-nfs-ganesha7",
48-
"centos-release-nfs-ganesha8",
49-
"centos-release-nfv-common",
50-
"centos-release-nfv-openvswitch",
51-
"centos-release-okd-4",
52-
"centos-release-openstack-antelope",
53-
"centos-release-openstack-bobcat",
54-
"centos-release-openstack-caracal",
55-
"centos-release-openstack-dalmatian",
56-
"centos-release-openstack-epoxy",
57-
"centos-release-openstack-yoga",
58-
"centos-release-openstack-zed",
59-
"centos-release-openstackclient-xena",
60-
"centos-release-opstools",
61-
"centos-release-ovirt45",
62-
"centos-release-ovirt45-testing",
63-
"centos-release-proposed_updates",
64-
"centos-release-rabbitmq-38",
65-
"centos-release-samba414",
66-
"centos-release-samba415",
67-
"centos-release-samba416",
68-
"centos-release-samba417",
69-
"centos-release-samba418",
70-
"centos-release-samba419",
71-
"centos-release-samba420",
72-
"centos-release-samba421",
73-
"centos-release-samba422",
74-
"centos-release-samba423",
75-
"centos-release-storage-common",
76-
"centos-release-virt-common",
31+
"centos-release-*",
7732
# present on Centos (not Stream) 8, let's include them if they are potentially leftover
7833
"centos-linux-release",
7934
"centos-linux-repos",
@@ -82,60 +37,19 @@
8237
},
8338
("almalinux", "rhel"): {
8439
"swap": {
85-
"almalinux-logos": "redhat-logos",
86-
"almalinux-logos-httpd": "redhat-logos-httpd",
87-
"almalinux-logos-ipa": "redhat-logos-ipa",
88-
"almalinux-indexhtml": "redhat-indexhtml",
89-
"almalinux-backgrouns": "redhat-backgrounds",
90-
"almalinux-release": "redhat-release",
40+
"almalinux-logos": "redhat-logos",
41+
"almalinux-logos-httpd": "redhat-logos-httpd",
42+
"almalinux-logos-ipa": "redhat-logos-ipa",
43+
"almalinux-indexhtml": "redhat-indexhtml",
44+
"almalinux-backgrouns": "redhat-backgrounds",
45+
"almalinux-release": "redhat-release",
9146
},
9247
"remove": {
93-
"almalinux-release-devel"
94-
"almalinux-release-nvidia-driver"
95-
"almalinux-release-opennebula-addons"
96-
"almalinux-release-synergy"
97-
"almalinux-release-testing"
98-
9948
"almalinux-repos",
10049
"almalinux-gpg-keys",
10150

102-
"centos-release-cloud",
103-
"centos-release-nfv-openvswitch",
104-
"centos-release-storage-common",
105-
"centos-release-virt-common",
106-
"centos-release-ceph-pacific",
107-
"centos-release-ceph-quincy",
108-
"centos-release-ceph-reef",
109-
"centos-release-gluster10",
110-
"centos-release-gluster11",
111-
"centos-release-gluster9",
112-
"centos-release-messaging",
113-
"centos-release-nfs-ganesha4",
114-
"centos-release-nfs-ganesha5",
115-
"centos-release-nfv-common",
116-
"centos-release-okd-4.13",
117-
"centos-release-okd-4.14",
118-
"centos-release-okd-4.15",
119-
"centos-release-okd-4.16",
120-
"centos-release-openstack-antelope",
121-
"centos-release-openstack-bobcat",
122-
"centos-release-openstack-caracal",
123-
"centos-release-openstack-dalmatian",
124-
"centos-release-openstack-yoga",
125-
"centos-release-openstack-zed",
126-
"centos-release-openstackclient-xena",
127-
"centos-release-opstools",
128-
"centos-release-ovirt45",
129-
"centos-release-ovirt45-testing",
130-
"centos-release-rabbitmq-38",
131-
"centos-release-samba414",
132-
"centos-release-samba415",
133-
"centos-release-samba416",
134-
"centos-release-samba417",
135-
"centos-release-samba418",
136-
"centos-release-samba419",
137-
"centos-release-samba420",
138-
51+
"almalinux-release-*",
52+
"centos-release-*",
13953
"elrepo-release",
14054
"epel-release",
14155
},
@@ -153,25 +67,30 @@ def _get_config(source_distro, target_distro, target_major):
15367
return _CONFIG.get(key)
15468

15569

156-
def _make_transaction_tasks(config):
157-
to_install = []
158-
to_remove = []
70+
def _glob_match_rpms(rpms, pattern):
71+
return [rpm for rpm in rpms if fnmatch.fnmatch(rpm, pattern)]
72+
73+
74+
def _make_transaction_tasks(config, rpms):
75+
to_install = set()
76+
to_remove = set()
15977
for source_pkg, target_pkg in config.get("swap", {}).items():
160-
if has_package(DistributionSignedRPM, source_pkg):
161-
to_remove.append(source_pkg)
162-
to_install.append(target_pkg)
78+
if source_pkg in rpms:
79+
to_remove.add(source_pkg)
80+
to_install.add(target_pkg)
16381

16482
for pkg in config.get("remove", {}):
165-
# this has_package call isn't strictly necessary as the actor
166-
# processing RpmTransactionTasks checks if the package is present, but
167-
# keeping it for consistency with the above
168-
if has_package(DistributionSignedRPM, pkg):
169-
to_remove.append(pkg)
83+
matches = _glob_match_rpms(rpms, pkg)
84+
to_remove.update(matches)
17085

171-
return RpmTransactionTasks(to_install=to_install, to_remove=to_remove)
86+
return RpmTransactionTasks(to_install=list(to_install), to_remove=list(to_remove))
17287

17388

17489
def process():
90+
rpms_msg = next(api.consume(DistributionSignedRPM), None)
91+
if not rpms_msg:
92+
raise StopActorExecutionError("Did not receive DistributionSignedRPM message")
93+
17594
source_distro = get_source_distro_id()
17695
target_distro = get_target_distro_id()
17796

@@ -187,5 +106,6 @@ def process():
187106
)
188107
return
189108

190-
task = _make_transaction_tasks(config)
109+
rpms = {rpm.name for rpm in rpms_msg.items}
110+
task = _make_transaction_tasks(config, rpms)
191111
api.produce(task)

0 commit comments

Comments
 (0)