From a07bbee70c3880c4882fd26a848f9726eafcecdc Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Thu, 12 Sep 2019 18:46:42 +0000 Subject: [PATCH] fetch-subunit-output: introduce zuul_use_fetch_output This change enables using fetch-subunit-output role along with the fetch-output role. By default the role still synchronizes artifacts back to the executor. Change-Id: I50a50856b96a9112c1b4be82ca04b612fd29d939 --- roles/fetch-subunit-output/README.rst | 8 +++ roles/fetch-subunit-output/defaults/main.yaml | 2 + roles/fetch-subunit-output/tasks/process.yaml | 9 +++ .../python/fetch-subunit-output.yaml | 68 +++++++++++++++++++ zuul-tests.d/python-jobs.yaml | 22 ++++++ 5 files changed, 109 insertions(+) create mode 100644 test-playbooks/python/fetch-subunit-output.yaml diff --git a/roles/fetch-subunit-output/README.rst b/roles/fetch-subunit-output/README.rst index a959f119e..61add6f53 100644 --- a/roles/fetch-subunit-output/README.rst +++ b/roles/fetch-subunit-output/README.rst @@ -17,3 +17,11 @@ Collect subunit outputs .. zuul:rolevar:: tox_envlist tox environment that was used to run the tests originally. + +.. zuul:rolevar:: zuul_use_fetch_output + :default: false + + Whether to synchronize files to the executor work dir, or to copy them + on the test instance. + When set to false, the role synchronizes the file to the executor. + When set to true, the job needs to use the fetch-output role later. diff --git a/roles/fetch-subunit-output/defaults/main.yaml b/roles/fetch-subunit-output/defaults/main.yaml index cda642faf..0b0477812 100644 --- a/roles/fetch-subunit-output/defaults/main.yaml +++ b/roles/fetch-subunit-output/defaults/main.yaml @@ -2,3 +2,5 @@ tox_envlist: "" fetch_subunit_output_additional_dirs: [] zuul_work_dir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" +zuul_output_dir: "{{ ansible_user_dir }}/zuul-output" +zuul_use_fetch_output: "{{ zuul_site_use_fetch_output|default(false) }}" diff --git a/roles/fetch-subunit-output/tasks/process.yaml b/roles/fetch-subunit-output/tasks/process.yaml index 3530e37ad..e9becfccc 100644 --- a/roles/fetch-subunit-output/tasks/process.yaml +++ b/roles/fetch-subunit-output/tasks/process.yaml @@ -23,6 +23,15 @@ src: "{{ item.path }}" verify_host: true with_items: "{{ subunit_files.files }}" + when: not zuul_use_fetch_output + +- name: Copy test-results + copy: + dest: "{{ zuul_output_dir }}/logs/" + src: "{{ item.path }}" + remote_src: true + with_items: "{{ subunit_files.files }}" + when: zuul_use_fetch_output - name: Return artifact to Zuul zuul_return: diff --git a/test-playbooks/python/fetch-subunit-output.yaml b/test-playbooks/python/fetch-subunit-output.yaml new file mode 100644 index 000000000..d6c4c98a8 --- /dev/null +++ b/test-playbooks/python/fetch-subunit-output.yaml @@ -0,0 +1,68 @@ +- hosts: all + pre_tasks: + # Run ensure-output-dirs now as it is not performed speculatively + - import_role: + name: ensure-output-dirs + + - name: Create fake test directory + file: + path: "{{ zuul.project.src_dir }}/ztest" + state: directory + + - name: Simplify tox config + copy: + content: "{{ item.content }}" + dest: "{{ zuul.project.src_dir }}/{{ item.dest }}" + with_items: + - content: | + [testenv] + sitepackages = True + usedevelop = True + deps = stestr + + [testenv:venv] + commands = stestr run --test-path ./ztest/ {posargs} + dest: tox.ini + - content: | + import setuptools + setuptools.setup() + dest: setup.py + - content: "" + dest: setup.cfg + - content: | + import unittest + class TestTestCase(unittest.TestCase): + def test_test(self): + assert True + dest: ztest/__init__.py + + - name: Generate tox results + include_role: + name: "{{ item }}" + with_items: + - ensure-tox + - ensure-python + - tox + + tasks: + - import_role: + name: fetch-subunit-output + + - import_role: + name: fetch-output + when: zuul_use_fetch_output + + post_tasks: + - name: Check for artifact on the test instance + stat: + path: "{{ ansible_user_dir }}/zuul-output/logs/testr_results.html" + register: _test_artifact + failed_when: not _test_artifact.stat.exists + when: zuul_use_fetch_output + + - name: Check for artifact on the executor + stat: + path: "{{ zuul.executor.log_root }}/testr_results.html" + delegate_to: localhost + register: _executor_artifact + failed_when: not _executor_artifact.stat.exists diff --git a/zuul-tests.d/python-jobs.yaml b/zuul-tests.d/python-jobs.yaml index e2dafeb0b..c39de1015 100644 --- a/zuul-tests.d/python-jobs.yaml +++ b/zuul-tests.d/python-jobs.yaml @@ -42,6 +42,26 @@ vars: zuul_use_fetch_output: false +- job: + name: zuul-jobs-test-fetch-subunit-output + description: Test the fetch-subunit-output + files: + - roles/ensure-output-dirs/.* + - roles/fetch-subunit-output/.* + - roles/fetch-output/.* + run: test-playbooks/python/fetch-subunit-output.yaml + vars: + zuul_use_fetch_output: true + +- job: + name: zuul-jobs-test-fetch-subunit-output-synchronize + description: Test the fetch-subunit-output + files: + - roles/fetch-subunit-output/.* + run: test-playbooks/python/fetch-subunit-output.yaml + vars: + zuul_use_fetch_output: false + - project: check: jobs: &id001 @@ -49,5 +69,7 @@ - zuul-jobs-test-tox-siblings - zuul-jobs-test-fetch-tox-output - zuul-jobs-test-fetch-tox-output-synchronize + - zuul-jobs-test-fetch-subunit-output + - zuul-jobs-test-fetch-subunit-output-synchronize gate: jobs: *id001