From d749fd62e7ecd81dca028035ff37d69846baac87 Mon Sep 17 00:00:00 2001 From: Ella Shulman Date: Tue, 24 Sep 2024 05:58:00 -0400 Subject: [PATCH] Allow setting order and hooks for test role - Allow passing hook list directly to hook role - Allow setting up stages and hooks for test operator role Jira: https://issues.redhat.com/browse/OSPRH-10106 --- roles/run_hook/tasks/main.yml | 3 +- roles/test_operator/defaults/main.yml | 22 ++++++++ roles/test_operator/tasks/main.yml | 50 ++----------------- .../tasks/runners/ansibletest_runner.yml | 9 ++++ .../tasks/runners/horizontest_runner.yml | 9 ++++ .../tasks/runners/tempest_runner.yml | 10 ++++ .../tasks/runners/tobiko_runner.yml | 11 ++++ roles/test_operator/tasks/stages.yml | 29 +++++++++++ 8 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 roles/test_operator/tasks/runners/ansibletest_runner.yml create mode 100644 roles/test_operator/tasks/runners/horizontest_runner.yml create mode 100644 roles/test_operator/tasks/runners/tempest_runner.yml create mode 100644 roles/test_operator/tasks/runners/tobiko_runner.yml create mode 100644 roles/test_operator/tasks/stages.yml diff --git a/roles/run_hook/tasks/main.yml b/roles/run_hook/tasks/main.yml index bd39f87e53..00cdd3c1cd 100644 --- a/roles/run_hook/tasks/main.yml +++ b/roles/run_hook/tasks/main.yml @@ -18,7 +18,8 @@ vars: _list_hooks: >- {{ - hostvars[inventory_hostname][step] | + hostvars[inventory_hostname][step] is defined | + ternary(hostvars[inventory_hostname][step], hook_list) | default([]) }} _matcher: "^{{ step }}_(.*)$" diff --git a/roles/test_operator/defaults/main.yml b/roles/test_operator/defaults/main.yml index da88f8ab44..9e541b41bb 100644 --- a/roles/test_operator/defaults/main.yml +++ b/roles/test_operator/defaults/main.yml @@ -19,6 +19,28 @@ # All variables within this role should have a prefix of "cifmw_test_operator" # Section 1: generic parameters (applied to all supported test frameworks) +cifmw_test_operator_stages: + - name: tempest + type: tempest + test_file: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/ansible-vars" + # pre_stage_hooks: + # post_stage_hooks: + - name: ansibletest + type: ansibletest + test_file: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/ansible-vars" + # pre_stage_hooks: + # post_stage_hooks: + - name: horizontest + type: horizontest + test_file: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/ansible-vars" + # pre_stage_hooks: + # post_stage_hooks: + - name: tobiko + type: tobiko + test_file: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/ansible-vars" + # pre_stage_hooks: + # post_stage_hooks: + cifmw_test_operator_fail_on_test_failure: true cifmw_test_operator_artifacts_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/tests/test_operator" cifmw_test_operator_namespace: openstack diff --git a/roles/test_operator/tasks/main.yml b/roles/test_operator/tasks/main.yml index b745d7da2c..fb3f332898 100644 --- a/roles/test_operator/tasks/main.yml +++ b/roles/test_operator/tasks/main.yml @@ -132,52 +132,12 @@ until: csv.resources[0].status.phase | default(omit) == "Succeeded" when: not cifmw_test_operator_dry_run | bool -- name: Run tempest job +- name: Call test stages loop vars: - run_test_fw: tempest - test_operator_config: "{{ cifmw_test_operator_tempest_config }}" - test_operator_job_name: "{{ cifmw_test_operator_tempest_name }}" - test_operator_kind_name: "{{ cifmw_test_operator_tempest_kind_name }}" - test_operator_crd_name: "{{ cifmw_test_operator_tempest_crd_name }}" - test_operator_workflow: "{{ cifmw_test_operator_tempest_workflow }}" - test_operator_config_playbook: tempest-tests.yml - ansible.builtin.include_tasks: run-test-operator-job.yml - when: run_tempest - -- name: Run ansibletest job - vars: - run_test_fw: ansibletest - test_operator_config: "{{ cifmw_test_operator_ansibletest_config }}" - test_operator_job_name: "{{ cifmw_test_operator_ansibletest_name }}" - test_operator_kind_name: "{{ cifmw_test_operator_ansibletest_kind_name }}" - test_operator_crd_name: "{{ cifmw_test_operator_ansibletest_crd_name }}" - test_operator_workflow: "{{ cifmw_test_operator_ansibletest_workflow }}" - ansible.builtin.include_tasks: run-test-operator-job.yml - when: run_ansibletest - -- name: Run horizontest job - vars: - run_test_fw: horizontest - test_operator_config: "{{ cifmw_test_operator_horizontest_config }}" - test_operator_job_name: "{{ cifmw_test_operator_horizontest_name }}" - test_operator_kind_name: "{{ cifmw_test_operator_horizontest_kind_name }}" - test_operator_crd_name: "{{ cifmw_test_operator_horizontest_crd_name }}" - test_operator_workflow: [] - ansible.builtin.include_tasks: run-test-operator-job.yml - when: run_horizontest - -# Since Tobiko may include disruptive tests (faults), it is better to execute it at the end -- name: Run tobiko job - vars: - run_test_fw: tobiko - test_operator_config: "{{ cifmw_test_operator_tobiko_config }}" - test_operator_job_name: "{{ cifmw_test_operator_tobiko_name }}" - test_operator_kind_name: "{{ cifmw_test_operator_tobiko_kind_name }}" - test_operator_crd_name: "{{ cifmw_test_operator_tobiko_crd_name }}" - test_operator_workflow: "{{ cifmw_test_operator_tobiko_workflow }}" - test_operator_config_playbook: tobiko-tests.yml - ansible.builtin.include_tasks: run-test-operator-job.yml - when: run_tobiko + stage_vars: "{{ item }}" + ansible.builtin.include_tasks: stages.yml + when: not cifmw_test_operator_dry_run | bool + loop: "{{ cifmw_test_operator_stages }}" - name: Delete all resources created by the role ansible.builtin.include_tasks: cleanup.yml diff --git a/roles/test_operator/tasks/runners/ansibletest_runner.yml b/roles/test_operator/tasks/runners/ansibletest_runner.yml new file mode 100644 index 0000000000..719385b834 --- /dev/null +++ b/roles/test_operator/tasks/runners/ansibletest_runner.yml @@ -0,0 +1,9 @@ +- name: Run ansibletest job + vars: + run_test_fw: ansibletest + test_operator_config: "{{ cifmw_test_operator_ansibletest_config }}" + test_operator_job_name: "{{ cifmw_test_operator_ansibletest_name }}" + test_operator_kind_name: "{{ cifmw_test_operator_ansibletest_kind_name }}" + test_operator_crd_name: "{{ cifmw_test_operator_ansibletest_crd_name }}" + test_operator_workflow: "{{ cifmw_test_operator_ansibletest_workflow }}" + ansible.builtin.include_tasks: run-test-operator-job.yml diff --git a/roles/test_operator/tasks/runners/horizontest_runner.yml b/roles/test_operator/tasks/runners/horizontest_runner.yml new file mode 100644 index 0000000000..76f6234e93 --- /dev/null +++ b/roles/test_operator/tasks/runners/horizontest_runner.yml @@ -0,0 +1,9 @@ +- name: Run horizontest job + vars: + run_test_fw: horizontest + test_operator_config: "{{ cifmw_test_operator_horizontest_config }}" + test_operator_job_name: "{{ cifmw_test_operator_horizontest_name }}" + test_operator_kind_name: "{{ cifmw_test_operator_horizontest_kind_name }}" + test_operator_crd_name: "{{ cifmw_test_operator_horizontest_crd_name }}" + test_operator_workflow: [] + ansible.builtin.include_tasks: run-test-operator-job.yml diff --git a/roles/test_operator/tasks/runners/tempest_runner.yml b/roles/test_operator/tasks/runners/tempest_runner.yml new file mode 100644 index 0000000000..a819c7c9e9 --- /dev/null +++ b/roles/test_operator/tasks/runners/tempest_runner.yml @@ -0,0 +1,10 @@ +- name: Run tempest job + vars: + run_test_fw: tempest + test_operator_config: "{{ cifmw_test_operator_tempest_config }}" + test_operator_job_name: "{{ cifmw_test_operator_tempest_name }}" + test_operator_kind_name: "{{ cifmw_test_operator_tempest_kind_name }}" + test_operator_crd_name: "{{ cifmw_test_operator_tempest_crd_name }}" + test_operator_workflow: "{{ cifmw_test_operator_tempest_workflow }}" + test_operator_config_playbook: tempest-tests.yml + ansible.builtin.include_tasks: run-test-operator-job.yml diff --git a/roles/test_operator/tasks/runners/tobiko_runner.yml b/roles/test_operator/tasks/runners/tobiko_runner.yml new file mode 100644 index 0000000000..185c6a79f2 --- /dev/null +++ b/roles/test_operator/tasks/runners/tobiko_runner.yml @@ -0,0 +1,11 @@ +# Since Tobiko may include disruptive tests (faults), it is better to execute it at the end +- name: Run tobiko job + vars: + run_test_fw: tobiko + test_operator_config: "{{ cifmw_test_operator_tobiko_config }}" + test_operator_job_name: "{{ cifmw_test_operator_tobiko_name }}" + test_operator_kind_name: "{{ cifmw_test_operator_tobiko_kind_name }}" + test_operator_crd_name: "{{ cifmw_test_operator_tobiko_crd_name }}" + test_operator_workflow: "{{ cifmw_test_operator_tobiko_workflow }}" + test_operator_config_playbook: tobiko-tests.yml + ansible.builtin.include_tasks: run-test-operator-job.yml diff --git a/roles/test_operator/tasks/stages.yml b/roles/test_operator/tasks/stages.yml new file mode 100644 index 0000000000..7efe2e8261 --- /dev/null +++ b/roles/test_operator/tasks/stages.yml @@ -0,0 +1,29 @@ + +- debug: + msg: "Run stage {{ stage_vars.name }}" + +- name: "Call pre stage hooks for test operator stage {{ stage_vars.name }}" + vars: + step: none + hook_list: "{{ stage_vars.pre_stage_hooks }}" + ansible.builtin.import_role: + name: run_hook + when: + - not cifmw_test_operator_dry_run | bool + - stage_vars.pre_stage_hooks is defined + +- name: Include stage var file + ansible.builtin.include_vars: + file: "{{ stage_vars.test_file }}" + +- name: "Call {{ stage_vars.type }} runner" + ansible.builtin.include_tasks: "runners/{{ stage_vars.type }}_runner.yml" + +- name: "Call post stage hooks for test operator stage {{ stage_vars.name }}" + vars: + step: stage_vars.post_stage_hooks + ansible.builtin.import_role: + name: run_hook + when: + - not cifmw_test_operator_dry_run | bool + - stage_vars.post_stage_hooks is defined