From a9199f6fba92a51f807dd31644ba9d5e4bc31905 Mon Sep 17 00:00:00 2001 From: lkuchlan Date: Thu, 8 Aug 2024 08:37:30 +0300 Subject: [PATCH] Wait for image to be active after creation We encountered Tempest failures due to the image being in the importing process. This patch ensures the image is active when the Tempest tests are executed. Jira: https://issues.redhat.com/browse/OSPRH-9284 --- .../tcib/base/os/tempest/run_tempest.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/container-images/tcib/base/os/tempest/run_tempest.sh b/container-images/tcib/base/os/tempest/run_tempest.sh index 62e572a..a86e364 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_IMAGE_CREATE_TIMEOUT="${TEMPEST_IMAGE_CREATE_TIMEOUT:-300}" function catch_error_if_debug { echo "File run_tempest.sh has run into an error!" @@ -217,6 +218,10 @@ if [ -n "$CONCURRENCY" ] && [ -z ${TEMPEST_CONCURRENCY} ]; then TEMPEST_ARGS+="--concurrency ${CONCURRENCY} " fi +function get_image_status { + openstack image show $IMAGE_ID -f value -c status +} + function upload_extra_images { for image_index in "${!TEMPEST_EXTRA_IMAGES_NAME[@]}"; do if ! openstack image show ${TEMPEST_EXTRA_IMAGES_NAME[image_index]}; then @@ -241,7 +246,19 @@ function upload_extra_images { image_create_params+=(--container-format ${TEMPEST_EXTRA_IMAGES_CONTAINER_FORMAT[image_index]}) image_create_params+=(--public ${TEMPEST_EXTRA_IMAGES_NAME[image_index]}) - openstack image create --import ${image_create_params[@]} + IMAGE_ID=$(openstack image create --import ${image_create_params[@]} -f value -c id) + STATUS=$(get_image_status) + START_TIME=$(date +%s) + while [ "$STATUS" != "active" ]; do + echo "Current status: $STATUS. Waiting for image to become active..." + sleep 5 + if [ $(($(date +%s) - $START_TIME)) -gt $TEMPEST_IMAGE_CREATE_TIMEOUT ]; then + echo "Error: Image creation exceeded the timeout period of $TEMPEST_IMAGE_CREATE_TIMEOUT seconds." + exit 1 + fi + STATUS=$(get_image_status) + done + echo "Image $IMAGE_ID is now active." fi if ! openstack flavor show ${TEMPEST_EXTRA_IMAGES_FLAVOR_NAME[image_index]}; then