[yum] Make package removal confirmation strict (#69592)

* [yum] Make package removal confirmation strict

Change:
After removing packages, the yum module does a final check to ensure the
packages are really installed. The check would include packages that
were RPM `Provides:` values of another package.

This means that, for example, if a third-party kernel RPM spec had
`Provides: kernel` in it, removing the stock kernel would be successful
but the check to see if it was really removed would fail and cause
Ansible to report a failure.

Test Plan:
Tested on local CentOS 7 VM with kernel from elrepo which is known to
`Provides: kernel`.

Tickets:
Fixes #69237
Refs #35672
Refs #40723

Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
Rick Elrod 2020-05-26 13:47:39 -05:00 committed by GitHub
parent f7dfa817ae
commit 4aff87770e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -1159,7 +1159,7 @@ class YumModule(YumDnf):
if pkg.startswith('@'):
installed = self.is_group_env_installed(pkg)
else:
installed = self.is_installed(repoq, pkg)
installed = self.is_installed(repoq, pkg, is_pkg=True)
if installed:
# Return a message so it's obvious to the user why yum failed

View file

@ -838,3 +838,31 @@
# actually honored and those releases are EOL'd so we have no expectation they
# will ever be fixed
when: not ((ansible_distribution == "Fedora") and (ansible_distribution_major_version|int < 26))
- name: Check that packages with Provides are handled correctly in state=absent
block:
- name: Install test packages
yum:
name:
- https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/yum/test-package-that-provides-toaster-1.3.3.7-1.el7.noarch.rpm
- https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/yum/toaster-1.2.3.4-1.el7.noarch.rpm
register: install
- name: Remove toaster
yum:
name: toaster
state: absent
register: remove
- name: rpm -qa
command: rpm -qa
register: rpmqa
- assert:
that:
- install is successful
- install is changed
- remove is successful
- remove is changed
- "'toaster-1.2.3.4' not in rpmqa.stdout"
- "'test-package-that-provides-toaster' in rpmqa.stdout"