leapp-repository/0089-UpgradeInitramfsGenerator-drop-distutils-dependency.patch
Toshio Kuratomi d9029cec24 CTC2 candidate 1 (Release for 8.10/9.5)
- Improve set_systemd_services_states logging
- [IPU 7 -> 8] Fix detection of bootable device on RAID
- Fix detection of valid sshd config with internal-sftp subsystem in Leapp
- Handle a false positive GPG check error when TargetUserSpaceInfo is missing
- Fix failing "update-ca-trust" command caused by missing util-linux package
- Improve report when a system is unsupported
- Fix handling of versions in RHUI configuration for ELS and SAP upgrades
- Add missing RHUI GCP config info for RHEL for SAP

- Resolves: RHEL-33902, RHEL-30573, RHEL-43978, RHEL-39046, RHEL-39047, RHEL-39049
2024-07-25 00:55:43 -07:00

92 lines
4.5 KiB
Diff

From 236483d5478ce845726ee05b7ca3e080105cdb80 Mon Sep 17 00:00:00 2001
From: Petr Stodulka <pstodulk@redhat.com>
Date: Mon, 15 Jul 2024 23:01:03 +0200
Subject: [PATCH 89/92] UpgradeInitramfsGenerator: drop distutils dependency
Originally the actor used distutils.version.LooseVersion to detect
newest version of installed kernel package inside target userspace
container. But the distutils python module has become deprecated
and we should not use it anymore in Python 3.12+.
However, we do not expect to see multiple versions of kernel present
inside the target userspace container as the container is created
during the IPU process from scratch (always). Considering the presence
of multiple kernels to be sign of error, which could negatively affect
also additional actions later.
Updated the solution, raising an error if multiple kernels are detected
inside the container. As we expect one kernel only, no need to compare
versions of particular possible kernel packages.
Note there are now just these cases when this could happen:
* a third party package is required to be installed inside the
container
* an explicit requirement to install particular version of container
is made by a custom actor
---
.../libraries/upgradeinitramfsgenerator.py | 37 ++++++++++++-------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
index 5a686a47..04fa061b 100644
--- a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
+++ b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
@@ -1,6 +1,5 @@
import os
import shutil
-from distutils.version import LooseVersion
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common import dnfplugin, mounting
@@ -30,23 +29,35 @@ def _get_target_kernel_version(context):
kernel_version = None
try:
- results = context.call(['rpm', '-qa', 'kernel-core'], split=True)
-
- versions = [ver.replace('kernel-core-', '') for ver in results['stdout']]
- api.current_logger().debug(
- 'Versions detected {versions}.'
- .format(versions=versions))
- sorted_versions = sorted(versions, key=LooseVersion, reverse=True)
- kernel_version = next(iter(sorted_versions), None)
+ # NOTE: Currently we install/use always kernel-core in the upgrade
+ # initramfs. We do not use currently any different kernel package
+ # in the container. Note this could change in future e.g. on aarch64
+ # for IPU 9 -> 10.
+ # TODO(pstodulk): Investigate situation on ARM systems. OAMG-11433
+ results = context.call(['rpm', '-qa', 'kernel-core'], split=True)['stdout']
except CalledProcessError:
raise StopActorExecutionError(
- 'Cannot get version of the installed kernel.',
- details={'Problem': 'Could not query the currently installed kernel through rmp.'})
+ 'Cannot get version of the installed kernel inside container.',
+ details={'Problem': 'Could not query the currently installed kernel inside container using rpm.'})
+
+ if len(results) > 1:
+ # this is should not happen. It's hypothetic situation, which alone it's
+ # already error. So skipping more sophisticated implementation.
+ # The container is always created during the upgrade and as that we expect
+ # always one-and-only kernel installed.
+ raise StopActorExecutionError(
+ 'Cannot get version of the installed kernel inside container.',
+ details={'Problem': 'Detected unexpectedly multiple kernels inside target userspace container.'}
+ )
+
+ # kernel version == version-release from package
+ kernel_version = '-'.join(results[0].rsplit("-", 2)[-2:])
+ api.current_logger().debug('Detected kernel version inside container: {}.'.format(kernel_version))
if not kernel_version:
raise StopActorExecutionError(
- 'Cannot get version of the installed kernel.',
- details={'Problem': 'A rpm query for the available kernels did not produce any results.'})
+ 'Cannot get version of the installed kernel inside container.',
+ details={'Problem': 'An rpm query for the available kernels did not produce any results.'})
return kernel_version
--
2.42.0