diff --git a/infrared_plugin/plugin.spec b/infrared_plugin/plugin.spec index bafaf6485..3c707c2a6 100644 --- a/infrared_plugin/plugin.spec +++ b/infrared_plugin/plugin.spec @@ -193,6 +193,13 @@ subparsers: help: Ignore test execution errors ansible_variable: ignore_test_failures + - title: Cleanup stage + options: + cleanup-heat-stacks: + type: Flag + help: Cleanup heat stacks created by tobiko + ansible_variable: stacks_cleanup + - title: Collect stage options: collect-dir: diff --git a/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml b/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml index 133d94ef8..0097e663a 100644 --- a/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-run/defaults/main.yaml @@ -5,3 +5,4 @@ tobiko_git_refspec: '' test_git_refspec: '' tobiko_git_remote: '' test_git_remote: '' +stacks_cleanup: false diff --git a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml index 950d752f9..98d6cd188 100644 --- a/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml +++ b/infrared_plugin/roles/tobiko-ir-run/tasks/main.yaml @@ -43,6 +43,10 @@ include_role: name=tobiko-run rescue: + - name: "clean up heat stacks generated during tobiko tests" + include_role: name=tobiko-cleanup + when: stacks_cleanup + - name: "finalize test execution" include_role: name=tobiko-collect ignore_errors: yes @@ -51,6 +55,10 @@ msg: 'TEST EXECUTION FAILED' +- name: "clean up heat stacks generated during tobiko tests" + include_role: name=tobiko-cleanup + when: stacks_cleanup + - name: "finalize test execution" include_role: name=tobiko-collect diff --git a/roles/tobiko-cleanup/defaults/main.yaml b/roles/tobiko-cleanup/defaults/main.yaml new file mode 100644 index 000000000..acef4f916 --- /dev/null +++ b/roles/tobiko-cleanup/defaults/main.yaml @@ -0,0 +1,4 @@ +--- + +# OpenStack client credentials +stackrc_file: '{{ ansible_user_dir }}/overcloudrc' diff --git a/roles/tobiko-cleanup/tasks/main.yaml b/roles/tobiko-cleanup/tasks/main.yaml new file mode 100644 index 000000000..70fa72402 --- /dev/null +++ b/roles/tobiko-cleanup/tasks/main.yaml @@ -0,0 +1,8 @@ +--- + +- name: "cleanup stacks created by tobiko tests" + shell: | + source {{ stackrc_file }} + openstack stack list -f value -c 'Stack Name' | grep "^tobiko\." | xargs openstack stack delete --wait + openstack image list -f value -c Name | grep "^tobiko\." | xargs openstack image delete + ignore_errors: yes