From 07084217dc4d5ee1f5434eb8bfde7f16e968200f Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Wed, 29 Apr 2020 16:30:01 -0500 Subject: [PATCH] [dnf] Make behavior/errors compatible for new DNF Change: Extend the logic for custom error handling in the dnf module, so that on newer DNF (such as DNF that ships with modern Fedora 31 container images, and ships with RHEL 8.2) we report errors consistently with older DNF. Test Plan: Ran dnf integration tests against an old Fedora 31 container image and a brand new Fedora 32 container image; tess passed on both. Signed-off-by: Rick Elrod --- changelogs/fragments/dnf-4-2-18.yml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 10 ++++++++-- test/integration/targets/dnf/tasks/dnf.yml | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/dnf-4-2-18.yml diff --git a/changelogs/fragments/dnf-4-2-18.yml b/changelogs/fragments/dnf-4-2-18.yml new file mode 100644 index 00000000000..dfd50ea17da --- /dev/null +++ b/changelogs/fragments/dnf-4-2-18.yml @@ -0,0 +1,3 @@ +bugfixes: + - dnf - Unified error messages when trying to install a nonexistent package with newer dnf (4.2.18) vs older dnf (4.2.9) + - dnf - Unified error messages when trying to remove a wildcard name that is not currently installed, with newer dnf (4.2.18) vs older dnf (4.2.9) diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index b44ce695f93..f8fa5d96bf2 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -339,7 +339,10 @@ class DnfModule(YumDnf): For unhandled dnf.exceptions.Error scenarios, there are certain error messages we want to filter in an install scenario. Do that here. """ - if to_text("no package matched") in to_text(error): + if ( + to_text("no package matched") in to_text(error) or + to_text("No match for argument:") in to_text(error) + ): return "No package {0} available.".format(spec) return error @@ -350,7 +353,10 @@ class DnfModule(YumDnf): messages we want to ignore in a removal scenario as known benign failures. Do that here. """ - if 'no package matched' in to_native(error): + if ( + 'no package matched' in to_native(error) or + 'No match for argument:' in to_native(error) + ): return (False, "{0} is not installed".format(spec)) # Return value is tuple of: diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 0b013d0e10b..abe7068d243 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -701,3 +701,14 @@ - "'vim-minimal' in rpm_output.stdout" when: - ansible_distribution == 'Fedora' + +- name: Remove wildcard package that isn't installed + dnf: + name: firefox* + state: absent + register: wildcard_absent + +- assert: + that: + - wildcard_absent is successful + - wildcard_absent is not changed