Separate roles in pre-run, run and post-run phases

Change-Id: Ibe539dd1a7be74be01310876ba04efba666f8bc1
This commit is contained in:
Federico Ressi 2020-04-06 10:42:35 +02:00
parent 672017742a
commit 8e469b87a5
17 changed files with 201 additions and 163 deletions

View File

@ -4,51 +4,4 @@
gather_facts: yes
any_errors_fatal: yes
roles:
- role: tobiko-common
- role: tobiko-deploy
vars:
src_dir: '{{ tobiko_src_dir }}'
dest_dir: '{{ tobiko_dir }}'
git_repo: '{{ tobiko_git_repo }}'
git_refspec: '{{ tobiko_git_refspec }}'
git_version: '{{ tobiko_git_version }}'
when:
- test_stage in ['all', 'pre-run', 'deploy', 'deploy-tobiko']
- role: tobiko-deploy
vars:
src_dir: '{{ test_src_dir }}'
dest_dir: '{{ test_dir }}'
git_repo: '{{ test_git_repo }}'
git_refspec: '{{ test_git_refspec }}'
git_version: '{{ test_git_version }}'
when:
- test_stage in ['all', 'pre-run', 'deploy', 'deploy-test']
- tobiko_dir != test_dir
- role: tobiko-configure
when:
- test_stage in ['all', 'pre-run', 'configure']
- role: tobiko-tox
ignore_errors: yes
when:
- test_stage in ['all', 'run', 'tox']
- role: tobiko-collect
when:
- test_stage in ['all', 'post-run', 'collect']
- hosts: '{{ test_host }}'
tasks:
- name: 'report test failure'
debug:
msg: 'Test cases have failed'
failed_when: yes
when:
- run_tox is defined
- run_tox is failed
- role: tobiko-all

View File

View File

@ -0,0 +1,28 @@
---
- block:
- name: "initialize test execution"
include_role:
name: tobiko-pre-run
- name: "run tests"
include_role:
name: tobiko-run
rescue:
- name: "finalize test execution"
include_role:
name: tobiko-post-run
ignore_errors: yes
- fail:
msg: 'TEST EXECUTION FAILED'
- name: "finalize test execution"
include_role:
name: tobiko-post-run
- debug:
msg: 'TEST EXECUTION SUCCEEDED'

View File

@ -1,6 +1,5 @@
---
report_dir: '{{ test_report_dir | realpath }}'
report_files: '{{ test_report_files }}'
report_name: '{{ test_report_name }}'

View File

@ -2,3 +2,4 @@
dependencies:
- role: tobiko-common
- role: tobiko-ensure-rsync

View File

@ -0,0 +1,50 @@
---
- name: "ensures local directory '{{ collect_dir }}' exists"
file:
path: '{{ collect_dir }}'
state: directory
delegate_to: localhost
- name: "look for report files in {{ report_dir }}"
find:
paths:
- "{{ report_dir }}"
patterns:
- "{{ report_name }}*.log"
- "{{ report_name }}*.subunit"
- "{{ report_name }}*.html"
- "{{ report_name }}*.xml"
register: find_report_files
- name: "add found report files"
set_fact:
report_files: '{{ (( find_report_files.files | json_query("[*].path")) + report_files) | unique }}'
- name: "check if report files exists"
stat:
path: "{{ item }}"
get_checksum: no
register: stat_report_files
loop: '{{ report_files }}'
- name: "filter out non existing report files"
set_fact:
report_files: >
{{ stat_report_files.results |
json_query("[?stat.exists].stat.path") }}
- name: "collect report files to local directory '{{ collect_dir }}'"
synchronize:
dest: '{{ collect_dir }}/{{ item | basename }}'
mode: pull
src: '{{ item }}'
use_ssh_args: yes
recursive: yes
ignore_errors: yes
loop: '{{ report_files }}'

View File

@ -1,50 +1,6 @@
---
- name: "ensures local directory '{{ collect_dir }}' exists"
file:
path: '{{ collect_dir }}'
state: directory
delegate_to: localhost
- name: "look for report files in {{ report_dir }}"
find:
paths:
- "{{ report_dir }}"
patterns:
- "{{ report_name }}*.log"
- "{{ report_name }}*.subunit"
- "{{ report_name }}*.html"
- "{{ report_name }}*.xml"
register: find_report_files
- name: "add found report files"
set_fact:
report_files: '{{ (( find_report_files.files | json_query("[*].path")) + report_files) | unique }}'
- name: "check if report files exists"
stat:
path: "{{ item }}"
get_checksum: no
register: stat_report_files
loop: '{{ report_files }}'
- name: "filter out non existing report files"
set_fact:
report_files: >
{{ stat_report_files.results |
json_query("[?stat.exists].stat.path") }}
- name: "collect report files to local directory '{{ collect_dir }}'"
synchronize:
dest: '{{ collect_dir }}/{{ item | basename }}'
mode: pull
src: '{{ item }}'
use_ssh_args: yes
recursive: yes
ignore_errors: yes
loop: '{{ report_files }}'
- name: "collect test results"
include_tasks: collect.yaml
when:
- test_stage in ['all', 'post-run', 'collect']

