From 261ac6804d1960d98267ab7f54d54c897c4ba2ba Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Mon, 9 Sep 2024 09:45:17 +0200 Subject: [PATCH] Cleanup tempest related resources after testing Let's run tempest cleanup after the tempest run if TEMPEST_CLEANUP is set to true (false by default and debug mode is not enabled, to delete any leftover resources (from the tempest run) so that they won't disrupt any further testing - testing frameworks executed after tempest. --- .../tcib/base/os/tempest/run_tempest.sh | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/container-images/tcib/base/os/tempest/run_tempest.sh b/container-images/tcib/base/os/tempest/run_tempest.sh index 9d94678..fab4c90 100644 --- a/container-images/tcib/base/os/tempest/run_tempest.sh +++ b/container-images/tcib/base/os/tempest/run_tempest.sh @@ -95,6 +95,7 @@ CONCURRENCY="${CONCURRENCY:-}" TEMPESTCONF_ARGS="" TEMPEST_ARGS="" TEMPEST_DEBUG_MODE="${TEMPEST_DEBUG_MODE:-false}" +TEMPEST_CLEANUP="${TEMPEST_CLEANUP:-false}" function catch_error_if_debug { echo "File run_tempest.sh has run into an error!" @@ -328,10 +329,28 @@ function run_git_tempest { tempest init openshift pushd $TEMPEST_DIR - discover_tempest_config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES} \ + # We're running cleanup only under certain circumstances + if [[ ${TEMPEST_DEBUG_MODE} == false ]] && [[ ${TEMPEST_CLEANUP} == true ]]; then + # generate a simple tempest.conf so that we can run --init-saved-state + discover-tempest-config + # let's remove the images that discover-tempest-config creates by default + # so that the're not part of the saved_state.json and can be deleted + # by tempest cleanup later + openstack image list -c Name -f value | grep cirros | xargs -I {} openstack image delete {} + tempest cleanup --init-saved-state + fi + + upload_extra_images + + discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES} \ && tempest run ${TEMPEST_ARGS} RETURN_VALUE=$? + # Run tempest cleanup to delete any leftover resources when not in debug mode + if [[ ${TEMPEST_DEBUG_MODE} == false ]] && [[ ${TEMPEST_CLEANUP} == true ]]; then + tempest cleanup + fi + deactivate popd @@ -350,10 +369,28 @@ function run_rpm_tempest { # List Tempest packages rpm -qa | grep tempest - discover_tempest_config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES} \ + # We're running cleanup only under certain circumstances + if [[ ${TEMPEST_DEBUG_MODE} == false ]] && [[ ${TEMPEST_CLEANUP} == true ]]; then + # generate a simple tempest.conf so that we can run --init-saved-state + discover-tempest-config + # let's remove the images that discover-tempest-config creates by default + # so that the're not part of the saved_state.json and can be deleted + # by tempest cleanup later + openstack image list -c Name -f value | grep cirros | xargs -I {} openstack image delete {} + tempest cleanup --init-saved-state + fi + + upload_extra_images + + discover-tempest-config ${TEMPESTCONF_ARGS} ${TEMPESTCONF_OVERRIDES} \ && tempest run ${TEMPEST_ARGS} RETURN_VALUE=$? + # Run tempest cleanup to delete any leftover resources when not in debug mode + if [[ ${TEMPEST_DEBUG_MODE} == false ]] && [[ ${TEMPEST_CLEANUP} == true ]]; then + tempest cleanup + fi + popd popd } @@ -390,10 +427,6 @@ function generate_test_results { export OS_CLOUD=default -if [[ ! ${#TEMPEST_EXTRA_IMAGES_NAME[@]} -eq 0 ]]; then - upload_extra_images -fi - if [ ! -z ${USE_EXTERNAL_FILES} ] && [ -e ${TEMPEST_PATH}clouds.yaml ]; then mkdir -p $HOME/.config/openstack cp ${TEMPEST_PATH}clouds.yaml $HOME/.config/openstack/clouds.yaml