Browse Source

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

Change-Id: Ibe539dd1a7be74be01310876ba04efba666f8bc1
changes/91/717691/1
Federico Ressi 1 year ago
parent
commit
8e469b87a5
  1. 49
      roles/infrared.yaml
  2. 0
      roles/tobiko-all/tasks/all.yaml
  3. 28
      roles/tobiko-all/tasks/main.yaml
  4. 1
      roles/tobiko-collect/defaults/main.yaml
  5. 1
      roles/tobiko-collect/meta/main.yaml
  6. 50
      roles/tobiko-collect/tasks/collect.yaml
  7. 52
      roles/tobiko-collect/tasks/main.yaml
  8. 2
      roles/tobiko-configure/defaults/main.yaml
  9. 46
      roles/tobiko-configure/tasks/configure.yaml
  10. 46
      roles/tobiko-configure/tasks/main.yaml
  11. 3
      roles/tobiko-ensure-git/defaults/main.yaml
  12. 4
      roles/tobiko-ensure-git/meta/main.yaml
  13. 42
      roles/tobiko-ensure-git/tasks/git.yaml
  14. 26
      roles/tobiko-ensure-git/tasks/main.yaml
  15. 4
      roles/tobiko-post-run/meta/main.yaml
  16. 6
      roles/tobiko-pre-run/meta/main.yaml
  17. 4
      roles/tobiko-run/meta/main.yaml

49
roles/infrared.yaml

@ -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

0
roles/tobiko-all/tasks/all.yaml

28
roles/tobiko-all/tasks/main.yaml

@ -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'

1
roles/tobiko-collect/defaults/main.yaml

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

1
roles/tobiko-collect/meta/main.yaml

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

50
roles/tobiko-collect/tasks/collect.yaml

@ -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 }}'

52
roles/tobiko-collect/tasks/main.yaml

@ -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']

2
roles/tobiko-configure/defaults/main.yaml

@ -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'

46
roles/tobiko-configure/tasks/configure.yaml

@ -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

46
roles/tobiko-configure/tasks/main.yaml

@ -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']

3
roles/tobiko-ensure-git/defaults/main.yaml

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

4
roles/tobiko-ensure-git/meta/main.yaml

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

42
roles/tobiko-ensure-git/tasks/git.yaml

@ -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 }}'

26
roles/tobiko-ensure-git/tasks/main.yaml

@ -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

4
roles/tobiko-post-run/meta/main.yaml

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

6
roles/tobiko-pre-run/meta/main.yaml

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

4
roles/tobiko-run/meta/main.yaml

@ -0,0 +1,4 @@
---
dependencies:
- role: tobiko-tox
Loading…
Cancel
Save