Allow tempest cleanup delete resources based on prefix
A warning in command description of run cleanup first with dry-run
is added. The cleanup behavior is extended to allow users to delete
only resources if their name starts with a certain prefix.
Closes-Bug: #1945082
Change-Id: I65dfe051c891b3679538acec713e8616746c47f6
diff --git a/roles/tempest-cleanup/README.rst b/roles/tempest-cleanup/README.rst
index d1fad90..d43319c 100644
--- a/roles/tempest-cleanup/README.rst
+++ b/roles/tempest-cleanup/README.rst
@@ -40,6 +40,12 @@
some must have been leaked. This can be also used to verify that tempest
cleanup was successful.
+.. zuul:rolevar:: run_tempest_cleanup_prefix
+ :default: false
+
+ When true, tempest cleanup will be called with '--prefix tempest' to delete
+ only resources with names that match the prefix. This option can be used
+ together with dry_run.
Role usage
----------
diff --git a/roles/tempest-cleanup/defaults/main.yaml b/roles/tempest-cleanup/defaults/main.yaml
index ce78bdb..8060b29 100644
--- a/roles/tempest-cleanup/defaults/main.yaml
+++ b/roles/tempest-cleanup/defaults/main.yaml
@@ -2,3 +2,4 @@
init_saved_state: false
dry_run: false
run_tempest_fail_if_leaked_resources: false
+run_tempest_cleanup_prefix: false
diff --git a/roles/tempest-cleanup/tasks/dry_run.yaml b/roles/tempest-cleanup/tasks/dry_run.yaml
index 46749ab..07e1b63 100644
--- a/roles/tempest-cleanup/tasks/dry_run.yaml
+++ b/roles/tempest-cleanup/tasks/dry_run.yaml
@@ -5,3 +5,12 @@
command: tox -evenv-tempest -- tempest cleanup --dry-run --debug
args:
chdir: "{{ devstack_base_dir }}/tempest"
+ when: not run_tempest_cleanup_prefix
+
+- name: Run tempest cleanup dry-run with tempest prefix
+ become: yes
+ become_user: tempest
+ command: tox -evenv-tempest -- tempest cleanup --dry-run --debug --prefix tempest
+ args:
+ chdir: "{{ devstack_base_dir }}/tempest"
+ when: run_tempest_cleanup_prefix
\ No newline at end of file
diff --git a/roles/tempest-cleanup/tasks/main.yaml b/roles/tempest-cleanup/tasks/main.yaml
index c1d63f0..7ef4928 100644
--- a/roles/tempest-cleanup/tasks/main.yaml
+++ b/roles/tempest-cleanup/tasks/main.yaml
@@ -27,6 +27,15 @@
command: tox -evenv-tempest -- tempest cleanup --debug
args:
chdir: "{{ devstack_base_dir }}/tempest"
+ when: not run_tempest_cleanup_prefix
+
+ - name: Run tempest cleanup with tempest prefix
+ become: yes
+ become_user: tempest
+ command: tox -evenv-tempest -- tempest cleanup --debug --prefix tempest
+ args:
+ chdir: "{{ devstack_base_dir }}/tempest"
+ when: run_tempest_cleanup_prefix
- when:
- run_tempest_fail_if_leaked_resources