View File

@ -16,4 +16,4 @@ log_debug: '{{ test_log_debug | bool }}'
log_file: "{{ test_log_file | realpath }}"
# OpenStack client credentials
stackrc_file: '{{ user_home }}/overcloudrc'
stackrc_file: '{{ ansible_user_dir }}/overcloudrc'

View File

@ -0,0 +1,46 @@
---
- name: "list configuration options"
set_fact:
conf_yaml: |
{% for section, options in (sections.items() | sort) %}
{% for option, value in (options.items() | sort) %}
- section: "{{ section }}"
option: "{{ option }}"
value: "{{ value }}"
{% endfor %}
{% endfor %}
vars:
sections: "{{ default_conf | combine(conf, recursive=True) }}"
- name: "generate '{{ conf_file }}' file"
ini_file:
path: "{{ conf_file }}"
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
mode: '0644'
when:
- item.section
- item.option
- item.value
loop: "{{ conf_yaml | from_yaml | list }}"
- name: "read resulting {{ conf_file }} file"
command: "cat '{{ conf_file }}'"
register: read_conf_file
- name: "show resulting '{{ conf_file }}' file"
debug: var=read_conf_file.stdout_lines
# TODO (fressi): move it to a Tobiko python fixture
- name: Set permissive quotas for instances and cores
shell: |
source "{{ stackrc_file }}"
openstack quota set --instances -1 admin
openstack quota set --cores -1 admin
ignore_errors: yes

View File

@ -1,46 +1,6 @@
---
- name: "list configuration options"
set_fact:
conf_yaml: |
{% for section, options in (sections.items() | sort) %}
{% for option, value in (options.items() | sort) %}
- section: "{{ section }}"
option: "{{ option }}"
value: "{{ value }}"
{% endfor %}
{% endfor %}
vars:
sections: "{{ default_conf | combine(conf, recursive=True) }}"
- name: "generate '{{ conf_file }}' file"
ini_file:
path: "{{ conf_file }}"
section: "{{ item.section }}"
option: "{{ item.option }}"
value: "{{ item.value }}"
mode: '0644'
- name: "configure test cases"
include_tasks: 'configure.yaml'
when:
- item.section
- item.option
- item.value
loop: "{{ conf_yaml | from_yaml | list }}"
- name: "read resulting {{ conf_file }} file"
command: "cat '{{ conf_file }}'"
register: read_conf_file
- name: "show resulting '{{ conf_file }}' file"
debug: var=read_conf_file.stdout_lines
# TODO (fressi): move it to a Tobiko python fixture
- name: Set permissive quotas for instances and cores
shell: |
source "{{ stackrc_file }}"
openstack quota set --instances -1 admin
openstack quota set --cores -1 admin
ignore_errors: yes
- test_stage in ['all', 'pre-run', 'configure']

View File

@ -0,0 +1,3 @@
---
git_executable: git

View File

@ -0,0 +1,4 @@
---
dependencies:
- role: tobiko-common

View File

@ -0,0 +1,42 @@
---
- block:
- name: "get '{{ git_executable }}' full path"
shell: >
which '{{ git_executable }}'
register: get_git_path
rescue:
- name: "install Git packages"
become: true
package:
name: git
- name: "get '{{ git_executable }}' full path"
shell: >
which '{{ git_executable }}'
register: get_git_path
- name: "update git_executable fact"
set_fact:
git_executable: '{{ get_git_path.stdout_lines | first }}'
- name: "get Git version"
command: >
'{{ git_executable }}' --version
register:
get_git_version
- name: update git_version fact
set_fact:
git_version: '{{ get_git_version.stdout_lines | first }}'
- name: "show Git facts"
debug:
msg:
git_executable: '{{ git_executable }}'
git_version: '{{ git_version }}'

View File

@ -1,24 +1,6 @@
---
- block:
- name: "get installed git version" # noqa 303
shell: >
git --version
register: get_git_gersion
rescue:
- name: "install Git packages"
become: true
package:
name: git
- name: "get installed git version" # noqa 303
shell: >
git --version
register: get_git_gersion
- name: "show installed git version"
debug:
var: get_git_gersion.stdout
verbosity: 1
- name: "ensures 'git' command is available"
include_tasks: git.yaml
when:
- git_version is not defined

View File

@ -0,0 +1,4 @@
---
dependencies:
- role: tobiko-collect

View File

@ -0,0 +1,6 @@
---
dependencies:
- role: tobiko-common
- role: tobiko-deploy
- role: tobiko-configure

View File

@ -0,0 +1,4 @@
---
dependencies:
- role: tobiko-tox