summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRick Elrod <rick@elrod.me>2020-04-29 16:30:01 -0500
committerMatt Clay <matt@mystile.com>2020-04-30 14:32:40 -0700
commit07084217dc4d5ee1f5434eb8bfde7f16e968200f (patch)
tree33a9f47d714af476b9d610a539ffd216a561287c
parenta4f13acd85e91fb83b1b599de4bf4091044a0b5c (diff)
downloadansible-07084217dc4d5ee1f5434eb8bfde7f16e968200f.tar.gz
[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 <rick@elrod.me>
-rw-r--r--changelogs/fragments/dnf-4-2-18.yml3
-rw-r--r--lib/ansible/modules/packaging/os/dnf.py10
-rw-r--r--test/integration/targets/dnf/tasks/dnf.yml11
3 files changed, 22 insertions, 2 deletions
diff --git a/changelogs/fragments/dnf-4-2-18.yml b/changelogs/fragments/dnf-4-2-18.yml
new file mode 100644
index 0000000000..dfd50ea17d
--- /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 b44ce695f9..f8fa5d96bf 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 0b013d0e10..abe7068d24 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