From 18f796ad6a02b00fe1d1ef1dbf29b5b9cc01d460 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Wed, 11 Nov 2020 19:53:37 +0000 Subject: [PATCH] Add tempest cleanup support If a user sets tempest_cleanup variable to true, tempest cleanup will be executed prior tempest tests (to generate saved_state.json) and after the tests in order to delete leaked resources if any. Change-Id: Ief00b43237cb634ee25a18264461bfda8464bbc7 --- defaults/main.yml | 5 +++++ tasks/main.yml | 6 ++++++ tasks/tempest_cleanup.yml | 33 +++++++++++++++++++++++++++++++++ tasks/tempest_cleanup_init.yml | 31 +++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 tasks/tempest_cleanup.yml create mode 100644 tasks/tempest_cleanup_init.yml diff --git a/defaults/main.yml b/defaults/main.yml index 0300292d..a7e0bd9c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -39,6 +39,11 @@ tempest_service_setup_host_python_interpreter: "{{ openstack_service_setup_host_ # Toggle whether tempest actually executes tempest_run: no +# Toggle whether tempest cleanup executes prior and after regular tempest run +tempest_cleanup: no +# if tempest_cleanup_dry_run is set to true, tempest cleanup will log all found +# leftover resources to a dry_run.json file, none resources will be deleted +#tempest_cleanup_dry_run: no # Toggle whether default resources are implemented tempest_default_role_resources: yes diff --git a/tasks/main.yml b/tasks/main.yml index 385e13e4..56e0eb4f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -64,8 +64,14 @@ - name: Flush handlers meta: flush_handlers +- import_tasks: tempest_cleanup_init.yml + when: tempest_cleanup | bool + - import_tasks: tempest_run.yml when: tempest_run | bool tags: - tempest-config - tempest-run + +- import_tasks: tempest_cleanup.yml + when: tempest_cleanup | bool diff --git a/tasks/tempest_cleanup.yml b/tasks/tempest_cleanup.yml new file mode 100644 index 00000000..3a2a7d0a --- /dev/null +++ b/tasks/tempest_cleanup.yml @@ -0,0 +1,33 @@ +--- +# Copyright 2020, Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- block: + - name: Cleanup leftover resources + shell: > + set -e; + if [ -d {{ tempest_venv_bin }} ]; + then + . {{ tempest_venv_bin }}/activate; + fi; + tempest cleanup + {% if tempest_cleanup_dry_run | bool %} + --dry-run + {% endif %} + {% if debug | bool %} + --debug + {% endif %} + args: + chdir: "{{ tempest_workspace }}" + executable: /bin/bash diff --git a/tasks/tempest_cleanup_init.yml b/tasks/tempest_cleanup_init.yml new file mode 100644 index 00000000..f21a6ddc --- /dev/null +++ b/tasks/tempest_cleanup_init.yml @@ -0,0 +1,31 @@ +--- +# Copyright 2020, Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- block: + - name: Generate saved_state.json for tempest cleanup + shell: | + set -e + if [ -d {{ tempest_venv_bin }} ]; + then + . {{ tempest_venv_bin }}/activate + fi + tempest cleanup \ + {% if debug | bool %} + --debug \ + {% endif %} + --init-saved-state + args: + chdir: "{{ tempest_workspace }}" + executable: /bin/bash