Updated stack cleanup
- new mask for tempest heat-stacks 'api-[0-9]+-[a-z]+'
- added stack cleanup substep
Change-Id: I3f12155acc43341ce9bf6dc3c0b9a09b1cd48972
Related-PROD: PROD-29898
diff --git a/cleanup.sh b/cleanup.sh
index 5048b6d..eb7c0a6 100644
--- a/cleanup.sh
+++ b/cleanup.sh
@@ -1,6 +1,8 @@
#!/bin/bash
export OS_INTERFACE='admin'
mask='s_rally\|rally_\|tempest_\|tempest-'
+stack_alt=false
+stack_regex='api-[0-9]+-[a-z]+'
dry_run=false
clean_projects=false
make_servers_active=false
@@ -16,11 +18,12 @@
printf "\t-P\tForce cleaning of projects\n"
printf "\t-s\tUse single thread of 'openstack' client for cleanup\n"
printf "\t-S\tSet servers to ACTIVE before deletion (bare metal reqiured)\n"
+ printf "\t-f\tForce stack cleanup with an additional mask of '%s'\n" ${stack_regex}
printf "\t-F\tForce purge deleted stacks. Batch size: %s, >%s %s\n" ${batch_size} ${stack_granularity_value} ${stack_granularity}
}
OPTIND=1 # Reset in case getopts has been used previously in the shell.
-while getopts "h?:tsSPF" opt; do
+while getopts "h?:tsSPfF" opt; do
case "$opt" in
h|\?)
show_help
@@ -38,6 +41,9 @@
P) clean_projects=true
printf "Project cleanning enabled\n"
;;
+ f) stack_alt=true
+ printf "Cleaning stacks using additional mask '%s'\n" ${stack_regex}
+ ;;
F) purge_deleted_stacks=true
printf "Purging stacks deleted >$stack_granularity_value $stack_granularity ago enabled, batch size %s\n" $stack_batch_size
;;
@@ -260,6 +266,15 @@
printf "%s\n" ${stacks[@]} | xargs -I{} echo stack check {} >>${cmds}
printf "%s\n" ${stacks[@]} | xargs -I{} echo stack delete -y {} >>${cmds}
_clean_and_flush
+
+ if [ "$stack_alt" = true ]; then
+ stacks=( $(openstack stack list --nested --hidden -c ID -c "Stack Name" -f value | grep -E ${stack_regex} | cut -d' ' -f1) )
+ echo "-> ${#stacks[@]} stacks containing '${stack_regex}' found"
+ printf "%s\n" ${stacks[@]} | xargs -I{} echo stack check {} >>${cmds}
+ printf "%s\n" ${stacks[@]} | xargs -I{} echo stack delete -y {} >>${cmds}
+ _clean_and_flush
+ fi
+
if [ "$purge_deleted_stacks" = true ]; then
heat-manage purge_deleted -g ${stack_granularity} -b ${batch_size} ${stack_granularity_value} | wc -l | xargs -I{} echo "-> Purged {} stacks"
fi