Browse code

Avoid uploading trove guest image twice

When creating the trove datastore, get the guest image id from glance.
The trove guest image gets uploaded along with all the other
images specified in $IMAGE_URLS. It is not necessary to upload
it again in init_trove.

Also: add xenapi case to stackrc for trove guest image

Closes-Bug: 1339818
Change-Id: I2973af27ab93182fcd674f874daba1036d767d52

Greg Lucas authored on 2014/07/10 02:30:38
Showing 2 changed files
... ...
@@ -203,10 +203,21 @@ function init_trove {
203 203
     # Initialize the trove database
204 204
     $TROVE_BIN_DIR/trove-manage db_sync
205 205
 
206
-    # Upload the trove-guest image to glance
207
-    TROVE_GUEST_IMAGE_ID=$(upload_image $TROVE_GUEST_IMAGE_URL $TOKEN | grep ' id ' | get_field 2)
206
+    # If no guest image is specified, skip remaining setup
207
+    [ -z "$TROVE_GUEST_IMAGE_URL"] && return 0
208
+
209
+    # Find the glance id for the trove guest image
210
+    # The image is uploaded by stack.sh -- see $IMAGE_URLS handling
211
+    GUEST_IMAGE_NAME=$(basename "$TROVE_GUEST_IMAGE_URL")
212
+    GUEST_IMAGE_NAME=${GUEST_IMAGE_NAME%.*}
213
+    TROVE_GUEST_IMAGE_ID=$(glance --os-auth-token $TOKEN --os-image-url http://$GLANCE_HOSTPORT image-list | grep "${GUEST_IMAGE_NAME}" | get_field 1)
214
+    if [ -z "$TROVE_GUEST_IMAGE_ID" ]; then
215
+        # If no glance id is found, skip remaining setup
216
+        echo "Datastore ${TROVE_DATASTORE_TYPE} will not be created: guest image ${GUEST_IMAGE_NAME} not found."
217
+        return 1
218
+    fi
208 219
 
209
-    # Initialize appropriate datastores / datastore versions
220
+    # Now that we have the guest image id, initialize appropriate datastores / datastore versions
210 221
     $TROVE_BIN_DIR/trove-manage datastore_update "$TROVE_DATASTORE_TYPE" ""
211 222
     $TROVE_BIN_DIR/trove-manage datastore_version_update "$TROVE_DATASTORE_TYPE" "$TROVE_DATASTORE_VERSION" "$TROVE_DATASTORE_TYPE" \
212 223
         "$TROVE_GUEST_IMAGE_ID" "$TROVE_DATASTORE_PACKAGE" 1
... ...
@@ -384,7 +384,7 @@ fi
384 384
 # Trove needs a custom image for it's work
385 385
 if [[ "$ENABLED_SERVICES" =~ 'tr-api' ]]; then
386 386
     case "$VIRT_DRIVER" in
387
-        libvirt|baremetal|ironic)
387
+        libvirt|baremetal|ironic|xenapi)
388 388
             TROVE_GUEST_IMAGE_URL=${TROVE_GUEST_IMAGE_URL:-"http://tarballs.openstack.org/trove/images/ubuntu_mysql.qcow2/ubuntu_mysql.qcow2"}
389 389
             IMAGE_URLS+=",${TROVE_GUEST_IMAGE_URL}"
390 390
             ;;