Skip to content

Instantly share code, notes, and snippets.

@r0x0d
Last active January 5, 2024 13:46
Show Gist options
  • Save r0x0d/5f17f442758864e8bda55da2c1d833b6 to your computer and use it in GitHub Desktop.
Save r0x0d/5f17f442758864e8bda55da2c1d833b6 to your computer and use it in GitHub Desktop.
diff --git a/convert2rhel/data/7/x86_64/configs/centos-7-x86_64.cfg b/convert2rhel/data/7/x86_64/configs/centos-7-x86_64.cfg
index 0153c9cd..f0438b10 100644
--- a/convert2rhel/data/7/x86_64/configs/centos-7-x86_64.cfg
+++ b/convert2rhel/data/7/x86_64/configs/centos-7-x86_64.cfg
@@ -23,6 +23,12 @@ excluded_pkgs =
yum-rhn-plugin
gnome-documents-libs
+# Mapping of packages that need to be swapped during the transaction
+# The format of the mapping is as follow: old_package | new_pakcage
+swap_pkgs =
+ centos-logos | redhat-logos
+ centos-indexhtml | redhat-indexhtml
+
# List of packages that either contain repofiles or affect variables in the repofiles (e.g. $releasever).
# Delimited by any whitespace(s).
repofile_pkgs =
diff --git a/convert2rhel/pkgmanager/handlers/yum/__init__.py b/convert2rhel/pkgmanager/handlers/yum/__init__.py
index 61d8e831..f1898135 100644
--- a/convert2rhel/pkgmanager/handlers/yum/__init__.py
+++ b/convert2rhel/pkgmanager/handlers/yum/__init__.py
@@ -163,7 +163,40 @@ class YumTransactionHandler(TransactionHandlerBase):
diagnosis="Loading repository metadata failed with error %s." % (str(e)),
)
- def _perform_operations(self):
+ def _swap_problematic_packages(self, validate_transaction):
+ """Swap system packages for their RHEL counterparts in the transaction
+
+ Some packages need to be manually injected in the transaction as a
+ "swap", since those packages are not always able to be installed
+ automatically by yum if they don't exist in the system anymore, this
+ can cause problems during the transaction as missing dependencies.
+ """
+ packages_to_backup = []
+ for old_package, new_package in system_info.swap_pkgs.items():
+ is_installed = system_info.is_rpm_installed(old_package)
+
+ if is_installed:
+ packages_to_backup.append(old_package)
+ self._base.remove(old_package)
+ self._base.install(new_package)
+
+ # Only perform backup if we are not validating the transaction.
+ if not validate_transaction:
+ loggerinst.debug(
+ "Swapping problematic packages to continue with the transaction:\n%s",
+ "\n".join(packages_to_backup),
+ )
+ remove_pkgs(
+ pkgs_to_remove=packages_to_backup,
+ backup=True,
+ critical=True,
+ set_releasever=True,
+ reposdir=BACKUP_DIR,
+ custom_releasever=system_info.version.major,
+ varsdir=os.path.join(BACKUP_DIR, "yum", "vars"),
+ )
+
+ def _perform_operations(self, validate_transaction):
"""Perform the necessary operations in the transaction.
This internal method will actually perform three operations in the
@@ -178,6 +211,7 @@ class YumTransactionHandler(TransactionHandlerBase):
loggerinst.info("Adding %s packages to the yum transaction set.", system_info.name)
try:
+ self._swap_problematic_packages(validate_transaction)
for pkg in original_os_pkgs:
can_update = self._base.update(pattern=pkg)
@@ -369,7 +403,7 @@ class YumTransactionHandler(TransactionHandlerBase):
attempts = 0
try:
while attempts <= MAX_NUM_OF_ATTEMPTS_TO_RESOLVE_DEPS:
- self._perform_operations()
+ self._perform_operations(validate_transaction)
resolved = self._resolve_dependencies(validate_transaction)
if not resolved:
loggerinst.info("Retrying to resolve dependencies %s", attempts)
@@ -385,7 +419,6 @@ class YumTransactionHandler(TransactionHandlerBase):
title="Failed to resolve dependencies.",
description="During package transaction yum failed to resolve the necessary dependencies needed for a package replacement.",
)
-
self._process_transaction(validate_transaction)
finally:
self._close_yum_base()
diff --git a/convert2rhel/systeminfo.py b/convert2rhel/systeminfo.py
index ce9afe92..45c0bd92 100644
--- a/convert2rhel/systeminfo.py
+++ b/convert2rhel/systeminfo.py
@@ -93,6 +93,8 @@ class SystemInfo:
self.eus_system = None
# Packages to be removed before the system conversion
self.excluded_pkgs = []
+ # Packages that need to perform a swap in the transaction
+ self.swap_pkgs = {}
# Release packages to be removed before the system conversion
self.repofile_pkgs = []
self.cfg_filename = None
@@ -124,6 +126,7 @@ class SystemInfo:
self.cfg_filename = self._get_cfg_filename()
self.cfg_content = self._get_cfg_content()
self.excluded_pkgs = self._get_excluded_pkgs()
+ self.swap_pkgs = self._get_swap_pkgs()
self.repofile_pkgs = self._get_repofile_pkgs()
self.default_rhsm_repoids = self._get_default_rhsm_repoids()
self.eus_rhsm_repoids = self._get_eus_rhsm_repoids()
@@ -251,6 +254,14 @@ class SystemInfo:
def _get_excluded_pkgs(self):
return self._get_cfg_opt("excluded_pkgs").split()
+ def _get_swap_pkgs(self):
+ pkgs_to_swap = {}
+ for line in self._get_cfg_opt("swap_pkgs").split():
+ old_package, new_package = tuple(line.split("|"))
+ pkgs_to_swap.update({old_package.strip(): new_package.strip()})
+
+ return pkgs_to_swap
+
def _get_repofile_pkgs(self):
return self._get_cfg_opt("repofile_pkgs").split()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment