diff --git a/.ansible-lint b/.ansible-lint index 2c7c8df0..bf155a59 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -24,3 +24,5 @@ exclude_paths: - examples/roles/ mock_roles: - linux-system-roles.timesync +mock_modules: + - ansible.utils.update_fact diff --git a/.ostree/README.md b/.ostree/README.md new file mode 100644 index 00000000..f5e6931b --- /dev/null +++ b/.ostree/README.md @@ -0,0 +1,3 @@ +*NOTE*: The `*.txt` files are used by `get_ostree_data.sh` to create the lists +of packages, and to find other system roles used by this role. DO NOT use them +directly. diff --git a/.ostree/get_ostree_data.sh b/.ostree/get_ostree_data.sh new file mode 100755 index 00000000..7c325241 --- /dev/null +++ b/.ostree/get_ostree_data.sh @@ -0,0 +1,123 @@ +#!/bin/bash + +set -euo pipefail + +role_collection_dir="${ROLE_COLLECTION_DIR:-fedora/linux_system_roles}" +ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}" + +if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then + cat < 0 +- name: Ensure correct package manager for ostree systems + vars: + ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree + ostree_booted_file: /run/ostree-booted + when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + block: + - name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + + - name: Set package manager to use for ostree + ansible.utils.update_fact: + updates: + - path: ansible_facts.pkg_mgr + value: "{{ ostree_pkg_mgr }}" + when: __ostree_booted_stat.stat.exists + - name: Set platform/version specific variables include_vars: "{{ lookup('first_found', ffparams) }}" vars: diff --git a/tests/tasks/setup.yml b/tests/tasks/setup.yml new file mode 100644 index 00000000..223cc364 --- /dev/null +++ b/tests/tasks/setup.yml @@ -0,0 +1,48 @@ +--- +# common test setup tasks +- name: Ensure correct package manager for ostree systems + vars: + ostree_pkg_mgr: ansible.posix.rhel_rpm_ostree + ostree_booted_file: /run/ostree-booted + when: ansible_facts.pkg_mgr | d("") != ostree_pkg_mgr + block: + - name: Check if system is ostree + stat: + path: "{{ ostree_booted_file }}" + register: __ostree_booted_stat + + - name: Set package manager to use for ostree + ansible.utils.update_fact: + updates: + - path: ansible_facts.pkg_mgr + value: "{{ ostree_pkg_mgr }}" + when: __ostree_booted_stat.stat.exists + +- name: Ensure iproute for gathering default_ipv4 fact + package: + name: iproute # for fact gathering for ip facts + state: present + +- name: Ensure ansible_facts used by test + setup: + gather_subset: "{{ __required_facts_subsets }}" + when: __required_facts | + difference(ansible_facts.keys() | list) | length > 0 + vars: + __required_facts: + - default_ipv4 + - distribution + - distribution_major_version + - distribution_version + - os_family + __required_facts_subsets: "{{ ['!all', '!min'] + __required_facts }}" + +- name: Debug + debug: + msg: facts {{ ansible_facts | to_nice_json }} + +- name: Skip test on ostree systems if unsupported + meta: end_host + when: + - __timesync_ostree_unsupported | d(false) + - ansible_facts.pkg_mgr | d() == "ansible.posix.rhel_rpm_ostree" diff --git a/tests/tests_ntp_provider1.yml b/tests/tests_ntp_provider1.yml index 4800bf7e..1c6bb08b 100644 --- a/tests/tests_ntp_provider1.yml +++ b/tests/tests_ntp_provider1.yml @@ -8,6 +8,11 @@ - linux-system-roles.timesync pre_tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: Remove provider packages check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_provider2.yml b/tests/tests_ntp_provider2.yml index f81204c1..36b3f01d 100644 --- a/tests/tests_ntp_provider2.yml +++ b/tests/tests_ntp_provider2.yml @@ -8,6 +8,11 @@ - linux-system-roles.timesync pre_tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: Remove the install ntp check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_provider3.yml b/tests/tests_ntp_provider3.yml index eaacfb28..3a5f6e77 100644 --- a/tests/tests_ntp_provider3.yml +++ b/tests/tests_ntp_provider3.yml @@ -8,6 +8,11 @@ - linux-system-roles.timesync pre_tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: Remove then install chrony check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_provider4.yml b/tests/tests_ntp_provider4.yml index 01676cbf..08671aa3 100644 --- a/tests/tests_ntp_provider4.yml +++ b/tests/tests_ntp_provider4.yml @@ -9,6 +9,11 @@ - linux-system-roles.timesync pre_tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: Install then remove chrony check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_provider5.yml b/tests/tests_ntp_provider5.yml index 9f141cf7..581292e0 100644 --- a/tests/tests_ntp_provider5.yml +++ b/tests/tests_ntp_provider5.yml @@ -9,6 +9,11 @@ - linux-system-roles.timesync pre_tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: Install then remove ntp check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_provider6.yml b/tests/tests_ntp_provider6.yml index 77afcd88..6fb42a1b 100644 --- a/tests/tests_ntp_provider6.yml +++ b/tests/tests_ntp_provider6.yml @@ -10,6 +10,11 @@ both_avail: true tasks: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + vars: + __timesync_ostree_unsupported: true + - name: See if both providers are available check_mode: false tags: tests::setup diff --git a/tests/tests_ntp_ptp.yml b/tests/tests_ntp_ptp.yml index 583d95a4..e62723cb 100644 --- a/tests/tests_ntp_ptp.yml +++ b/tests/tests_ntp_ptp.yml @@ -20,13 +20,17 @@ timesync_step_threshold: 0.001 timesync_dhcp_ntp_servers: false timesync_min_sources: 2 - roles: - - linux-system-roles.timesync - tasks: - name: Run test tags: tests::verify block: + - name: Common test setup tasks + include_tasks: tasks/setup.yml + + - name: Run role + include_role: + name: linux-system-roles.timesync + - name: Flush handlers meta: flush_handlers diff --git a/tests/tests_ptp_multi.yml b/tests/tests_ptp_multi.yml index 56ed06d9..c118a73a 100644 --- a/tests/tests_ptp_multi.yml +++ b/tests/tests_ptp_multi.yml @@ -25,6 +25,9 @@ - name: Flush handlers meta: flush_handlers + - name: Common test setup tasks + include_tasks: tasks/setup.yml + - name: Ensure ethtool is installed package: name: ethtool diff --git a/tests/tests_ptp_single.yml b/tests/tests_ptp_single.yml index 6dd461e4..8e44003d 100644 --- a/tests/tests_ptp_single.yml +++ b/tests/tests_ptp_single.yml @@ -16,6 +16,9 @@ - name: Flush handlers meta: flush_handlers + - name: Common test setup tasks + include_tasks: tasks/setup.yml + - name: Ensure ethtool is installed package: name: ethtool