From 28f3e0b8f6f5949c361ef85a4f0cc3bd7577e5c7 Mon Sep 17 00:00:00 2001 From: Sergei Petrosian Date: Fri, 12 Apr 2024 11:24:44 +0200 Subject: [PATCH] fix: Fail on the s390x architecture with a not supported msg --- tasks/main.yml | 7 +++++++ tests/tasks/assert_fail_on_s390x.yml | 10 ++++++++++ tests/tests_add_rm.yml | 4 ++++ tests/tests_default.yml | 11 +++++++++-- tests/tests_include_vars_from_parent.yml | 3 +++ tests/tests_password.yml | 4 ++++ tests/tests_settings.yml | 4 ++++ vars/main.yml | 1 + 8 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/tasks/assert_fail_on_s390x.yml diff --git a/tasks/main.yml b/tasks/main.yml index f055f75..3875f38 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,6 +3,13 @@ - name: Set platform/version specific variables include_tasks: tasks/set_vars.yml +- name: Fail on s390x architecture + fail: + msg: >- + This role does not support s390x architecture. + Let us know if you need the role to support it. + when: ansible_architecture == 's390x' + - name: Ensure required packages are installed package: name: "{{ __bootloader_packages }}" diff --git a/tests/tasks/assert_fail_on_s390x.yml b/tests/tasks/assert_fail_on_s390x.yml new file mode 100644 index 0000000..c49fb96 --- /dev/null +++ b/tests/tasks/assert_fail_on_s390x.yml @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT +--- +- name: Assert failure on the s390x architecture + when: ansible_architecture == 's390x' + assert: + that: __str in ansible_failed_result.msg + vars: + __str: This role does not support s390x architecture. + register: __bootloader_s390x_err + diff --git a/tests/tests_add_rm.yml b/tests/tests_add_rm.yml index 7ef44e1..69de34b 100644 --- a/tests/tests_add_rm.yml +++ b/tests/tests_add_rm.yml @@ -96,6 +96,9 @@ that: bootloader_facts | selectattr('title', 'defined') | selectattr('title', 'search', 'Clone2') | list | length == 0 + rescue: + - name: Assert failure on s390x architecture + include_tasks: tasks/assert_fail_on_s390x.yml always: - name: Remove cloned kernels command: >- @@ -105,3 +108,4 @@ - 2 changed_when: true failed_when: false + when: __bootloader_s390x_err is skipped diff --git a/tests/tests_default.yml b/tests/tests_default.yml index 912c44c..52570e2 100644 --- a/tests/tests_default.yml +++ b/tests/tests_default.yml @@ -3,5 +3,12 @@ - name: Ensure that the role runs with default parameters hosts: all gather_facts: false # for testing the role fact gathering - roles: - - linux-system-roles.bootloader + tasks: + - name: Run in a block to clean up afterwards + block: + - name: Run with default parameters + include_role: + name: linux-system-roles.bootloader + rescue: + - name: Assert failure on s390x architecture + include_tasks: tasks/assert_fail_on_s390x.yml diff --git a/tests/tests_include_vars_from_parent.yml b/tests/tests_include_vars_from_parent.yml index 03d55f3..c85d521 100644 --- a/tests/tests_include_vars_from_parent.yml +++ b/tests/tests_include_vars_from_parent.yml @@ -49,6 +49,9 @@ name: caller vars: roletoinclude: linux-system-roles.bootloader + rescue: + - name: Assert failure on s390x architecture + include_tasks: tasks/assert_fail_on_s390x.yml always: - name: Cleanup file: diff --git a/tests/tests_password.yml b/tests/tests_password.yml index 9310006..0d7fe7c 100644 --- a/tests/tests_password.yml +++ b/tests/tests_password.yml @@ -34,9 +34,13 @@ - name: Verify that user conf doesn't exist assert: that: not __bootloader_user_conf_stat.stat.exists + rescue: + - name: Assert failure on s390x architecture + include_tasks: tasks/assert_fail_on_s390x.yml always: - name: Remove boot loader password vars: bootloader_remove_password: true include_role: name: linux-system-roles.bootloader + when: __bootloader_s390x_err is skipped diff --git a/tests/tests_settings.yml b/tests/tests_settings.yml index f037a1a..c05afad 100644 --- a/tests/tests_settings.yml +++ b/tests/tests_settings.yml @@ -170,9 +170,13 @@ regex('set timeout=4') register: __bootloader_default_grub_content changed_when: false + rescue: + - name: Assert failure on s390x architecture + include_tasks: tasks/assert_fail_on_s390x.yml always: - name: Remove cloned kernels command: >- grubby --remove-kernel={{ test_kernel.kernel }}_clone1 changed_when: true failed_when: false + when: __bootloader_s390x_err is skipped diff --git a/vars/main.yml b/vars/main.yml index 9e04ec7..5d8ff68 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,6 +2,7 @@ --- # ansible_facts required by the role __bootloader_required_facts: + - architecture - distribution - distribution_major_version - distribution_version