From b581d774dc59a5d8863c58ac61f2d3e916071694 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 16 Feb 2024 21:01:43 +0100 Subject: [PATCH] Make the "dnf4" equivalent to "dnf" Fixes: https://github.com/rpm-software-management/mock/issues/1271 --- mock/docs/site-defaults.cfg | 31 ++++++++++--------- .../setup-playbook/tasks/main.yml | 4 +++ mock/mock.spec | 2 +- mock/py/mockbuild/config.py | 22 ++++++++----- mock/py/mockbuild/package_manager.py | 18 ++++++----- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/mock/docs/site-defaults.cfg b/mock/docs/site-defaults.cfg index 6e990004b..b0d655ce7 100644 --- a/mock/docs/site-defaults.cfg +++ b/mock/docs/site-defaults.cfg @@ -91,10 +91,13 @@ # variable use_container_host_hostname or %_buildhost macro can override this # config_opts['hostname'] = 'my.own.hostname' -# The default package manager is DNF -# config_opts['package_manager'] = 'dnf' -# If you want to use DNF, set it to 'dnf'. To use DNF you need to have dnf and -# dnf-plugins-core installed +# The default package manager is DNF4. +# https://github.com/rpm-software-management/dnf +# Options are: +# - 'dnf4' for DNF4 (Python) https://github.com/rpm-software-management/dnf +# - 'dnf5' for DNF5 (C++) https://github.com/rpm-software-management/dnf5 +# - 'yum' for YUM https://github.com/rpm-software-management/yum +#config_opts['package_manager'] = 'dnf4' # Number of attempts to execute package manager's action, and delay between # attempts (seconds). This is useful e.g. if the build is done against @@ -132,11 +135,11 @@ #config_opts['use_bootstrap'] = True #config_opts['system_yum_command'] = '/usr/bin/yum' -#config_opts['system_dnf_command'] = '/usr/bin/dnf' +#config_opts['system_dnf4_command'] = '/usr/bin/dnf' # The bootstrap chroot is normally installed using a package manager from host, # but in some cases even this isn't possible (e.g. installing rather new ZSTD -# compressed dnf.rpm package by 'dnf_install_command' on epel-7 host). In such +# compressed dnf.rpm package by 'dnf4_install_command' on epel-7 host). In such # case, you may need to have "bootstrap" chroot pre-populated from a container # image first (where the package manager stack is already pre-installed, so # mock doesn't have to). @@ -476,7 +479,7 @@ # # You can configure how DNF (and other packager managers) will be used with # Mock. Each option is specific to a concrete package manager, and then it -# is appropriately prefixed by , namely `dnf5_`, `dnf_`, `yum_` or +# is appropriately prefixed by , namely `dnf5_`, `dnf4_`, `yum_` or # `microdnf_`. Mock attempts to use appropriate package manager depending on # the `package_manager` configuration option. # @@ -508,7 +511,7 @@ # might want to use 'use_bootstrap_image' instead (then bootstrap chroot # is just "downloaded", not installed). # -# '_disable_plugins (e.g. dnf_disable_plugins) - list of package +# '_disable_plugins (e.g. dnf4_disable_plugins) - list of package # manager plugins that should be always disabled when Mock executes the # '_command' (e.g. versionlock, with Mock we always want to build # against the latest package versions available in buildroot) @@ -518,18 +521,18 @@ # build dependencies. There's no 'yum builddep' (sub)command though, # but /bin/yum-builddep. Use this option to override the default. # -# '_builddep_opts (e.g. dnf_builddep_opts) - list of additional +# '_builddep_opts (e.g. dnf5_builddep_opts) - list of additional # options to always use with the builddep command # DNF (or DNF4, Python) - https://github.com/rpm-software-management/dnf -#config_opts['dnf_command'] = '/usr/bin/dnf-3' -#config_opts['dnf_common_opts'] = ['--setopt=deltarpm=False', '--setopt=allow_vendor_change=yes', '--allowerasing'] +#config_opts['dnf4_command'] = '/usr/bin/dnf-3' +#config_opts['dnf4_common_opts'] = ['--setopt=deltarpm=False', '--setopt=allow_vendor_change=yes', '--allowerasing'] # DF5 sub-command 'builddep' doesn't support the '--allowerasing' option: # https://github.com/rpm-software-management/dnf5/issues/461 #config_opts["dnf5_avoid_opts"] = {"builddep": ["--allowerasing"]} -#config_opts['dnf_install_command'] = 'install python3-dnf python3-dnf-plugins-core' -#config_opts['dnf_disable_plugins'] = ['local', 'spacewalk', 'versionlock'] -#config_opts['dnf_builddep_opts'] = [] +#config_opts['dnf4_install_command'] = 'install python3-dnf python3-dnf-plugins-core' +#config_opts['dnf4_disable_plugins'] = ['local', 'spacewalk', 'versionlock'] +#config_opts['dnf4_builddep_opts'] = [] # DNF5 (DNF4 re-written in C++) https://github.com/rpm-software-management/dnf5 # Known issue with DNF5: --forcearch is not supported by DNF5 diff --git a/mock/integration-tests/setup-playbook/tasks/main.yml b/mock/integration-tests/setup-playbook/tasks/main.yml index 977a35145..998ec55ab 100644 --- a/mock/integration-tests/setup-playbook/tasks/main.yml +++ b/mock/integration-tests/setup-playbook/tasks/main.yml @@ -3,6 +3,10 @@ community.general.copr: name: '@mock/mock-stable' +- name: up2date mock dependencies + community.general.copr: + name: '@mock/mock-deps' + - name: install mock and other needed packages package: name={{ packages }} state=latest vars: diff --git a/mock/mock.spec b/mock/mock.spec index 49548c6ec..a310f5038 100644 --- a/mock/mock.spec +++ b/mock/mock.spec @@ -53,7 +53,7 @@ Requires: python%{python3_pkgversion}-jinja2 Requires: python%{python3_pkgversion}-requests Requires: python%{python3_pkgversion}-rpm Requires: python%{python3_pkgversion}-pyroute2 -Requires: python%{python3_pkgversion}-templated-dictionary +Requires: python%{python3_pkgversion}-templated-dictionary >= 1.5 Requires: python%{python3_pkgversion}-backoff BuildRequires: python%{python3_pkgversion}-backoff BuildRequires: python%{python3_pkgversion}-devel diff --git a/mock/py/mockbuild/config.py b/mock/py/mockbuild/config.py index 4f29d9fcb..bc63ad709 100644 --- a/mock/py/mockbuild/config.py +++ b/mock/py/mockbuild/config.py @@ -51,7 +51,15 @@ def nspawn_supported(): @traceLog() def setup_default_config_opts(): "sets up default configuration." - config_opts = TemplatedDictionary(alias_spec={'dnf.conf': ['yum.conf', 'dnf5.conf']}) + + alt_opts = {'dnf.conf': ['yum.conf', 'dnf5.conf', 'dnf4.conf']} + for alt in ["dnf_command", "system_dnf_command", "dnf_common_opts", + "dnf_install_command", "dnf_disable_plugins", + "dnf_avoid_opts"]: + alt_opts[alt.replace("dnf", "dnf4")] = alt + + config_opts = TemplatedDictionary(alias_spec=alt_opts) + config_opts['config_paths'] = [] config_opts['version'] = VERSION config_opts['basedir'] = '/var/lib/mock' # root name is automatically added to this @@ -323,12 +331,12 @@ def setup_default_config_opts(): config_opts['yum_builddep_command'] = '/usr/bin/yum-builddep' config_opts["yum_avoid_opts"] = {} - config_opts['dnf_command'] = '/usr/bin/dnf-3' - config_opts['system_dnf_command'] = '/usr/bin/dnf-3' - config_opts['dnf_common_opts'] = ['--setopt=deltarpm=False', '--setopt=allow_vendor_change=yes', '--allowerasing'] - config_opts['dnf_install_command'] = 'install python3-dnf python3-dnf-plugins-core' - config_opts['dnf_disable_plugins'] = ['local', 'spacewalk', 'versionlock'] - config_opts["dnf_avoid_opts"] = {} + config_opts['dnf4_command'] = '/usr/bin/dnf-3' + config_opts['system_dnf4_command'] = '/usr/bin/dnf-3' + config_opts['dnf4_common_opts'] = ['--setopt=deltarpm=False', '--setopt=allow_vendor_change=yes', '--allowerasing'] + config_opts['dnf4_install_command'] = 'install python3-dnf python3-dnf-plugins-core' + config_opts['dnf4_disable_plugins'] = ['local', 'spacewalk', 'versionlock'] + config_opts["dnf4_avoid_opts"] = {} config_opts['dnf5_command'] = '/usr/bin/dnf5' config_opts['system_dnf5_command'] = '/usr/bin/dnf5' diff --git a/mock/py/mockbuild/package_manager.py b/mock/py/mockbuild/package_manager.py index fdaf2d2ed..5df629b7f 100644 --- a/mock/py/mockbuild/package_manager.py +++ b/mock/py/mockbuild/package_manager.py @@ -18,10 +18,11 @@ from .mounts import BindMountPoint fallbacks = { - 'dnf': ['dnf', 'dnf5', 'yum'], - 'yum': ['yum', 'dnf', 'dnf5'], - 'microdnf': ['microdnf', 'dnf','dnf5', 'yum'], - 'dnf5': ['dnf5', 'dnf', 'yum'], + 'dnf4': ['dnf4', 'dnf5', 'yum'], + 'dnf': ['dnf4', 'dnf5', 'yum'], # backward-compat + 'yum': ['yum', 'dnf4', 'dnf5'], + 'microdnf': ['microdnf', 'dnf4', 'dnf5', 'yum'], + 'dnf5': ['dnf5', 'dnf4', 'yum'], } @@ -30,7 +31,7 @@ def package_manager_from_string(name): return Dnf5 if name == 'yum': return Yum - if name == 'dnf': + if name in ['dnf4', 'dnf']: # dnf for backward compat return Dnf if name == 'microdnf': return MicroDnf @@ -45,6 +46,9 @@ def package_manager_exists(pm_class, config_opts, chroot=None): return False # resolve symlinks, and detect that e.g. /bin/yum doesn't point to /bin/dnf real_pathname = os.path.realpath(pathname) + if name == 'dnf4': + # The DNF4 used to be /bin/dnf, not /bin/dnf4 + name = 'dnf' return name in real_pathname @@ -92,7 +96,7 @@ def package_manager_class_fallback(config_opts, buildroot, fallback): return pm_class - raise Exception("No package from {} found".format(fallbacks[desired])) + raise Exception(f"No package from {fallbacks[desired]} found, desired {desired}") def package_manager(buildroot, bootstrap_buildroot, fallback): @@ -671,7 +675,7 @@ def _check_missing(output): class Dnf(_PackageManager): - name = 'dnf' + name = 'dnf4' support_installroot = True def __init__(self, config, buildroot, plugins, bootstrap_buildroot):