diff --git a/roles/infrared.yaml b/roles/infrared.yaml index 915917eff..8df5d79da 100644 --- a/roles/infrared.yaml +++ b/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 diff --git a/roles/tobiko-all/tasks/all.yaml b/roles/tobiko-all/tasks/all.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/roles/tobiko-all/tasks/main.yaml b/roles/tobiko-all/tasks/main.yaml new file mode 100644 index 000000000..d88d714f4 --- /dev/null +++ b/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' diff --git a/roles/tobiko-collect/defaults/main.yaml b/roles/tobiko-collect/defaults/main.yaml index 96be84768..cb8ea7953 100644 --- a/roles/tobiko-collect/defaults/main.yaml +++ b/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 }}' diff --git a/roles/tobiko-collect/meta/main.yaml b/roles/tobiko-collect/meta/main.yaml index 0d4361583..9ee06aeff 100644 --- a/roles/tobiko-collect/meta/main.yaml +++ b/roles/tobiko-collect/meta/main.yaml @@ -2,3 +2,4 @@ dependencies: - role: tobiko-common + - role: tobiko-ensure-rsync diff --git a/roles/tobiko-collect/tasks/collect.yaml b/roles/tobiko-collect/tasks/collect.yaml new file mode 100644 index 000000000..9ab482678 --- /dev/null +++ b/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 }}' diff --git a/roles/tobiko-collect/tasks/main.yaml b/roles/tobiko-collect/tasks/main.yaml index 9ab482678..3e4e3a6fc 100644 --- a/roles/tobiko-collect/tasks/main.yaml +++ b/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'] diff --git a/roles/tobiko-configure/defaults/main.yaml b/roles/tobiko-configure/defaults/main.yaml index d5f5922ee..d22a3d2bc 100644 --- a/roles/tobiko-configure/defaults/main.yaml +++ b/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' diff --git a/roles/tobiko-configure/tasks/configure.yaml b/roles/tobiko-configure/tasks/configure.yaml new file mode 100644 index 000000000..169f2833b --- /dev/null +++ b/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 diff --git a/roles/tobiko-configure/tasks/main.yaml b/roles/tobiko-configure/tasks/main.yaml index 169f2833b..c27f4eec8 100644 --- a/roles/tobiko-configure/tasks/main.yaml +++ b/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'] diff --git a/roles/tobiko-ensure-git/defaults/main.yaml b/roles/tobiko-ensure-git/defaults/main.yaml new file mode 100644 index 000000000..6e10e75d5 --- /dev/null +++ b/roles/tobiko-ensure-git/defaults/main.yaml @@ -0,0 +1,3 @@ +--- + +git_executable: git diff --git a/roles/tobiko-ensure-git/meta/main.yaml b/roles/tobiko-ensure-git/meta/main.yaml new file mode 100644 index 000000000..0d4361583 --- /dev/null +++ b/roles/tobiko-ensure-git/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: tobiko-common diff --git a/roles/tobiko-ensure-git/tasks/git.yaml b/roles/tobiko-ensure-git/tasks/git.yaml new file mode 100644 index 000000000..b7aa7de74 --- /dev/null +++ b/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 }}' diff --git a/roles/tobiko-ensure-git/tasks/main.yaml b/roles/tobiko-ensure-git/tasks/main.yaml index 124623c0a..d06fa0468 100644 --- a/roles/tobiko-ensure-git/tasks/main.yaml +++ b/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 diff --git a/roles/tobiko-post-run/meta/main.yaml b/roles/tobiko-post-run/meta/main.yaml new file mode 100644 index 000000000..80c9226ff --- /dev/null +++ b/roles/tobiko-post-run/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: tobiko-collect diff --git a/roles/tobiko-pre-run/meta/main.yaml b/roles/tobiko-pre-run/meta/main.yaml new file mode 100644 index 000000000..af525a911 --- /dev/null +++ b/roles/tobiko-pre-run/meta/main.yaml @@ -0,0 +1,6 @@ +--- + +dependencies: + - role: tobiko-common + - role: tobiko-deploy + - role: tobiko-configure diff --git a/roles/tobiko-run/meta/main.yaml b/roles/tobiko-run/meta/main.yaml new file mode 100644 index 000000000..d0e9e4f30 --- /dev/null +++ b/roles/tobiko-run/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: tobiko-tox