From 4ad01c25849ef2cb394ed8129df86f4b8a1673e0 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Jun 05 2017 20:24:53 +0000 Subject: Add test selector role --- diff --git a/roles/standard-test-selector/README.md b/roles/standard-test-selector/README.md new file mode 100644 index 0000000..06b9b2e --- /dev/null +++ b/roles/standard-test-selector/README.md @@ -0,0 +1,38 @@ +# Ansible role for selecting tests to be run + +Put this role in your test_local.yml playbook. + +You'll need to have the following input variables defined: + +* tests_docker: A list of tests to run only in a docker container (optional) +* tests_not_docker: A list of tests to run only when NOT in a docker container (optional) +* tests_all: A list of tests to always run (optional) + +When the role is completed, the following variable will be set: + +* selected_tests: The list of selected tests + +Run another role in your playbook after this role to run the list of selected tests. For example, standard-test-rhts. + +```yaml +--- +# This first play always runs on the local staging system +- hosts: localhost + + roles: + - role: standard-test-selector + tests_docker: + - dockertest1 + - dockertest2 + tests_not_docker: + - nondockertest1 + - nondockertest2 + tests_all: + - alltest1 + - alltest2 + + - role: standard-test-rhts + tests: "{{ selected_tests }}" + required_packages: + - package1 # alltest1 needs foo command +``` diff --git a/roles/standard-test-selector/defaults/main.yml b/roles/standard-test-selector/defaults/main.yml new file mode 100644 index 0000000..31b2334 --- /dev/null +++ b/roles/standard-test-selector/defaults/main.yml @@ -0,0 +1,5 @@ +--- +tests_docker: [] # input: tests to run only in docker container +tests_not_docker: [] # input: tests to run only when not in docker +tests_all: [] # input: tests to always run +selected_tests: [] # output: list of selected tests diff --git a/roles/standard-test-selector/tasks/main.yml b/roles/standard-test-selector/tasks/main.yml new file mode 100644 index 0000000..88687c9 --- /dev/null +++ b/roles/standard-test-selector/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: Set initial list of tests to run in all environments + set_fact: + selected_tests: "{{ tests_all }}" + +- name: Check if running in docker container + shell: grep -q /docker /proc/self/cgroup + register: docker_check_result + ignore_errors: True + +- name: Add tests to run only when in docker container + set_fact: + selected_tests: "{{ selected_tests }} + {{ tests_docker }}" + when: docker_check_result|succeeded + +- name: Add tests to run when not in docker container + set_fact: + selected_tests: "{{ selected_tests }} + {{ tests_not_docker }}" + when: docker_check_result|failed