From 44ee04bd1f7d683fce246c16e752ace04d244b4c Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Thu, 7 Jan 2021 11:32:06 -0600 Subject: [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 --- test/integration/targets/dnf/tasks/dnf.yml | 50 ++++++++++++++++++++++ .../targets/dnf/tasks/test_sos_removal.yml | 19 ++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/integration/targets/dnf/tasks/test_sos_removal.yml (limited to 'test/integration/targets/dnf') 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 -- cgit v1.2.3