Skip to content

Commit

Permalink
Make the "dnf4" equivalent to "dnf"
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Sep 17, 2024
1 parent 78f2fc5 commit b30045d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
31 changes: 17 additions & 14 deletions mock/docs/site-defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 <pm_pfx>, namely `dnf5_`, `dnf_`, `yum_` or
# is appropriately prefixed by <pm_pfx>, namely `dnf5_`, `dnf4_`, `yum_` or
# `microdnf_`. Mock attempts to use appropriate package manager depending on
# the `package_manager` configuration option.
#
Expand Down Expand Up @@ -508,7 +511,7 @@
# might want to use 'use_bootstrap_image' instead (then bootstrap chroot
# is just "downloaded", not installed).
#
# '<pm_pfx>_disable_plugins (e.g. dnf_disable_plugins) - list of package
# '<pm_pfx>_disable_plugins (e.g. dnf4_disable_plugins) - list of package
# manager plugins that should be always disabled when Mock executes the
# '<pm_pfx>_command' (e.g. versionlock, with Mock we always want to build
# against the latest package versions available in buildroot)
Expand All @@ -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.
#
# '<pm_pfx>_builddep_opts (e.g. dnf_builddep_opts) - list of additional
# '<pm_pfx>_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
Expand Down
4 changes: 2 additions & 2 deletions mock/mock.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +92,7 @@ BuildRequires: python%{python3_pkgversion}-jsonschema
BuildRequires: python%{python3_pkgversion}-pyroute2
BuildRequires: python%{python3_pkgversion}-pytest
BuildRequires: python%{python3_pkgversion}-requests
BuildRequires: python%{python3_pkgversion}-templated-dictionary
BuildRequires: python%{python3_pkgversion}-templated-dictionary >= 1.5
%endif

%if 0%{?fedora} || 0%{?rhel}
Expand Down
22 changes: 15 additions & 7 deletions mock/py/mockbuild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
18 changes: 11 additions & 7 deletions mock/py/mockbuild/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}


Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit b30045d

Please sign in to comment.