Skip to content

Commit 2f88995

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "lib/tempest: add wait for Glance image import"
2 parents 9eb6489 + 111a38b commit 2f88995

1 file changed

Lines changed: 67 additions & 6 deletions

File tree

lib/tempest

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ TEMPEST_VOLUME_VENDOR=${TEMPEST_VOLUME_VENDOR:-$TEMPEST_DEFAULT_VOLUME_VENDOR}
7171
TEMPEST_DEFAULT_STORAGE_PROTOCOL="iSCSI"
7272
TEMPEST_STORAGE_PROTOCOL=${TEMPEST_STORAGE_PROTOCOL:-$TEMPEST_DEFAULT_STORAGE_PROTOCOL}
7373

74+
# Glance/Image variables
75+
# When Glance image import is enabled, image creation is asynchronous and images
76+
# may not yet be active when tempest looks for them. In that case, we poll
77+
# Glance every TEMPEST_GLANCE_IMPORT_POLL_INTERVAL seconds for the number of
78+
# times specified by TEMPEST_GLANCE_IMPORT_POLL_LIMIT. If you are importing
79+
# multiple images, set TEMPEST_GLANCE_IMAGE_COUNT so the poller does not quit
80+
# too early (though it will not exceed the polling limit).
81+
TEMPEST_GLANCE_IMPORT_POLL_INTERVAL=${TEMPEST_GLANCE_IMPORT_POLL_INTERVAL:-1}
82+
TEMPEST_GLANCE_IMPORT_POLL_LIMIT=${TEMPEST_GLANCE_IMPORT_POLL_LIMIT:-12}
83+
TEMPEST_GLANCE_IMAGE_COUNT=${TEMPEST_GLANCE_IMAGE_COUNT:-1}
84+
7485
# Neutron/Network variables
7586
IPV6_ENABLED=$(trueorfalse True IPV6_ENABLED)
7687
IPV6_SUBNET_ATTRIBUTES_ENABLED=$(trueorfalse True IPV6_SUBNET_ATTRIBUTES_ENABLED)
@@ -127,6 +138,48 @@ function set_tempest_venv_constraints {
127138
fi
128139
}
129140

141+
# Makes a call to glance to get a list of active images, ignoring
142+
# ramdisk and kernel images. Takes 3 arguments, an array and two
143+
# variables. The array will contain the list of active image UUIDs;
144+
# if an image with ``DEFAULT_IMAGE_NAME`` is found, its UUID will be
145+
# set as the value of *both* other parameters.
146+
function get_active_images {
147+
declare -n img_array=$1
148+
declare -n img_id=$2
149+
declare -n img_id_alt=$3
150+
151+
# start with a fresh array in case we are called multiple times
152+
img_array=()
153+
154+
while read -r IMAGE_NAME IMAGE_UUID; do
155+
if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
156+
img_id="$IMAGE_UUID"
157+
img_id_alt="$IMAGE_UUID"
158+
fi
159+
img_array+=($IMAGE_UUID)
160+
done < <(openstack --os-cloud devstack-admin image list --property status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
161+
}
162+
163+
function poll_glance_images {
164+
declare -n image_array=$1
165+
declare -n image_id=$2
166+
declare -n image_id_alt=$3
167+
local -i poll_count
168+
169+
poll_count=$TEMPEST_GLANCE_IMPORT_POLL_LIMIT
170+
while (( poll_count-- > 0 )) ; do
171+
sleep $TEMPEST_GLANCE_IMPORT_POLL_INTERVAL
172+
get_active_images image_array image_id image_id_alt
173+
if (( ${#image_array[*]} >= $TEMPEST_GLANCE_IMAGE_COUNT )) ; then
174+
return
175+
fi
176+
done
177+
local msg
178+
msg="Polling limit of $TEMPEST_GLANCE_IMPORT_POLL_LIMIT exceeded; "
179+
msg+="poll interval was $TEMPEST_GLANCE_IMPORT_POLL_INTERVAL sec"
180+
warn $LINENO "$msg"
181+
}
182+
130183
# configure_tempest() - Set config files, create data dirs, etc
131184
function configure_tempest {
132185
if [[ "$INSTALL_TEMPEST" == "True" ]]; then
@@ -168,13 +221,21 @@ function configure_tempest {
168221
declare -a images
169222

170223
if is_service_enabled glance; then
171-
while read -r IMAGE_NAME IMAGE_UUID; do
172-
if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
173-
image_uuid="$IMAGE_UUID"
174-
image_uuid_alt="$IMAGE_UUID"
224+
get_active_images images image_uuid image_uuid_alt
225+
226+
if (( ${#images[*]} < $TEMPEST_GLANCE_IMAGE_COUNT )); then
227+
# Glance image import is asynchronous and may be configured
228+
# to do image conversion. If image import is being used,
229+
# it's possible that this code is being executed before the
230+
# import has completed and there may be no active images yet.
231+
if [[ "$GLANCE_USE_IMPORT_WORKFLOW" == "True" ]]; then
232+
poll_glance_images images image_uuid image_uuid_alt
233+
if (( ${#images[*]} < $TEMPEST_GLANCE_IMAGE_COUNT )); then
234+
echo "Only found ${#images[*]} image(s), was looking for $TEMPEST_GLANCE_IMAGE_COUNT"
235+
exit 1
236+
fi
175237
fi
176-
images+=($IMAGE_UUID)
177-
done < <(openstack --os-cloud devstack-admin image list --property status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
238+
fi
178239

179240
case "${#images[*]}" in
180241
0)

0 commit comments

Comments
 (0)