From 48937b3c5af8e3a752f22e08466b74b4cf2a873a Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 24 Apr 2024 13:16:09 -0600 Subject: [PATCH] ci: fix ci tests fix ci tests Signed-off-by: Rich Megginson --- pytest_extra_requirements.txt | 7 ++++++ tasks/enable-repositories/CentOS.yml | 13 +++++++++-- tasks/install-packages.yml | 26 ++++------------------ tasks/main.yml | 9 +++++--- tasks/set_vars.yml | 33 ++++++++++++++++++++++++++++ tests/library/find_unused_disk.py | 2 -- tests/module_utils/size.py | 5 +++-- vars/CentOS_8.yml | 5 +++++ vars/CentOS_9.yml | 5 +++++ 9 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 pytest_extra_requirements.txt create mode 100644 tasks/set_vars.yml create mode 100644 vars/CentOS_8.yml create mode 100644 vars/CentOS_9.yml diff --git a/pytest_extra_requirements.txt b/pytest_extra_requirements.txt new file mode 100644 index 0000000..0d79ed5 --- /dev/null +++ b/pytest_extra_requirements.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT + +# ansible and dependencies for all supported platforms +ansible ; python_version > "2.6" +ansible<2.7 ; python_version < "2.7" +idna<2.8 ; python_version < "2.7" +PyYAML<5.1 ; python_version < "2.7" diff --git a/tasks/enable-repositories/CentOS.yml b/tasks/enable-repositories/CentOS.yml index 77daf74..0eb578a 100644 --- a/tasks/enable-repositories/CentOS.yml +++ b/tasks/enable-repositories/CentOS.yml @@ -1,4 +1,13 @@ # SPDX-License-Identifier: MIT -# No enable-repositories tasks are needed for Fedora. This file serves as a -# placeholder and prevents RedHat.yml to be executed instead. --- +- name: List active CentOS repositories + command: dnf repolist + register: __gfs2_repolist + changed_when: false + check_mode: false + +- name: Enable CentOS repositories + command: dnf config-manager --set-enabled {{ item.id | quote }} + loop: "{{ __gfs2_repos }}" + when: item.id not in __gfs2_repolist.stdout + changed_when: item.name not in __gfs2_repolist.stdout diff --git a/tasks/install-packages.yml b/tasks/install-packages.yml index 7b0c7bd..dc0b4d7 100644 --- a/tasks/install-packages.yml +++ b/tasks/install-packages.yml @@ -1,27 +1,9 @@ # SPDX-License-Identifier: MIT --- -- name: Ensure ansible_facts used by role - setup: - gather_subset: "{{ __gfs2_required_facts_subsets }}" - when: __gfs2_required_facts | - difference(ansible_facts.keys() | list) | length > 0 - -- name: Determine if system is ostree and set flag - when: not __gfs2_is_ostree is defined - block: - - name: Check if system is ostree - stat: - path: /run/ostree-booted - register: __ostree_booted_stat - - - name: Set flag to indicate system is ostree - set_fact: - __gfs2_is_ostree: "{{ __ostree_booted_stat.stat.exists }}" - - name: Find environment-specific tasks to enable repositories ansible.builtin.set_fact: - __gfs2_enable_repo_tasks_file: \ - "{{ __gfs2_enable_repo_tasks_file_candidate }}" + __gfs2_enable_repo_tasks_file: >- + {{ __gfs2_enable_repo_tasks_file_candidate }} loop: - "{{ ansible_facts['os_family'] }}.yml" - "{{ ansible_facts['distribution'] }}.yml" @@ -32,8 +14,8 @@ {{ ansible_facts['distribution'] ~ '_' ~ ansible_facts['distribution_version'] }}.yml vars: - __gfs2_enable_repo_tasks_file_candidate: \ - "{{ role_path }}/tasks/enable-repositories/{{ item }}" + __gfs2_enable_repo_tasks_file_candidate: >- + {{ role_path }}/tasks/enable-repositories/{{ item }} when: - gfs2_enable_repos | bool - __gfs2_enable_repo_tasks_file_candidate is file diff --git a/tasks/main.yml b/tasks/main.yml index d2ca895..5fbad01 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,11 @@ # SPDX-License-Identifier: MIT --- +- name: Set platform/version specific variables + ansible.builtin.include_tasks: set_vars.yml + +- name: Install required packages + ansible.builtin.include_tasks: install-packages.yml + - name: Check for an active stonith resource ansible.builtin.command: argv: @@ -14,9 +20,6 @@ or "Started" not in stonith_status.stdout when: not _gfs2_test_allow_stonith_disabled -- name: Install required packages - ansible.builtin.include_tasks: install-packages.yml - - name: Setup cluster ansible.builtin.include_tasks: setup-cluster.yml when: gfs2_file_systems | length > 0 diff --git a/tasks/set_vars.yml b/tasks/set_vars.yml new file mode 100644 index 0000000..e361421 --- /dev/null +++ b/tasks/set_vars.yml @@ -0,0 +1,33 @@ +--- +- name: Ensure ansible_facts used by role + ansible.builtin.setup: + gather_subset: "{{ __gfs2_required_facts_subsets }}" + when: __gfs2_required_facts | + difference(ansible_facts.keys() | list) | length > 0 + +- name: Determine if system is ostree and set flag + when: not __gfs2_is_ostree is defined + block: + - name: Check if system is ostree + ansible.builtin.stat: + path: /run/ostree-booted + register: __ostree_booted_stat + + - name: Set flag to indicate system is ostree + ansible.builtin.set_fact: + __gfs2_is_ostree: "{{ __ostree_booted_stat.stat.exists }}" + +- name: Set platform/version specific variables + ansible.builtin.include_vars: "{{ __vars_file }}" + loop: + - "{{ ansible_facts['os_family'] }}.yml" + - "{{ ansible_facts['distribution'] }}.yml" + - >- + {{ ansible_facts['distribution'] ~ '_' ~ + ansible_facts['distribution_major_version'] }}.yml + - >- + {{ ansible_facts['distribution'] ~ '_' ~ + ansible_facts['distribution_version'] }}.yml + vars: + __vars_file: "{{ role_path }}/vars/{{ item }}" + when: __vars_file is file diff --git a/tests/library/find_unused_disk.py b/tests/library/find_unused_disk.py index 7583367..1f24d51 100644 --- a/tests/library/find_unused_disk.py +++ b/tests/library/find_unused_disk.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - from __future__ import absolute_import, division, print_function __metaclass__ = type diff --git a/tests/module_utils/size.py b/tests/module_utils/size.py index 6b7f379..9d5f5fa 100644 --- a/tests/module_utils/size.py +++ b/tests/module_utils/size.py @@ -161,6 +161,7 @@ def get(self, units="autobin", fmt="%0.1f %sb"): exp += 1 else: ftr, exp = self._parse_units(units.strip()) - value = (float(self.factor**self.exponent) / float(ftr**exp)) * self.number - + value = ( + float(self.factor**self.exponent) / float(ftr**exp) + ) * self.number return self._format(fmt, ftr, exp) % value diff --git a/vars/CentOS_8.yml b/vars/CentOS_8.yml new file mode 100644 index 0000000..a7e9ed1 --- /dev/null +++ b/vars/CentOS_8.yml @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +--- +__gfs2_repos: + - id: resilientstorage + name: ResilientStorage diff --git a/vars/CentOS_9.yml b/vars/CentOS_9.yml new file mode 100644 index 0000000..a7e9ed1 --- /dev/null +++ b/vars/CentOS_9.yml @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: MIT +--- +__gfs2_repos: + - id: resilientstorage + name: ResilientStorage