leapp-repository/SOURCES/0013-fix-userspacegen-add-exeception-handling-to-swapping.patch
eabdullin b1bd6e77a6 Import from CS git
(cherry picked from commit 5bdc5cf293)
2025-05-15 11:55:21 +03:00

69 lines
3.2 KiB
Diff

From 53f125b42f3e17354cc2d3e93b80fe089cf4c3b2 Mon Sep 17 00:00:00 2001
From: Michal Hecko <mhecko@redhat.com>
Date: Tue, 4 Mar 2025 14:42:44 +0100
Subject: [PATCH 13/37] fix(userspacegen): add exeception handling to swapping
of RHUI clients
Leapp swaps to RHUI target clients (uninstall source client+install
target client) in the scratch container to gain repository access.
To perform this step atomically, without loosing repository access
in between, `dnf shell` is invoked. The instruction as to which RPMs
should be uninstalled and which should be installed are given on
stdin of the `dnf shell` command. Currently, if we fail to swap clients
we crash with an unhandled exception `CalledProcessError` that contains
no information about what went wrong since the actual performed
transaction is hidden within the stdin of the process. This patch
adds error handling, so that we can tell that we have failed to swap
RHUI clients. Leapp's logs also contain the full DNF transaction as well
as possible explanations on why we failed.
jira-ref: RHEL-77945
---
.../libraries/userspacegen.py | 30 ++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
index 12736ab7..9fc96a52 100644
--- a/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
+++ b/repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py
@@ -1239,7 +1239,35 @@ def setup_target_rhui_access_if_needed(context, indata):
'shell'
]
- context.call(cmd, callback_raw=utils.logging_handler, stdin='\n'.join(dnf_transaction_steps))
+ try:
+ dnf_shell_instructions = '\n'.join(dnf_transaction_steps)
+ api.current_logger().debug(
+ 'Supplying the following instructions to the `dnf shell`: {}'.format(dnf_shell_instructions)
+ )
+ context.call(cmd, callback_raw=utils.logging_handler, stdin=dnf_shell_instructions)
+ except CalledProcessError as error:
+ api.current_logger().debug(
+ 'Failed to swap RHUI clients. This is likely because there are no repositories '
+ ' containing RHUI clients enabled, or we cannot access them.'
+ )
+ api.current_logger().debug(error)
+
+ swapping_clients_info_msg = 'Failed to swap `{0}` (source client{1}) with {2} (target client{3}).'
+ swapping_clients_info_msg = swapping_clients_info_msg.format(
+ ' '.join(indata.rhui_info.src_client_pkg_names),
+ '' if len(indata.rhui_info.src_client_pkg_names) == 1 else 's',
+ ' '.join(indata.rhui_info.target_client_pkg_names),
+ '' if len(indata.rhui_info.target_client_pkg_names) == 1 else 's',
+ )
+
+ details = {
+ 'details': swapping_clients_info_msg,
+ 'error': str(error)
+ }
+ raise StopActorExecutionError(
+ 'Failed to swap RHUI clients to establish content access',
+ details=details
+ )
_apply_rhui_access_postinstall_tasks(context, setup_info)
--
2.49.0