From 7bd86fcd99a86355de130b7f009f730bced864b2 Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Wed, 4 Oct 2017 14:41:48 +0100 Subject: [PATCH] Add a generic process-test-results role Takes an stestr or testr repo as input and generates a subunit file and an html report out of it. The files are stored in the staging area on the test node. This in combination with a generic role to pull the staging folder to the zuul executor is meant to eventually replace to existing roles: - fetch-testr-output - fetch-stestr-output Change-Id: Id6149d4e265ab9f0ab6d8faeffdec651c63dc056 --- roles/process-test-results/README.rst | 35 +++++++++++++ roles/process-test-results/defaults/main.yaml | 4 ++ roles/process-test-results/tasks/main.yaml | 49 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 roles/process-test-results/README.rst create mode 100644 roles/process-test-results/defaults/main.yaml create mode 100644 roles/process-test-results/tasks/main.yaml diff --git a/roles/process-test-results/README.rst b/roles/process-test-results/README.rst new file mode 100644 index 000000000..dfe4bad86 --- /dev/null +++ b/roles/process-test-results/README.rst @@ -0,0 +1,35 @@ +Process test results + +Take a testr / stestr repo as input. Produce subunit from the latest +run and the html report using subunit2html. + +**Role Variables** + +.. zuul:rolevar:: test_results_dir + :default: None + + The folder where the [s]testr repo lives. + +.. zuul:rolevar:: tox_envdir + :default: venv + + The name of the virtual environemnt created by tox to run tests. + This may be different from the name of the tox environment. + +.. zuul:rolevar:: stage_dir + :default: {{ ansible_user_dir }} + + Folder into which the output files will be written. Assumption is that + the user that runs this role has read access to test results and write + access to tempest_work_dir. + +.. zuul:rolevar:: subunit2html + :default: /usr/os-testr-env/bin/subunit2html + + The full path to subunit2html. This utility is part of os-testr, + and it's usually baked into test images, hence the default value. + +.. zuul:rolevar:: test_results_stage_name + :default: test_results + + The name of the subunit and html files generated. diff --git a/roles/process-test-results/defaults/main.yaml b/roles/process-test-results/defaults/main.yaml new file mode 100644 index 000000000..064079dd8 --- /dev/null +++ b/roles/process-test-results/defaults/main.yaml @@ -0,0 +1,4 @@ +tox_envdir: venv +stage_dir: "{{ ansible_user_dir }}" +subunit2html: /usr/os-testr-env/bin/subunit2html +test_results_stage_name: test_results diff --git a/roles/process-test-results/tasks/main.yaml b/roles/process-test-results/tasks/main.yaml new file mode 100644 index 000000000..35057e36d --- /dev/null +++ b/roles/process-test-results/tasks/main.yaml @@ -0,0 +1,49 @@ +# NOTE(andreaf) There could be more than one repo in the test folder. +# Since that's unlikely we don't provide a variable to select the +# test runner and we pick the first hit. +- name: Discover stestr repo + stat: + path: "{{ test_results_dir }}/.stestr" + register: stestr_repo + +- name: Discover testr repo + stat: + path: "{{ test_results_dir }}/.testrepository" + register: testr_repo + when: not stestr_repo.stat.exists + +- name: Use stestr test runner + set_fact: + test_runner: ".tox/{{ tox_envdir }}/bin/stestr" + when: stestr_repo.stat.exists + +- name: Use legacy testr test runner + set_fact: + test_runner: ".tox/{{ tox_envdir }}/bin/testr" + when: not stestr_repo.stat.exists and testr_repo.stat.exists + +- name: Check if the venv has been created + stat: + path: "{{ test_results_dir }}/.tox/{{ tox_envdir }}" + register: run_venv + +- name: Make sure test results are world readable + file: + path: "{{ test_results_dir }}" + mode: "a+rX" + recurse: true + become: true + +- name: Create a subunit file from the last run + shell: "{{ test_runner }} last --subunit > {{ stage_dir }}/{{ test_results_stage_name }}.subunit" + args: + chdir: "{{ test_results_dir }}" + when: run_venv.stat.exists and test_runner is defined + register: subunit_report + +- name: Generate the html report for the last run + command: "{{ subunit2html }} ./{{ test_results_stage_name}}.subunit {{ test_results_stage_name }}.html" + args: + chdir: "{{ stage_dir }}" + when: run_venv.stat.exists and test_runner is defined + register: html_report