From 85ebeeb0c21ed9ca507039e218124dfcd28aedf6 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 28 Sep 2024 18:28:34 +0200 Subject: [PATCH 1/4] package_manager: fix the DNF4 fallback for --no-bootstrap-chroot When package_manager = dnf, 'dnf4' is to be selected and used when bootstrap chroot is disabled. This was not detected by test-suite; my bet is that we do tests with testConfig=fedora-40-x86_64 which is already dnf5 and we have dnf5 installed on the testing machines. I'm trying to modify one test-case to test DNF4 chroot explicitly. Fixes: #1475 --- mock/py/mockbuild/package_manager.py | 7 +++++-- releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix diff --git a/mock/py/mockbuild/package_manager.py b/mock/py/mockbuild/package_manager.py index af3f24a24..2c4b7b984 100644 --- a/mock/py/mockbuild/package_manager.py +++ b/mock/py/mockbuild/package_manager.py @@ -19,7 +19,6 @@ fallbacks = { 'dnf4': ['dnf4', 'dnf5', 'yum'], - 'dnf': ['dnf4', 'dnf5', 'yum'], # backward-compat 'yum': ['yum', 'dnf4', 'dnf5'], 'microdnf': ['microdnf', 'dnf4', 'dnf5', 'yum'], 'dnf5': ['dnf5', 'dnf4', 'yum'], @@ -31,7 +30,7 @@ def package_manager_from_string(name): return Dnf5 if name == 'yum': return Yum - if name in ['dnf4', 'dnf']: # dnf for backward compat + if name in 'dnf4': return Dnf if name == 'microdnf': return MicroDnf @@ -54,6 +53,10 @@ def package_manager_exists(pm_class, config_opts, chroot=None): def package_manager_class_fallback(config_opts, buildroot, fallback): desired = config_opts['package_manager'] + + if desired == 'dnf': # backward compat + desired = 'dnf4' + if not fallback: return package_manager_from_string(desired) diff --git a/releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix b/releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix new file mode 100644 index 000000000..5d92876ba --- /dev/null +++ b/releng/release-notes-next/dnf-to-dnf4-fallback-fix.bugfix @@ -0,0 +1,3 @@ +A fix for the DNF → DNF4 fallback has been applied. Now Mock correctly selects +DNF4, even when the `--no-bootstrap-chroot` command is used. See +[issue#1475][] for more info. From 6daf6f40d3bbffa8e9f306928fa8404fdbe4f88f Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 28 Sep 2024 18:28:51 +0200 Subject: [PATCH 2/4] package_manager: drop a no-op call --- mock/py/mockbuild/package_manager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mock/py/mockbuild/package_manager.py b/mock/py/mockbuild/package_manager.py index 2c4b7b984..19ea4220b 100644 --- a/mock/py/mockbuild/package_manager.py +++ b/mock/py/mockbuild/package_manager.py @@ -73,8 +73,6 @@ def package_manager_class_fallback(config_opts, buildroot, fallback): for manager in fallbacks[desired]: pm_class = package_manager_from_string(manager) - package_manager_exists(pm_class, config_opts) - if package_manager_exists(pm_class, config_opts, chroot=chroot_to_search_in): if desired == manager: return pm_class From b8b67c7e71c414844a26214f1384eb6b8b598f16 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 28 Sep 2024 18:29:17 +0200 Subject: [PATCH 3/4] package_manager: make it obvious that some methods are internal --- mock/py/mockbuild/package_manager.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mock/py/mockbuild/package_manager.py b/mock/py/mockbuild/package_manager.py index 19ea4220b..b7c4082ee 100644 --- a/mock/py/mockbuild/package_manager.py +++ b/mock/py/mockbuild/package_manager.py @@ -25,7 +25,7 @@ } -def package_manager_from_string(name): +def _package_manager_from_string(name): if name == 'dnf5': return Dnf5 if name == 'yum': @@ -37,7 +37,7 @@ def package_manager_from_string(name): raise Exception('Unrecognized package manager "{}"'.format(name)) -def package_manager_exists(pm_class, config_opts, chroot=None): +def _package_manager_exists(pm_class, config_opts, chroot=None): name = pm_class.name command = pm_class.get_command(config_opts) pathname = (chroot or "") + command @@ -51,14 +51,14 @@ def package_manager_exists(pm_class, config_opts, chroot=None): return name in real_pathname -def package_manager_class_fallback(config_opts, buildroot, fallback): +def _package_manager_class_fallback(config_opts, buildroot, fallback): desired = config_opts['package_manager'] if desired == 'dnf': # backward compat desired = 'dnf4' if not fallback: - return package_manager_from_string(desired) + return _package_manager_from_string(desired) getLog().debug("searching for '%s' package manager or alternatives", desired) if desired not in fallbacks: @@ -72,8 +72,8 @@ def package_manager_class_fallback(config_opts, buildroot, fallback): bootstrap = buildroot.is_bootstrap for manager in fallbacks[desired]: - pm_class = package_manager_from_string(manager) - if package_manager_exists(pm_class, config_opts, chroot=chroot_to_search_in): + pm_class = _package_manager_from_string(manager) + if _package_manager_exists(pm_class, config_opts, chroot=chroot_to_search_in): if desired == manager: return pm_class @@ -101,7 +101,7 @@ def package_manager_class_fallback(config_opts, buildroot, fallback): def package_manager(buildroot, bootstrap_buildroot, fallback): - cls = package_manager_class_fallback(buildroot.config, buildroot, fallback) + cls = _package_manager_class_fallback(buildroot.config, buildroot, fallback) return cls(buildroot.config, buildroot, buildroot.plugins, bootstrap_buildroot) From 1fed15e7b7b77a9cba48c7568634339aaa400f61 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sat, 28 Sep 2024 18:52:38 +0200 Subject: [PATCH 4/4] package_manager: fix linter issues The rename of methods makes linter thing these are new issues: - Ignore the f"" warning, as f-string is not optimal for this use-case. - Use RuntimeError instead of the generic Exception. It is still too generic and mock prints stack trace if it happens, but package_manager.py probably deserves it's own exception (#1477). --- mock/py/mockbuild/package_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mock/py/mockbuild/package_manager.py b/mock/py/mockbuild/package_manager.py index b7c4082ee..fa3001dd6 100644 --- a/mock/py/mockbuild/package_manager.py +++ b/mock/py/mockbuild/package_manager.py @@ -34,7 +34,7 @@ def _package_manager_from_string(name): return Dnf if name == 'microdnf': return MicroDnf - raise Exception('Unrecognized package manager "{}"'.format(name)) + raise RuntimeError(f'Unrecognized package manager "{name}"') def _package_manager_exists(pm_class, config_opts, chroot=None): @@ -84,6 +84,7 @@ def _package_manager_class_fallback(config_opts, buildroot, fallback): return pm_class if not bootstrap: + # pylint: disable=consider-using-f-string print("""WARNING! WARNING! WARNING! You are building package for distribution which uses {0}. However your system does not support {0}. You can continue with {1}, which will likely succeed, @@ -97,7 +98,7 @@ def _package_manager_class_fallback(config_opts, buildroot, fallback): return pm_class - raise Exception(f"No package from {fallbacks[desired]} found, desired {desired}") + raise RuntimeError(f"No package from {fallbacks[desired]} found, desired {desired}") def package_manager(buildroot, bootstrap_buildroot, fallback):