From c76a01f456e59ece26f8c1bdb77aa97e9d9213ef Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Sep 13 2017 13:43:47 +0000 Subject: Add bits needed to support own spec. Signed-off-by: Chris Evich --- diff --git a/tests/inventory b/tests/inventory new file mode 120000 index 0000000..e09e1ad --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +../inventory \ No newline at end of file diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..193b15b --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,3 @@ +--- + +- include: unittests.yml diff --git a/tests/unittests.yml b/tests/unittests.yml new file mode 100644 index 0000000..11afbb0 --- /dev/null +++ b/tests/unittests.yml @@ -0,0 +1,78 @@ +--- + +- hosts: all + gather_subset: network + vars: + - artifacts: '{{ artifacts | default(lookup("env", "TEST_ARTIFACTS") | default("./artifacts", True)) }}' + - test_source: "{{ playbook_dir }}" # FIXME: See below fixmes + - repo_source: "{{ playbook_dir }}/../.." # FIXME: See below fixmes + - unittest_args: "--verbose --locals" + + tags: + - classic + + pre_tasks: + + - Name: Dependencies for ansible modules are installed + raw: "$(type -P dnf || type -P yum ) dnf install -y python3 python-simplejson libselinux-python" + + tasks: + + - name: Make artifacts directory + file: + path: "{{ artifacts }}" + state: directory + mode: 755 + recurse: yes + + - name: A temporary directory exists for a copy of the source + command: mktemp -d + register: tempdir + + - name: Test block + block: + + # FIXME: This should consume a '*.rpm' or '*.repo' $TEST_SUBJECT and install it + - name: The source is transfered to temporary directory + synchronize: + src: "{{ repo_source }}" + dest: "{{ tempdir.stdout | trim }}" + + - name: List of unittest files to execute is buffered + find: + paths: + - "{{ tempdir.stdout | trim }}/tests" # FIXME: See above fixme + - "{{ /usr/share }}" + patterns: + # FIXME: unittest scripts expect '../inventory/standard-inventory-*' + - "test_*.py" + - "ansible/standard-test-roles-tests/test_*.py" + register: unittests + + - name: Unittests executed from buffered list + shell: '"{{ item }}" {{ unittest_args }} &> "{{ artifacts }}/{{ item | basename }}.output.txt"' + args: + chdir: "{{ artifacts }}" + creates: "{{ artifacts }}/{{ item | basename }}.output.txt" + ignore_errors: True + register: result + with_items: '{{ unittests.files }}' + + - name: Execution result is recorded + copy: + dest: "{{ artifacts }}/test.log" + # Workaround yaml-conversion bug (if present) + contents: "result | to_json | from_json | to_nice_yaml }}" + + always: + + - name: Cleanup temporary directory + file: + path: "{{ tempdir.stdout | trim }}" + state: absent + ignore_errors: True + + - name: Pull out the artifacts + fetch: + dest: "{{ artifacts }}/" + src: "{{ artifacts }}/"