From e956cd87c81c03705059519060e2a6d4037972c9 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Thu, 21 Mar 2019 17:33:23 +0000
Subject: [PATCH] Wait for cinder volume to become available in CI

Fixes a race condition where sometimes a volume would still be in the
'creating' state when trying to attach it to a server.

Invalid volume: Volume <id> status must be available or downloading to
reserve, but the current status is creating.

Change-Id: I0687ddfd78c384650cb361ff07aa64c5c3806a93
---
 tests/test-openstack.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tests/test-openstack.sh b/tests/test-openstack.sh
index cbffebe833..4f6d6d1248 100755
--- a/tests/test-openstack.sh
+++ b/tests/test-openstack.sh
@@ -27,6 +27,17 @@ function test_openstack_logged {
     if [[ $ACTION = "ceph" ]] || [[ $ACTION == "cinder-lvm" ]]; then
         echo "TESTING: Cinder volume attachment"
         openstack volume create --size 2 test_volume
+        attempt=1
+        while [[ $(openstack volume show test_volume -f value -c status) != "available" ]]; do
+            echo "Volume not available yet"
+            attempt=$((attempt+1))
+            if [[ $attempt -eq 10 ]]; then
+                echo "Volume failed to become available"
+                openstack volume show test_volume
+                return 1
+            fi
+            sleep 10
+        done
         openstack server add volume kolla_boot_test test_volume --device /dev/vdb
         attempt=1
         while [[ $(openstack volume show test_volume -f value -c status) != "in-use" ]]; do