From c99493eb3f1121b73f76927e37834afa0d6e0269 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 19 Nov 2024 18:00:35 +0100 Subject: [PATCH] dnf5 - consolidate package resolving settings (#84335) Fixes #84334 --- .../84334-dnf5-consolidate-settings.yml | 2 ++ lib/ansible/modules/dnf5.py | 25 +++++++++++++------ test/integration/targets/dnf/tasks/repo.yml | 23 +++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/84334-dnf5-consolidate-settings.yml diff --git a/changelogs/fragments/84334-dnf5-consolidate-settings.yml b/changelogs/fragments/84334-dnf5-consolidate-settings.yml new file mode 100644 index 00000000000..7873d3ed432 --- /dev/null +++ b/changelogs/fragments/84334-dnf5-consolidate-settings.yml @@ -0,0 +1,2 @@ +bugfixes: + - dnf5 - matching on a binary can be achieved only by specifying a full path (https://github.com/ansible/ansible/issues/84334) diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index b157158514f..0e429d3a43d 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -358,14 +358,20 @@ libdnf5 = None def is_installed(base, spec): settings = libdnf5.base.ResolveSpecSettings() - # Disable checking whether SPEC is a binary -> `/usr/(s)bin/`, - # this prevents scenarios like the following: - # * the `sssd-common` package is installed and provides `/usr/sbin/sssd` binary - # * the `sssd` package is NOT installed - # * due to `set_with_binaries(True)` being default `is_installed(base, "sssd")` would "unexpectedly" return True - # If users wish to target the `sssd` binary they can by specifying the full path `name=/usr/sbin/sssd` explicitly - # due to settings.set_with_filenames(True) being default. - settings.set_with_binaries(False) + try: + settings.set_group_with_name(True) + # Disable checking whether SPEC is a binary -> `/usr/(s)bin/`, + # this prevents scenarios like the following: + # * the `sssd-common` package is installed and provides `/usr/sbin/sssd` binary + # * the `sssd` package is NOT installed + # * due to `set_with_binaries(True)` being default `is_installed(base, "sssd")` would "unexpectedly" return True + # If users wish to target the `sssd` binary they can by specifying the full path `name=/usr/sbin/sssd` explicitly + # due to settings.set_with_filenames(True) being default. + settings.set_with_binaries(False) + except AttributeError: + # dnf5 < 5.2.0.0 + settings.group_with_name = True + settings.with_binaries = False installed_query = libdnf5.rpm.PackageQuery(base) installed_query.filter_installed() @@ -655,9 +661,12 @@ class Dnf5Module(YumDnf): settings = libdnf5.base.GoalJobSettings() try: settings.set_group_with_name(True) + settings.set_with_binaries(False) except AttributeError: # dnf5 < 5.2.0.0 settings.group_with_name = True + settings.with_binaries = False + if self.bugfix or self.security: advisory_query = libdnf5.advisory.AdvisoryQuery(base) types = [] diff --git a/test/integration/targets/dnf/tasks/repo.yml b/test/integration/targets/dnf/tasks/repo.yml index ec31fe4a4ae..cdec5a85ae7 100644 --- a/test/integration/targets/dnf/tasks/repo.yml +++ b/test/integration/targets/dnf/tasks/repo.yml @@ -564,3 +564,26 @@ dnf: name: provides-binary state: absent + +# https://github.com/ansible/ansible/issues/84334 +- name: test that a binary is not matched by its base name + block: + - dnf: + name: provides-binary + state: present + + - dnf: + name: package-name + state: absent + register: dnf_result + + - assert: + that: + - dnf_result is not changed + always: + - name: Clean up + dnf: + name: + - provides-binary + - package-name + state: absent