[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>
pull/69282/head
Rick Elrod 5 years ago committed by Matt Clay
parent a4f13acd85
commit 07084217dc

@ -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)

@ -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:

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

Loading…
Cancel
Save