Skip to content

Commit f1882e4

Browse files
fyanacdasm
authored andcommitted
Add tobiko_cleanup in cifmw
1 parent 712ef7d commit f1882e4

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

roles/test_operator/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Default value: {}
107107
* `cifmw_test_operator_tobiko_name`: (String) Value used in the `Tobiko.Metadata.Name` field. The value specifies the name of some resources spawned by the test-operator role. Default value: `tobiko-tests`
108108
* `cifmw_test_operator_tobiko_registry`: (String) The registry where to pull tobiko container. Default value: `{{ cifmw_test_operator_default_registry }}`
109109
* `cifmw_test_operator_tobiko_namespace`: (String) Registry's namespace where to pull tobiko container. Default value: `{{ cifmw_test_operator_default_namespace }}`
110+
* `cifmw_test_operator_tobiko_cleanup`: (Boolean) Cleanup all resources created by tobiko. Default value: `false`
110111
* `cifmw_test_operator_tobiko_container`: (String) Name of the tobiko container. Default value: `openstack-tobiko`
111112
* `cifmw_test_operator_tobiko_image`: (String) Tobiko image to be used. Default value: `{{ cifmw_test_operator_tobiko_registry }}/{{ cifmw_test_operator_tobiko_namespace }}/{{ cifmw_test_operator_tobiko_container }}`
112113
* `cifmw_test_operator_tobiko_image_tag`: (String) Tag for the `cifmw_test_operator_tobiko_image`. Default value: `{{ cifmw_test_operator_default_image_tag }}`
@@ -117,6 +118,7 @@ Default value: {}
117118
* `cifmw_test_operator_tobiko_num_processes`: (Integer) Sets the value of the env variable `TOX_NUM_PROCESSES` that is used to run pytest with `--numprocesses $TOX_NUM_PROCESSES`. Defaults to `null`. In case of `null` value, `TOX_NUM_PROCESSES` is not set (tobiko internally uses the value `auto`, see pytest documentation about the `--numprocesses` option).
118119
* `cifmw_test_operator_tobiko_advanced_image_url`: (String) Tobiko will download images from this URL that will be used to create advance VM instances. By default, the provided image will include all the customizations required by the tobiko tests. Defaults to `https://softwarefactory-project.io/ubuntu-minimal-customized-enp3s0`.
119120
* `cifmw_test_operator_tobiko_kubeconfig_secret`: (String) Name of the Openshift Secret required to use Openshift Client from the Tobiko pod. Default value: `tobiko-secret`
121+
* `cifmw_test_operator_tobiko_openstack_cmd`: (String) Openstack command is used by tobiko to cleanup resources. Default value: `oc -n openstack exec openstackclient -- openstack`
120122
* `cifmw_test_operator_tobiko_override_conf`: (Dict) Overrides the default configuration from `cifmw_test_operator_tobiko_default_conf` that is used to generate the tobiko.conf file. Default value: empty dictionary
121123
* `cifmw_test_operator_tobiko_ssh_keytype`: (String) Type of ssh key that tobiko will use to connect to the VM instances it creates. Defaults to `cifmw_ssh_keytype` which default to `ecdsa`.
122124
* `cifmw_test_operator_tobiko_ssh_keysize`: (Integer) Size of ssh key that tobiko will use to connect to the VM instances it creates. Defaults to `cifmw_ssh_keysize` which defaults to 521.

roles/test_operator/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ cifmw_test_operator_tobiko_num_processes: null
164164
cifmw_test_operator_tobiko_advanced_image_url: "https://softwarefactory-project.io/ubuntu-minimal-customized-enp3s0"
165165
cifmw_test_operator_tobiko_override_conf: {}
166166
cifmw_test_operator_tobiko_kubeconfig_secret: tobiko-secret
167+
cifmw_test_operator_tobiko_openstack_cmd: 'oc -n openstack exec openstackclient -- openstack'
168+
cifmw_test_operator_tobiko_cleanup: false
167169
cifmw_test_operator_tobiko_ssh_keytype: "{{ cifmw_ssh_keytype | default('ecdsa') }}"
168170
cifmw_test_operator_tobiko_ssh_keysize: "{{ cifmw_ssh_keysize | default(521) }}"
169171
cifmw_test_operator_tobiko_debug: false

roles/test_operator/tasks/runners/tobiko_runner.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,60 @@
1010
test_operator_workflow: "{{ stage_vars_dict.cifmw_test_operator_tobiko_workflow }}"
1111
test_operator_config_playbook: tobiko-tests.yml
1212
ansible.builtin.include_tasks: run-test-operator-job.yml
13+
14+
- name: Cleanup tobiko workloads
15+
when: cifmw_test_operator_tobiko_cleanup | bool
16+
block:
17+
- name: Cleanup Loadbalancers created by Tobiko tests
18+
ansible.builtin.shell: |
19+
set -o pipefail && \
20+
for lb in $({{ cifmw_test_operator_tobiko_openstack_cmd }} loadbalancer list | \
21+
grep "tobiko" | awk -F '|' '{print $2}')
22+
do
23+
{{ cifmw_test_operator_tobiko_openstack_cmd }} loadbalancer delete --cascade --wait $lb
24+
done
25+
failed_when: false
26+
27+
- name: Cleanup Heat stacks created by Tobiko tests
28+
ansible.builtin.shell: |
29+
set -o pipefail && \
30+
{{ cifmw_test_operator_tobiko_openstack_cmd }} stack list | \
31+
grep "tobiko" | awk -F '|' '{print $2}' | \
32+
xargs -r timeout 180 {{ cifmw_test_operator_tobiko_openstack_cmd }} stack delete -y --wait
33+
register: result
34+
retries: 5
35+
delay: 5
36+
until: result.rc == 0
37+
failed_when: false
38+
39+
- name: Cleanup subnet pools created by Tobiko tests
40+
ansible.builtin.shell: |
41+
set -o pipefail && \
42+
{{ cifmw_test_operator_tobiko_openstack_cmd }} subnet pool list | \
43+
grep "tobiko" | awk -F '|' '{print $2}' | \
44+
xargs -r {{ cifmw_test_operator_tobiko_openstack_cmd }} subnet pool delete
45+
failed_when: false
46+
47+
- name: Cleanup Security Groups created by Tobiko tests
48+
ansible.builtin.shell: |
49+
set -o pipefail && \
50+
{{ cifmw_test_operator_tobiko_openstack_cmd }} security group list | \
51+
grep "tobiko" | awk -F '|' '{print $2}' | \
52+
xargs -r {{ cifmw_test_operator_tobiko_openstack_cmd }} security group delete
53+
failed_when: false
54+
55+
- name: Cleanup Glance images created by Tobiko tests
56+
ansible.builtin.shell: |
57+
set -o pipefail && \
58+
{{ cifmw_test_operator_tobiko_openstack_cmd }} image list | \
59+
grep "tobiko" | awk -F '|' '{print $2}' | \
60+
xargs -r {{ cifmw_test_operator_tobiko_openstack_cmd }} image delete
61+
failed_when: false
62+
63+
- name: Cleanup Manila shares created by Tobiko tests
64+
ansible.builtin.shell: |
65+
set -o pipefail && \
66+
{{ cifmw_test_operator_tobiko_openstack_cmd }} share list | \
67+
grep "tobiko" | awk -F '|' '{print $2}' | \
68+
xargs -r {{ cifmw_test_operator_tobiko_openstack_cmd }} share delete --force
69+
failed_when: false

0 commit comments

Comments
 (0)