ansible-role-refstack-client/tasks/main.yaml

199 lines
5.4 KiB
YAML

---
- name: Install required packages
include: install-packages.yaml
- name: Clone refstack-client
git:
repo: 'https://github.com/openstack/refstack-client.git'
dest: "{{ refstack_client_source }}"
version: "{{ refstack_client_version }}"
- name: Look for python3
command: "python3 --version"
ignore_errors: true
register: python3_is_available
changed_when: false
- name: Set python3 params for setup_env
set_fact:
python3_param: "-p 3"
when: python3_is_available.rc == 0
- name: Install refstack-client
command: ./setup_env {{ python3_param | default('') }}
args:
chdir: "{{ refstack_client_source }}"
when: tempest_tag is not defined
- name: Install refstack-client and clone Tempest from specific tag
command: ./setup_env -t {{ tempest_tag }} {{ python3_param | default('') }}
args:
chdir: "{{ refstack_client_source }}"
when: tempest_tag is defined
- name: Generate accounts.yaml file
include: generate-accounts.yaml
when: accounts_path is not defined
- name: Set path to newly generated accounts.yaml
set_fact:
path_to_accounts_file: "{{ refstack_client_source }}/etc/accounts.yaml"
when: accounts_path is not defined
- name: Set path to provided accounts.yaml
set_fact:
path_to_accounts_file: "{{ accounts_path }}"
when: accounts_path is defined
- name: Generate tempest configuration script
template:
src: generate-tempestconf.sh.j2
dest: "{{ refstack_client_source }}/generate-tempestconf.sh"
mode: 0744
when: tempest_config_path is not defined
- name: Generate tempest configuration file
shell: |
./generate-tempestconf.sh
args:
chdir: "{{ refstack_client_source }}"
executable: /bin/bash
when: tempest_config_path is not defined
- name: Set path to newly generated tempest.conf
set_fact:
path_to_tempest_config: "{{ refstack_client_source }}/etc/tempest.conf"
when: tempest_config_path is not defined
- name: Set path to provided tempest.conf
set_fact:
path_to_tempest_config: "{{ tempest_config_path }}"
when: tempest_config_path is defined
- name: Validate setup
shell: |
set -ex
source .venv/bin/activate
refstack-client test -c {{ path_to_tempest_config }} \
-v \
-- \
--regex tempest.api.identity.v3.test_tokens.TokensV3Test.test_create_token
args:
chdir: "{{ refstack_client_source }}"
executable: /bin/bash
changed_when: false
- name: Run tests with the defined test list
shell: |
set -ex
export PATH=$PATH:/usr/local/sbin:/usr/sbin
source .venv/bin/activate
printenv
refstack-client test \
-c {{ path_to_tempest_config }} \
-v \
--test-list {{ test_list }}
args:
chdir: "{{ refstack_client_source }}"
executable: /bin/bash
register: refstack_result
ignore_errors: true
when: test_list is defined
- name: Run tests with the default test list
shell: |
set -ex
export PATH=$PATH:/usr/local/sbin:/usr/sbin
source .venv/bin/activate
printenv
refstack-client test \
-c {{ path_to_tempest_config }} \
-v \
--test-list "https://refstack.openstack.org/api/v1/guidelines/{{ guideline }}/tests?target=platform&type=required&alias=true&flag=false"
args:
chdir: "{{ refstack_client_source }}"
executable: /bin/bash
register: refstack_result
ignore_errors: true
when: test_list is not defined
- name: Find the test result json file
shell: |
set -o pipefail -ex
ls | grep "\.json" | tail -1
register: ls_out
args:
chdir: "{{ refstack_client_source }}/.tempest/.stestr"
executable: /bin/bash
changed_when: false
- name: Copy private key
copy:
src: "{{ private_key_path_src }}"
dest: "{{ private_key_path }}"
mode: '0600'
when:
- upload_results | bool
- private_key_path is defined
- private_key_path_src is defined
- name: Upload results with signature
shell: |
set -o pipefail -ex
source .venv/bin/activate
yes | refstack-client upload ".tempest/.stestr/{{ ls_out.stdout }}" \
--url {{ server }} \
-i {{ private_key_path }}
register: upload_out
args:
chdir: "{{ refstack_client_source }}"
executable: /bin/bash
when:
- upload_results | bool
- private_key_path is defined
- when: download_artifacts | bool
block:
- name: Download results file in .json
fetch:
src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout }}"
dest: "{{ dest_dir }}/test_results.json"
flat: true
- name: Download results file in subunit
fetch:
src: "{{ refstack_client_source }}/.tempest/.stestr/{{ ls_out.stdout | splitext | first }}"
dest: "{{ dest_dir }}/test_results_subunit"
flat: true
- debug:
msg: "{{ upload_out.stdout }}"
- name: Dump output of upload command
copy:
content: "{{ upload_out.stdout }}"
dest: "{{ dest_dir }}/upload_output.txt"
mode: '0644'
delegate_to: localhost
- name: Download tempest.conf file
fetch:
src: "{{ path_to_tempest_config }}"
dest: "{{ dest_dir }}/tempest.conf"
flat: true
args:
chdir: "{{ refstack_client_source }}"
- name: Download accounts.yaml file
fetch:
src: "{{ path_to_accounts_file }}"
dest: "{{ dest_dir }}/accounts.yaml"
flat: true
args:
chdir: "{{ refstack_client_source }}"
- name: Check if we passed refstack tests
fail:
msg: "Refstack tests failed."
when: refstack_result.rc > 0