|
| 1 | +--- |
| 2 | +# This playbook executes tests from the StackHPC OpenStack Tests repository. |
| 3 | +# https://github.com/stackhpc/stackhpc-openstack-tests |
| 4 | + |
| 5 | +- name: Run StackHPC OpenStack tests |
| 6 | + hosts: tempest_runner:overcloud |
| 7 | + tags: |
| 8 | + - stackhpc-openstack-tests |
| 9 | + vars: |
| 10 | + sot_venv: "{{ virtualenv_path }}/sot-venv" |
| 11 | + sot_repo: "https://github.com/stackhpc/stackhpc-openstack-tests" |
| 12 | + sot_version: "v0.0.1" |
| 13 | + sot_timeout: 30 |
| 14 | + results_path_local: "{{ lookup('env', 'HOME') }}/sot-results" |
| 15 | + tasks: |
| 16 | + - name: Assert that there is only one host in the tempest_runner group |
| 17 | + assert: |
| 18 | + that: groups.get('tempest_runner', []) | length == 1 |
| 19 | + fail_msg: The tempest_runner group should contain exactly one host |
| 20 | + |
| 21 | + - block: |
| 22 | + - name: Create a temporary directory for tests repo |
| 23 | + ansible.builtin.tempfile: |
| 24 | + state: directory |
| 25 | + suffix: sot-repo |
| 26 | + register: repo_tmpdir |
| 27 | + |
| 28 | + - name: Create a temporary directory for results |
| 29 | + ansible.builtin.tempfile: |
| 30 | + state: directory |
| 31 | + suffix: sot-results |
| 32 | + register: results_tmpdir |
| 33 | + |
| 34 | + - name: Clone the StackHPC OpenStack tests repository |
| 35 | + ansible.builtin.git: |
| 36 | + repo: "{{ sot_repo }}" |
| 37 | + version: "{{ sot_version }}" |
| 38 | + dest: "{{ repo_tmpdir.path }}" |
| 39 | + depth: 1 |
| 40 | + single_branch: true |
| 41 | + |
| 42 | + - name: Ensure the latest versions of pip and setuptools are installed # noqa package-latest |
| 43 | + ansible.builtin.pip: |
| 44 | + name: "{{ item.name }}" |
| 45 | + state: latest |
| 46 | + virtualenv: "{{ sot_venv }}" |
| 47 | + virtualenv_command: "python3 -m venv" |
| 48 | + with_items: |
| 49 | + - { name: pip } |
| 50 | + - { name: setuptools } |
| 51 | + |
| 52 | + - name: Ensure required Python packages are installed |
| 53 | + ansible.builtin.pip: |
| 54 | + name: |
| 55 | + - "{{ repo_tmpdir.path }}" |
| 56 | + - "-r{{ repo_tmpdir.path }}/requirements.txt" |
| 57 | + - pytest-html |
| 58 | + - pytest-timeout |
| 59 | + virtualenv: "{{ sot_venv }}" |
| 60 | + |
| 61 | + - name: Include Kolla Ansible passwords |
| 62 | + ansible.builtin.include_vars: |
| 63 | + file: "{{ kayobe_env_config_path }}/kolla/passwords.yml" |
| 64 | + name: kolla_passwords |
| 65 | + |
| 66 | + # Monitoring tests should run once, executed on the host in the |
| 67 | + # tempest_runner group. |
| 68 | + - name: Run StackHPC OpenStack monitoring tests |
| 69 | + ansible.builtin.command: |
| 70 | + cmd: > |
| 71 | + {{ sot_venv }}/bin/py.test |
| 72 | + --html={{ results_tmpdir.path }}/monitoring.html |
| 73 | + --self-contained-html |
| 74 | + --pyargs stackhpc_openstack_tests.monitoring |
| 75 | + --timeout {{ sot_timeout }} |
| 76 | + -vv |
| 77 | + environment: |
| 78 | + GRAFANA_URL: "{{ sot_grafana_url }}" |
| 79 | + GRAFANA_USERNAME: "{{ sot_grafana_username }}" |
| 80 | + GRAFANA_PASSWORD: "{{ sot_grafana_password }}" |
| 81 | + OPENSEARCH_HOSTS: "{{ sot_opensearch_hosts }}" |
| 82 | + OPENSEARCH_PORT: "{{ sot_opensearch_port }}" |
| 83 | + OPENSEARCH_TLS: "{{ sot_opensearch_tls }}" |
| 84 | + OPENSEARCH_DASHBOARDS_URL: "{{ sot_opensearch_dashboards_url }}" |
| 85 | + OPENSEARCH_DASHBOARDS_USERNAME: "{{ sot_opensearch_dashboards_username }}" |
| 86 | + OPENSEARCH_DASHBOARDS_PASSWORD: "{{ sot_opensearch_dashboards_password }}" |
| 87 | + PROMETHEUS_URL: "{{ sot_prometheus_url }}" |
| 88 | + PROMETHEUS_USERNAME: "{{ sot_prometheus_username }}" |
| 89 | + PROMETHEUS_PASSWORD: "{{ sot_prometheus_password }}" |
| 90 | + vars: |
| 91 | + kolla_external_scheme: "{{ 'https' if kolla_enable_tls_external | bool else 'http' }}" |
| 92 | + kolla_internal_scheme: "{{ 'https' if kolla_enable_tls_internal | bool else 'http' }}" |
| 93 | + sot_grafana_url: "{{ kolla_external_scheme }}://{{ kolla_external_fqdn }}:3000" |
| 94 | + sot_grafana_username: "grafana_local_admin" |
| 95 | + sot_grafana_password: "{{ kolla_passwords.grafana_admin_password }}" |
| 96 | + sot_opensearch_hosts: "{{ kolla_internal_fqdn }}" |
| 97 | + sot_opensearch_port: 9200 |
| 98 | + sot_opensearch_tls: false |
| 99 | + sot_opensearch_dashboards_url: "{{ kolla_external_scheme }}://{{ kolla_external_fqdn }}:5601" |
| 100 | + sot_opensearch_dashboards_username: "opensearch" |
| 101 | + sot_opensearch_dashboards_password: "{{ kolla_passwords.opensearch_dashboards_password }}" |
| 102 | + sot_prometheus_url: "{{ kolla_internal_scheme }}://{{ kolla_internal_fqdn }}:9091" |
| 103 | + sot_prometheus_username: "admin" |
| 104 | + sot_prometheus_password: "{{ kolla_passwords.prometheus_password }}" |
| 105 | + failed_when: monitoring_results.rc not in [0, 1] |
| 106 | + register: monitoring_results |
| 107 | + when: "'tempest_runner' in group_names" |
| 108 | + |
| 109 | + # Host tests should run on every host in the overcloud group. |
| 110 | + # TODO: Use TestInfra's native Ansible or SSH connection plugins for |
| 111 | + # remote test execution? That would place all results in a single file |
| 112 | + # and allow us to execute all tests from a single host. |
| 113 | + # https://testinfra.readthedocs.io/en/latest/backends.html#connection-backends |
| 114 | + - name: Run StackHPC OpenStack host tests |
| 115 | + ansible.builtin.command: |
| 116 | + cmd: > |
| 117 | + {{ sot_venv }}/bin/py.test |
| 118 | + --html={{ results_tmpdir.path }}/host-{{ inventory_hostname }}.html |
| 119 | + --self-contained-html |
| 120 | + --pyargs stackhpc_openstack_tests.host |
| 121 | + --timeout {{ sot_timeout }} |
| 122 | + -vv |
| 123 | + environment: |
| 124 | + DOCKER_VERSION_MIN: "{{ sot_docker_version_min }}" |
| 125 | + DOCKER_VERSION_MAX: "{{ sot_docker_version_max }}" |
| 126 | + SELINUX_STATE: "{{ sot_selinux_state }}" |
| 127 | + vars: |
| 128 | + # Inclusive min |
| 129 | + sot_docker_version_min: "24.0.0" |
| 130 | + # Exclusive max |
| 131 | + sot_docker_version_max: "27.0.0" |
| 132 | + sot_selinux_state: "{{ selinux_state }}" |
| 133 | + failed_when: host_results.rc not in [0, 1] |
| 134 | + register: host_results |
| 135 | + when: "'overcloud' in group_names" |
| 136 | + always: |
| 137 | + - name: Synchronize results |
| 138 | + ansible.posix.synchronize: |
| 139 | + src: "{{ results_tmpdir.path }}/" |
| 140 | + dest: "{{ results_path_local }}/" |
| 141 | + mode: pull |
| 142 | + archive: no |
| 143 | + recursive: true |
| 144 | + # For jump host |
| 145 | + use_ssh_args: true |
| 146 | + |
| 147 | + - name: Write a file containing failed test runs |
| 148 | + ansible.builtin.copy: |
| 149 | + content: |- |
| 150 | + {% for host in ansible_play_hosts_all %} |
| 151 | + {% if host not in ansible_play_hosts %} |
| 152 | + {{ host }}: Host failure |
| 153 | + {% endif %} |
| 154 | + {% if hostvars[host].monitoring_results.rc | default(0) != 0 %} |
| 155 | + monitoring.html |
| 156 | + {% endif %} |
| 157 | + {% if hostvars[host].host_results.rc | default(0) != 0 %} |
| 158 | + host-{{ host }}.html |
| 159 | + {% endif %} |
| 160 | + {% endfor %} |
| 161 | + dest: "{{ results_path_local }}/failed-tests" |
| 162 | + delegate_to: localhost |
| 163 | + run_once: true |
| 164 | + |
| 165 | + - name: Clean up temporary directory |
| 166 | + ansible.builtin.file: |
| 167 | + path: "{{ item }}" |
| 168 | + state: absent |
| 169 | + loop: |
| 170 | + - "{{ repo_tmpdir.path }}" |
| 171 | + - "{{ results_tmpdir.path }}" |
0 commit comments