From 3a6f825a8e06a32915899097580003463d5800dd Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Fri, 12 Apr 2024 09:34:46 +0200 Subject: [PATCH] dnf - honor installroot and substitutes in paths (#83011) In #80094 support for var substitution for cachedir was added but there are more options that should be supported. Using an API for prepend_installroot which should be done anyway provide that feature so use that. In addition, perform the operation once all substitutes are in place (releasever as well). --- .../fragments/dnf-installroot-substitutions.yml | 3 +++ lib/ansible/modules/dnf.py | 11 +++++------ .../_util/controller/sanity/mypy/ansible-core.ini | 3 --- .../_util/controller/sanity/mypy/modules.ini | 3 --- 4 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 changelogs/fragments/dnf-installroot-substitutions.yml diff --git a/changelogs/fragments/dnf-installroot-substitutions.yml b/changelogs/fragments/dnf-installroot-substitutions.yml new file mode 100644 index 00000000000..aef96f4e2b3 --- /dev/null +++ b/changelogs/fragments/dnf-installroot-substitutions.yml @@ -0,0 +1,3 @@ +bugfixes: + - dnf - honor installroot for ``cachedir``, ``logdir`` and ``persistdir`` + - dnf - perform variable substitutions in ``logdir`` and ``persistdir`` diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index 16b3bcc2b41..44abe0b7ee0 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -403,7 +403,6 @@ from ansible.module_utils.yumdnf import YumDnf, yumdnf_argument_spec # to set proper locale before importing dnf to be able to scrape # the output in some cases (FIXME?). dnf = None -libdnf = None class DnfModule(YumDnf): @@ -484,7 +483,6 @@ class DnfModule(YumDnf): os.environ['LANGUAGE'] = os.environ['LANG'] = locale global dnf - global libdnf try: import dnf import dnf.const @@ -492,7 +490,6 @@ class DnfModule(YumDnf): import dnf.package import dnf.subject import dnf.util - import libdnf HAS_DNF = True except ImportError: HAS_DNF = False @@ -560,9 +557,6 @@ class DnfModule(YumDnf): # Load substitutions from the filesystem conf.substitutions.update_from_etc(installroot) - # Substitute variables in cachedir path - conf.cachedir = libdnf.conf.ConfigParser.substitute(conf.cachedir, conf.substitutions) - # Handle different DNF versions immutable mutable datatypes and # dnf v1/v2/v3 # @@ -596,6 +590,11 @@ class DnfModule(YumDnf): # setting this to an empty string instead of None appears to mimic the DNF CLI behavior conf.substitutions['releasever'] = '' + # Honor installroot for dnf directories + # This will also perform variable substitutions in the paths + for opt in ('cachedir', 'logdir', 'persistdir'): + conf.prepend_installroot(opt) + # Set skip_broken (in dnf this is strict=0) if self.skip_broken: conf.strict = 0 diff --git a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini index 0a8a3e6b40f..0251f674b51 100644 --- a/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini +++ b/test/lib/ansible_test/_util/controller/sanity/mypy/ansible-core.ini @@ -58,9 +58,6 @@ ignore_missing_imports = True [mypy-dnf.*] ignore_missing_imports = True -[mypy-libdnf.*] -ignore_missing_imports = True - [mypy-apt.*] ignore_missing_imports = True diff --git a/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini b/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini index ddabecdabb6..b4e7b05eb9f 100644 --- a/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini +++ b/test/lib/ansible_test/_util/controller/sanity/mypy/modules.ini @@ -25,9 +25,6 @@ ignore_missing_imports = True [mypy-dnf.*] ignore_missing_imports = True -[mypy-libdnf.*] -ignore_missing_imports = True - [mypy-apt.*] ignore_missing_imports = True