From 603e65d2041e6e27cdd7ea9a6bf5a25ebc75fcf4 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 2 Jun 2025 09:52:38 +0200 Subject: [PATCH] Merge dnf and dnf5 integration tests (#85199) (cherry picked from commit 01bb9393d7f48bae396615e8c95d630e5421a928) --- test/integration/targets/dnf/tasks/dnf.yml | 2 +- .../integration/targets/dnf/tasks/logging.yml | 12 ++ test/integration/targets/dnf/tasks/main.yml | 122 ++++++++++-------- .../targets/dnf/tasks/multilib.yml | 2 +- .../dnf/tasks/skip_broken_and_nobest.yml | 6 +- test/integration/targets/dnf/vars/main.yml | 4 - test/integration/targets/dnf5/aliases | 6 - test/integration/targets/dnf5/playbook.yml | 34 ----- test/integration/targets/dnf5/runme.sh | 5 - 9 files changed, 83 insertions(+), 110 deletions(-) delete mode 100644 test/integration/targets/dnf/vars/main.yml delete mode 100644 test/integration/targets/dnf5/aliases delete mode 100644 test/integration/targets/dnf5/playbook.yml delete mode 100755 test/integration/targets/dnf5/runme.sh diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 2d7772492f7..77cd0c3720d 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -896,4 +896,4 @@ - '"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: " in disable_plugin_result.msg' - '"nonexisting" in enable_plugin_result.msg' - '"nonexisting" in disable_plugin_result.msg' - when: dnf5|default(false) + when: dnf5 diff --git a/test/integration/targets/dnf/tasks/logging.yml b/test/integration/targets/dnf/tasks/logging.yml index f3e8503c433..b38e029dff1 100644 --- a/test/integration/targets/dnf/tasks/logging.yml +++ b/test/integration/targets/dnf/tasks/logging.yml @@ -1,3 +1,15 @@ +- set_fact: + dnf_log_files: + - /var/log/dnf5.log + when: dnf5 + +- set_fact: + dnf_log_files: + - /var/log/dnf.log + - /var/log/dnf.rpm.log + - /var/log/dnf.librepo.log + when: not dnf5 + - name: Check logging enabled block: - name: remove logfiles if exist diff --git a/test/integration/targets/dnf/tasks/main.yml b/test/integration/targets/dnf/tasks/main.yml index 2d98d332012..37f597242df 100644 --- a/test/integration/targets/dnf/tasks/main.yml +++ b/test/integration/targets/dnf/tasks/main.yml @@ -1,64 +1,74 @@ -# test code for the dnf module # (c) 2014, James Tanner +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +- set_fact: + dnf5: "{{ (ansible_distribution == 'RedHat' and ansible_distribution_major_version | int > 10) or ansible_distribution == 'Fedora' }}" -- when: dnf5 | default(False) +- when: dnf5 block: - - block: - - include_tasks: dnf.yml - - include_tasks: skip_broken_and_nobest.yml - - block: - - include_tasks: filters.yml - - include_tasks: filters_check_mode.yml - tags: - - filters - - include_tasks: gpg.yml - - include_tasks: repo.yml - - include_tasks: dnf_group_remove.yml - - include_tasks: dnfinstallroot.yml - - include_tasks: logging.yml - - include_tasks: cacheonly.yml - - include_tasks: multilib.yml - when: ansible_distribution in ['Fedora', 'RedHat'] + - command: "dnf install -y 'dnf-command(copr)'" + - name: Test against dnf5 nightly build to detect any issues early + command: dnf copr enable -y rpmsoftwaremanagement/dnf-nightly - # Attempting to install a different RHEL release in a tmpdir doesn't work (rhel8 beta) - - include_tasks: dnfreleasever.yml - when: ansible_distribution == 'Fedora' + - name: Ensure module deps are not installed + command: dnf remove -y python3-libdnf5 - - when: - - ansible_distribution == 'RedHat' - - not dnf5|default(false) - block: - # FUTURE - look at including AppStream support in our local repo - - name: list modules - command: dnf module list -q - register: module_list + - name: Test the auto_install_module_deps option + dnf5: + name: sos + auto_install_module_deps: false + register: r + ignore_errors: true - # A module that only has a single version - - name: Find a module that meets our testing needs - set_fact: - astream_name: '@{{ module.name }}:{{ module.version }}/{{ module.profile }}' - astream_name_no_stream: '@{{ module.name }}/{{ module.profile }}' - vars: - module: '{{ module_list.stdout|get_first_single_version_module }}' + - assert: + that: + - r is failed + - r.msg is contains("Could not import the libdnf5 python module") - - include_tasks: modularity.yml - tags: - - dnf_modularity - rescue: - # Just in case something crazy happens when listing or parsing modules - - meta: noop + # Now the first dnf5 task in the integration tests should auto install python3-libdnf5 as + # auto_install_module_deps is true by default. + +- when: ansible_distribution in ['RedHat', 'Fedora'] + block: + - include_tasks: dnf.yml + - include_tasks: skip_broken_and_nobest.yml + - block: + - include_tasks: filters.yml + - include_tasks: filters_check_mode.yml + tags: + - filters + - include_tasks: gpg.yml + - include_tasks: repo.yml + - include_tasks: dnf_group_remove.yml + - include_tasks: dnfinstallroot.yml + - include_tasks: logging.yml + - include_tasks: cacheonly.yml + - include_tasks: multilib.yml + +# Attempting to install a different RHEL release in a tmpdir doesn't work (rhel8 beta) +- include_tasks: dnfreleasever.yml + when: ansible_distribution == 'Fedora' + +- when: + - ansible_distribution == 'RedHat' + - ansible_distribution_major_version | int == 9 + block: + # FUTURE - look at including AppStream support in our local repo + - name: list modules + command: dnf module list -q + register: module_list + + # A module that only has a single version + - name: Find a module that meets our testing needs + set_fact: + astream_name: '@{{ module.name }}:{{ module.version }}/{{ module.profile }}' + astream_name_no_stream: '@{{ module.name }}/{{ module.profile }}' + vars: + module: '{{ module_list.stdout|get_first_single_version_module }}' + + - include_tasks: modularity.yml + tags: + - dnf_modularity + rescue: + # Just in case something crazy happens when listing or parsing modules + - meta: noop diff --git a/test/integration/targets/dnf/tasks/multilib.yml b/test/integration/targets/dnf/tasks/multilib.yml index d251721d84d..71346e0ff7c 100644 --- a/test/integration/targets/dnf/tasks/multilib.yml +++ b/test/integration/targets/dnf/tasks/multilib.yml @@ -11,7 +11,7 @@ content: | x86_64 dest: /etc/dnf/vars/arch - when: dnf5|default(false) + when: dnf5 - block: - name: test that only evr is compared, avoiding a situation when a specific arch would be considered as a "newer" package diff --git a/test/integration/targets/dnf/tasks/skip_broken_and_nobest.yml b/test/integration/targets/dnf/tasks/skip_broken_and_nobest.yml index 0404e63aebe..69e14bd27e8 100644 --- a/test/integration/targets/dnf/tasks/skip_broken_and_nobest.yml +++ b/test/integration/targets/dnf/tasks/skip_broken_and_nobest.yml @@ -128,7 +128,7 @@ register: res - vars: - pkg_state: '{{ "Downgrade:" if dnf5|default(false) else "Installed:" }}' + pkg_state: '{{ "Downgrade:" if dnf5 else "Installed:" }}' assert: that: - res is changed @@ -181,7 +181,7 @@ register: res - vars: - pkg_state: '{{ "Downgrade:" if dnf5|default(false) else "Installed:" }}' + pkg_state: '{{ "Downgrade:" if dnf5 else "Installed:" }}' assert: that: - res is changed @@ -309,7 +309,7 @@ # skip_broken and skip_unavailable. # TODO: for this test to pass on dnf5 the skip_unavailable option would have to be # added to the dnf5 module and used here instead of skip_broken. - when: not dnf5|default(false) + when: not dnf5 always: - name: Remove all test packages installed diff --git a/test/integration/targets/dnf/vars/main.yml b/test/integration/targets/dnf/vars/main.yml deleted file mode 100644 index 86588de335d..00000000000 --- a/test/integration/targets/dnf/vars/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -dnf_log_files: - - /var/log/dnf.log - - /var/log/dnf.rpm.log - - /var/log/dnf.librepo.log diff --git a/test/integration/targets/dnf5/aliases b/test/integration/targets/dnf5/aliases deleted file mode 100644 index 4baf6e62c65..00000000000 --- a/test/integration/targets/dnf5/aliases +++ /dev/null @@ -1,6 +0,0 @@ -destructive -shippable/posix/group1 -skip/freebsd -skip/macos -context/target -needs/target/dnf diff --git a/test/integration/targets/dnf5/playbook.yml b/test/integration/targets/dnf5/playbook.yml deleted file mode 100644 index a36c17a2020..00000000000 --- a/test/integration/targets/dnf5/playbook.yml +++ /dev/null @@ -1,34 +0,0 @@ -- hosts: localhost - tasks: - - block: - - command: "dnf install -y 'dnf-command(copr)'" - - name: Test against dnf5 nightly build to detect any issues early - command: dnf copr enable -y rpmsoftwaremanagement/dnf-nightly - - - name: Ensure module deps are not installed - command: dnf remove -y python3-libdnf5 - - - name: Test the auto_install_module_deps option - dnf5: - name: sos - auto_install_module_deps: false - register: r - ignore_errors: true - - - assert: - that: - - r is failed - - r.msg is contains("Could not import the libdnf5 python module") - - # Now the first dnf5 task in the dnf role should auto install python3-libdnf5 as - # auto_install_module_deps is true by default. - - include_role: - name: dnf - vars: - dnf5: true - dnf_log_files: - - /var/log/dnf5.log - when: ansible_distribution == 'Fedora' - module_defaults: - dnf: - use_backend: dnf5 diff --git a/test/integration/targets/dnf5/runme.sh b/test/integration/targets/dnf5/runme.sh deleted file mode 100755 index 51a6bf45241..00000000000 --- a/test/integration/targets/dnf5/runme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -ux -export ANSIBLE_ROLES_PATH=../ -ansible-playbook playbook.yml "$@"