From 2f03ec23fd9f2fdafd9e064f04f9904a67a6cefc Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Sat, 8 Dec 2018 13:20:26 -0500 Subject: [PATCH] Wait for volume to be available before attaching it On slower test nodes we're seeing failures where the 2nd cinder volume created is not yet available by the time we try to attach it to a server which fails with a 400 InvalidVolume error. This fixes the bug by waiting for the volume to be available before trying to attach it. Change-Id: I833d79ecc97ddc844bf156ab64477c7c77424f20 Closes-Bug: #1807520 --- projects/70_cinder/resources.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/projects/70_cinder/resources.sh b/projects/70_cinder/resources.sh index fe8cc42f..4c39b96e 100755 --- a/projects/70_cinder/resources.sh +++ b/projects/70_cinder/resources.sh @@ -141,6 +141,24 @@ function create { eval $(openstack volume create --size 1 $CINDER_VOL2 -f shell) resource_save cinder cinder_volume2_id $id + # Wait for the volume to be available before attaching it to the server. + # TODO(mriedem): Replace this (and the wait loop above) with --wait once + # OSC story 2002158 is complete. + timeleft=30 + while [[ $timeleft -gt 0 ]]; do + local status=$(openstack volume show $CINDER_VOL2 -f value -c status) + if [[ "$status" != "available" ]]; then + echo "Volume is not yet available, waiting..." + sleep 1 + timeleft=$((timeleft - 1)) + if [[ $timeleft == 0 ]]; then + die $LINENO "Timed out waiting for volume $CINDER_VOL2 to be available" + fi + else + break + fi + done + # Attach second volume and ensure it becomes in-use openstack server add volume $CINDER_SERVER $CINDER_VOL2 local timeleft=30