From 55996d598fd1c75d17cf43b00f4a4431d3e8a7b7 Mon Sep 17 00:00:00 2001 From: mhecko Date: Tue, 15 Aug 2023 16:29:11 +0200 Subject: [PATCH] lib(kernel): iteratively query whatprovides --- .../system_upgrade/common/libraries/kernel.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/repos/system_upgrade/common/libraries/kernel.py b/repos/system_upgrade/common/libraries/kernel.py index 283504093e..178ba00528 100644 --- a/repos/system_upgrade/common/libraries/kernel.py +++ b/repos/system_upgrade/common/libraries/kernel.py @@ -116,16 +116,21 @@ def get_kernel_pkg_info_for_uname_r(uname_r): :returns: Information about the kernel package providing given uname_r :rtype: KernelPkgInfo """ - try: - kernel_pkg_nevras = run(['rpm', '-q', '--whatprovides'] + KERNEL_UNAME_R_PROVIDES, split=True)['stdout'] - for kernel_pkg_nevra in kernel_pkg_nevras: - provided_uname = get_uname_r_provided_by_kernel_pkg(kernel_pkg_nevra) - if not provided_uname: - api.current_logger().warning('Failed to obtain uname-r provided by %s', kernel_pkg_nevra) - if provided_uname == uname_r: - return get_kernel_pkg_info(kernel_pkg_nevra) - except CalledProcessError as e: - raise StopActorExecutionError(message='Unable to obtain kernel information of the booted kernel.', - details={'details': str(e), 'stderr': e.stderr}) + kernel_pkg_nevras = [] + for kernel_uname_r_provide in KERNEL_UNAME_R_PROVIDES: + try: + kernel_pkg_nevras += run(['rpm', '-q', '--whatprovides', kernel_uname_r_provide], split=True)['stdout'] + except CalledProcessError: # There is nothing providing a particular provide, e.g, kernel-rt-uname-r + continue # Nothing bad happened, continue + + kernel_pkg_nevras = set(kernel_pkg_nevras) + + for kernel_pkg_nevra in kernel_pkg_nevras: + provided_uname = get_uname_r_provided_by_kernel_pkg(kernel_pkg_nevra) # We know all packages provide a uname + if not provided_uname: + api.current_logger().warning('Failed to obtain uname-r provided by %s', kernel_pkg_nevra) + if provided_uname == uname_r: + return get_kernel_pkg_info(kernel_pkg_nevra) + raise StopActorExecutionError(message='Unable to obtain kernel information of the booted kernel: no package is ' 'providing the booted kernel release returned by uname.')