summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/dnf
diff options
context:
space:
mode:
authorRick Elrod <rick@elrod.me>2021-01-07 18:32:06 +0100
committerGitHub <noreply@github.com>2021-01-07 18:32:06 +0100
commit44ee04bd1f7d683fce246c16e752ace04d244b4c (patch)
tree268c57031222392cab290a1fa570d41b34cb6f69 /test/integration/targets/dnf
parentRefactor ansible-test cryptography install code. (diff)
downloadansible-44ee04bd1f7d683fce246c16e752ace04d244b4c.tar.xz
ansible-44ee04bd1f7d683fce246c16e752ace04d244b4c.zip
[dnf] Make "remove" filtering closer to dnf CLI (#73033)
Change: - Internally, use dnf.subject.Subject#get_best_query for state: absent - Add a bunch of tests for removing packages, given a bunch of different pkg specs (nv, nvr, nvra, wildcard, etc.) Test Plan: - New tests - Local experiments with DNF API via PDB. Tickets: - Fixes #72809 Signed-off-by: Rick Elrod <rick@elrod.me>
Diffstat (limited to 'test/integration/targets/dnf')
-rw-r--r--test/integration/targets/dnf/tasks/dnf.yml50
-rw-r--r--test/integration/targets/dnf/tasks/test_sos_removal.yml19
2 files changed, 69 insertions, 0 deletions
diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml
index bf0f96e673..1734d1e46d 100644
--- a/test/integration/targets/dnf/tasks/dnf.yml
+++ b/test/integration/targets/dnf/tasks/dnf.yml
@@ -772,3 +772,53 @@
that:
- wildcard_absent is successful
- wildcard_absent is not changed
+
+- name: Test removing with various package specs
+ block:
+ - name: Ensure sos is installed
+ dnf:
+ name: sos
+ state: present
+
+ - name: Determine version of sos
+ command: rpm -q --queryformat=%{version} sos
+ register: sos_version_command
+
+ - name: Determine release of sos
+ command: rpm -q --queryformat=%{release} sos
+ register: sos_release_command
+
+ - name: Determine arch of sos
+ command: rpm -q --queryformat=%{arch} sos
+ register: sos_arch_command
+
+ - set_fact:
+ sos_version: "{{ sos_version_command.stdout | trim }}"
+ sos_release: "{{ sos_release_command.stdout | trim }}"
+ sos_arch: "{{ sos_arch_command.stdout | trim }}"
+
+ # We are just trying to remove the package by specifying its spec in a
+ # bunch of different ways. Each "item" here is a test (a name passed, to make
+ # sure it matches, with how we call Hawkey in the dnf module).
+ - include_tasks: test_sos_removal.yml
+ with_items:
+ - sos
+ - sos-{{ sos_version }}
+ - sos-{{ sos_version }}-{{ sos_release }}
+ - sos-{{ sos_version }}-{{ sos_release }}.{{ sos_arch }}
+ - sos-*-{{ sos_release }}
+ - sos-{{ sos_version[0] }}*
+ - sos-{{ sos_version[0] }}*-{{ sos_release }}
+ - sos-{{ sos_version[0] }}*{{ sos_arch }}
+
+ - name: Ensure deleting a non-existing package fails correctly
+ dnf:
+ name: a-non-existent-package
+ state: absent
+ ignore_errors: true
+ register: nonexisting
+
+ - assert:
+ that:
+ - nonexisting is success
+ - nonexisting.msg == 'Nothing to do'
diff --git a/test/integration/targets/dnf/tasks/test_sos_removal.yml b/test/integration/targets/dnf/tasks/test_sos_removal.yml
new file mode 100644
index 0000000000..40ceb62bf4
--- /dev/null
+++ b/test/integration/targets/dnf/tasks/test_sos_removal.yml
@@ -0,0 +1,19 @@
+# These are safe to just check in check_mode, because in the module, the
+# logic to match packages will happen anyway. check_mode will just prevent
+# the transaction from actually running once the matches are found.
+- name: Remove {{ item }}
+ dnf:
+ name: "{{ item }}"
+ state: absent
+ check_mode: true
+ register: sos_rm
+
+- debug:
+ var: sos_rm
+
+- assert:
+ that:
+ - sos_rm is successful
+ - sos_rm is changed
+ - "'Removed: sos-{{ sos_version }}-{{ sos_release }}' in sos_rm.results[0]"
+ - sos_rm.results|length == 1