From 3761e11a5cb0c49bb66912a072773c4b34e3b60c Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 2 May 2024 12:59:50 -0500 Subject: [PATCH] [stable-2.16] Don't hardcode the dnf module, dynamically select one (#83183). (#83185) (cherry picked from commit dc6b77beca27535f790f0d6e392948ca9a6d62fa) --- .../dnf/filter_plugins/dnf_module_list.py | 40 +++++++++++++++++++ test/integration/targets/dnf/tasks/main.yml | 25 ++++++++++-- .../targets/dnf/tasks/modularity.yml | 9 ----- test/integration/targets/dnf/vars/CentOS.yml | 2 - test/integration/targets/dnf/vars/Fedora.yml | 6 --- .../integration/targets/dnf/vars/RedHat-9.yml | 2 - test/integration/targets/dnf/vars/RedHat.yml | 2 - 7 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 test/integration/targets/dnf/filter_plugins/dnf_module_list.py delete mode 100644 test/integration/targets/dnf/vars/CentOS.yml delete mode 100644 test/integration/targets/dnf/vars/Fedora.yml delete mode 100644 test/integration/targets/dnf/vars/RedHat-9.yml delete mode 100644 test/integration/targets/dnf/vars/RedHat.yml diff --git a/test/integration/targets/dnf/filter_plugins/dnf_module_list.py b/test/integration/targets/dnf/filter_plugins/dnf_module_list.py new file mode 100644 index 00000000000..3ef9874da32 --- /dev/null +++ b/test/integration/targets/dnf/filter_plugins/dnf_module_list.py @@ -0,0 +1,40 @@ +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import annotations + +from collections import Counter + + +def parse_module_list(stdout): + lines = stdout.splitlines() + name_offset = 0 + empty_offset = -1 + modules = [] + for i, line in enumerate(lines): + if line.startswith('Name '): + name_offset = i + 1 + if not line.strip(): + empty_offset = i + for line in lines[name_offset:empty_offset]: + cols = line.split()[:3] + modules.append({ + 'name': cols[0], + 'version': cols[1], + 'profile': cols[2].rstrip(','), # Just the first profile + }) + return modules + + +def get_first_single_version_module(stdout): + modules = parse_module_list(stdout) + name = Counter([m['name'] for m in modules]).most_common()[-1][0] + module, = [m for m in modules if m['name'] == name] + return module + + +class FilterModule: + def filters(self): + return { + 'get_first_single_version_module': get_first_single_version_module, + } diff --git a/test/integration/targets/dnf/tasks/main.yml b/test/integration/targets/dnf/tasks/main.yml index 4941e2c3bd5..d56859fa6f0 100644 --- a/test/integration/targets/dnf/tasks/main.yml +++ b/test/integration/targets/dnf/tasks/main.yml @@ -57,13 +57,30 @@ - ansible_distribution == 'Fedora' - ansible_distribution_major_version is version('23', '>=') -- include_tasks: modularity.yml - when: +- when: - (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('29', '>=')) or (ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>=')) - not dnf5|default(false) - tags: - - dnf_modularity + 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 - include_tasks: logging.yml when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('31', '>=')) or diff --git a/test/integration/targets/dnf/tasks/modularity.yml b/test/integration/targets/dnf/tasks/modularity.yml index 94f43a40754..6a97bf6fe6f 100644 --- a/test/integration/targets/dnf/tasks/modularity.yml +++ b/test/integration/targets/dnf/tasks/modularity.yml @@ -1,12 +1,3 @@ -# FUTURE - look at including AppStream support in our local repo -- name: Include distribution specific variables - include_vars: "{{ item }}" - with_first_found: - - files: - - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml" - - "{{ ansible_facts.distribution }}.yml" - paths: ../vars - - name: install "{{ astream_name }}" module dnf: name: "{{ astream_name }}" diff --git a/test/integration/targets/dnf/vars/CentOS.yml b/test/integration/targets/dnf/vars/CentOS.yml deleted file mode 100644 index c70d8538d81..00000000000 --- a/test/integration/targets/dnf/vars/CentOS.yml +++ /dev/null @@ -1,2 +0,0 @@ -astream_name: '@php:7.2/minimal' -astream_name_no_stream: '@php/minimal' diff --git a/test/integration/targets/dnf/vars/Fedora.yml b/test/integration/targets/dnf/vars/Fedora.yml deleted file mode 100644 index fff6f4b7cba..00000000000 --- a/test/integration/targets/dnf/vars/Fedora.yml +++ /dev/null @@ -1,6 +0,0 @@ -astream_name: '@varnish:6.0/default' - -# For this to work, it needs to be that only shows once in `dnf module list`. -# Such packages, that exist on all the versions we test on, are hard to come by. -# TODO: This would be solved by using our own repo with modularity/streams. -astream_name_no_stream: '@varnish/default' diff --git a/test/integration/targets/dnf/vars/RedHat-9.yml b/test/integration/targets/dnf/vars/RedHat-9.yml deleted file mode 100644 index 680157dcd62..00000000000 --- a/test/integration/targets/dnf/vars/RedHat-9.yml +++ /dev/null @@ -1,2 +0,0 @@ -astream_name: '@php:8.1/minimal' -astream_name_no_stream: '@php/minimal' diff --git a/test/integration/targets/dnf/vars/RedHat.yml b/test/integration/targets/dnf/vars/RedHat.yml deleted file mode 100644 index c70d8538d81..00000000000 --- a/test/integration/targets/dnf/vars/RedHat.yml +++ /dev/null @@ -1,2 +0,0 @@ -astream_name: '@php:7.2/minimal' -astream_name_no_stream: '@php/minimal'