From 30197fb67c1adea4bc1893cc15244c0d244da1f9 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 | 47 ++++++++++++++++--- 1 file changed, 41 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..e39d5f6 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,29 @@ 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 delete cirros-0.6.2-x86_64-disk.img + openstack image delete cirros-0.6.2-x86_64-disk.img_alt + 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 +370,29 @@ 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 delete cirros-0.6.2-x86_64-disk.img + openstack image delete cirros-0.6.2-x86_64-disk.img_alt + 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 +429,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