From 4089ef6afe7065f7a4478264232ded4e7007bb23 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Tue, 12 Sep 2023 08:57:18 +0200 Subject: [PATCH] Delegate tasks from the tobiko-cleanup role to undercloud In case of tripleo setups, Tobiko can be executed from the undercloud or from a different node (test_host). In case it is not run from the undercloud, the tobiko-cleanup role has to be delegated to the undercloud node. Change-Id: Ic81196dee9735acbd1841baeb25003f96f69d5a2 --- .../roles/tobiko-ir-run/tasks/main.yaml | 14 +++++++++-- roles/tobiko-cleanup/defaults/main.yaml | 4 +-- roles/tobiko-cleanup/tasks/main.yaml | 25 ++++++++----------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml index 389e82ed1..bf798db55 100644 --- a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml @@ -1,4 +1,8 @@ --- +- name: "from which host the cleanup will be executed" + set_fact: + cleanup_delegate_to: '{{ groups.get("undercloud", []) | first | default(test_host) }}' + - block: - include_role: name=tobiko-ir-jenkins when: "(lookup('env','JENKINS_URL') | length) > 0" @@ -59,7 +63,10 @@ rescue: - name: "clean up heat stacks generated during tobiko tests" - include_role: name=tobiko-cleanup + include_role: + name: tobiko-cleanup + apply: + delegate_to: '{{ cleanup_delegate_to }}' when: stacks_cleanup - name: "finalize test execution" @@ -71,7 +78,10 @@ - name: "clean up heat stacks generated during tobiko tests" - include_role: name=tobiko-cleanup + include_role: + name: tobiko-cleanup + apply: + delegate_to: '{{ cleanup_delegate_to }}' when: stacks_cleanup - name: "finalize test execution" diff --git a/roles/tobiko-cleanup/defaults/main.yaml b/roles/tobiko-cleanup/defaults/main.yaml index acef4f916..dc99a5bf3 100644 --- a/roles/tobiko-cleanup/defaults/main.yaml +++ b/roles/tobiko-cleanup/defaults/main.yaml @@ -1,4 +1,4 @@ --- -# OpenStack client credentials -stackrc_file: '{{ ansible_user_dir }}/overcloudrc' +# OpenStack command +openstack_cmd: 'openstack --os-cloud overcloud' diff --git a/roles/tobiko-cleanup/tasks/main.yaml b/roles/tobiko-cleanup/tasks/main.yaml index f726b8c65..c9e617dee 100644 --- a/roles/tobiko-cleanup/tasks/main.yaml +++ b/roles/tobiko-cleanup/tasks/main.yaml @@ -1,18 +1,16 @@ --- - name: "cleanup Loadbalancers created by Tobiko tests" shell: | - source {{ stackrc_file }} - openstack loadbalancer list -f value -c 'name' | \ + {{ openstack_cmd }} loadbalancer list -f value -c 'name' | \ grep "^tobiko\." | \ - xargs -r openstack loadbalancer delete --cascade --wait + xargs -r {{ openstack_cmd }} loadbalancer delete --cascade --wait ignore_errors: yes - name: "cleanup Heat stacks created by Tobiko tests" shell: | - source {{ stackrc_file }} - openstack stack list -f value -c 'Stack Name' | \ + {{ openstack_cmd }} stack list -f value -c 'Stack Name' | \ grep "^tobiko\." | \ - xargs -r timeout 180 openstack stack delete -y --wait + xargs -r timeout 180 {{ openstack_cmd }} stack delete -y --wait register: result retries: 5 delay: 5 @@ -21,24 +19,21 @@ - name: "cleanup subnet pools created by Tobiko tests" shell: | - source {{ stackrc_file }} - openstack subnet pool list -f value -c 'Name' | \ + {{ openstack_cmd }} subnet pool list -f value -c 'Name' | \ grep "^tobiko\." | \ - xargs -r openstack subnet pool delete + xargs -r {{ openstack_cmd }} subnet pool delete ignore_errors: yes - name: "cleanup Security Groups created by Tobiko tests" shell: | - source {{ stackrc_file }} - openstack security group list -f value -c 'Name' | \ + {{ openstack_cmd }} security group list -f value -c 'Name' | \ grep "^tobiko\." | \ - xargs -r openstack security group delete + xargs -r {{ openstack_cmd }} security group delete ignore_errors: yes - name: "cleanup Glance images created by Tobiko tests" shell: | - source {{ stackrc_file }} - openstack image list -f value -c 'Name' | \ + {{ openstack_cmd }} image list -f value -c 'Name' | \ grep "^tobiko\." | \ - xargs -r openstack image delete + xargs -r {{ openstack_cmd }} image delete ignore_errors: yes