Browse code

Add/Overwrite default images in IMAGE_URLS and detect duplicates

IMAGE_URLS could be set both in localrc with customization or stackrc by
default. By setting DOWNLOAD_DEFAULT_IMAGES, user could choose to add
default images to IMAGE_URLS or overwrite them.

As uploading duplicate images will cause a "409 Conflict" error, a
duplicate detection will expose it earlier.

Care needs to be taken that you don't end up with a duplicate image, so
clean up Xen's README.

Depends-On: I6fbae12f950a03afab39f341132746d3db9f788c
Change-Id: I3ca4e576aa3fb8992c08ca44900a8c53dd4b4163
Closes-Bug: #1473432

John Hua authored on 2015/08/06 21:53:35
Showing 3 changed files
... ...
@@ -396,6 +396,24 @@ Set the following options to point to the master
396 396
         GLANCE_HOSTPORT=w.x.y.z:9292
397 397
         ENABLED_SERVICES=n-vol,n-cpu,n-net,n-api
398 398
 
399
+Guest Images
400
+------------
401
+
402
+Images provided in URLS via the comma-separated ``IMAGE_URLS``
403
+variable will be downloaded and uploaded to glance by DevStack.
404
+
405
+Default guest-images are predefined for each type of hypervisor and
406
+their testing-requirements in ``stack.sh``.  Setting
407
+``DOWNLOAD_DEFAULT_IMAGES=False`` will prevent DevStack downloading
408
+these default images; in that case, you will want to populate
409
+``IMAGE_URLS`` with sufficient images to satisfy testing-requirements.
410
+
411
+    ::
412
+
413
+        DOWNLOAD_DEFAULT_IMAGES=False
414
+        IMAGE_URLS="http://foo.bar.com/image.qcow,"
415
+        IMAGE_URLS+="http://foo.bar.com/image2.qcow"
416
+
399 417
 IP Version
400 418
 ----------
401 419
 
... ...
@@ -2,6 +2,11 @@
2 2
 #
3 3
 # stackrc
4 4
 #
5
+
6
+# ensure we don't re-source this in the same environment
7
+[[ -z "$_DEVSTACK_STACKRC" ]] || return 0
8
+declare -r _DEVSTACK_STACKRC=1
9
+
5 10
 # Find the other rc files
6 11
 RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)
7 12
 
... ...
@@ -560,40 +565,47 @@ CIRROS_ARCH=${CIRROS_ARCH:-"x86_64"}
560 560
 # Set default image based on ``VIRT_DRIVER`` and ``LIBVIRT_TYPE``, either of
561 561
 # which may be set in ``local.conf``.  Also allow ``DEFAULT_IMAGE_NAME`` and
562 562
 # ``IMAGE_URLS`` to be set in the `localrc` section of ``local.conf``.
563
-case "$VIRT_DRIVER" in
564
-    openvz)
565
-        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ubuntu-12.04-x86_64}
566
-        IMAGE_URLS=${IMAGE_URLS:-"http://download.openvz.org/template/precreated/ubuntu-12.04-x86_64.tar.gz"};;
567
-    libvirt)
568
-        case "$LIBVIRT_TYPE" in
569
-            lxc) # the cirros root disk in the uec tarball is empty, so it will not work for lxc
570
-                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-rootfs}
571
-                IMAGE_URLS=${IMAGE_URLS:-"http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-rootfs.img.gz"};;
572
-            *) # otherwise, use the uec style image (with kernel, ramdisk, disk)
573
-                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec}
574
-                IMAGE_URLS=${IMAGE_URLS:-"http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec.tar.gz"};;
575
-        esac
576
-        ;;
577
-    vsphere)
578
-        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.2-i386-disk.vmdk}
579
-        IMAGE_URLS=${IMAGE_URLS:-"http://partnerweb.vmware.com/programs/vmdkimage/cirros-0.3.2-i386-disk.vmdk"};;
580
-    xenserver)
581
-        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.4-x86_64-disk}
582
-        IMAGE_URLS=${IMAGE_URLS:-"http://ca.downloads.xensource.com/OpenStack/cirros-0.3.4-x86_64-disk.vhd.tgz"}
583
-        IMAGE_URLS+=",http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz";;
584
-    ironic)
585
-        # Ironic can do both partition and full disk images, depending on the driver
586
-        if [[ "$IRONIC_DEPLOY_DRIVER" == "agent_ssh" ]]; then
587
-            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-x86_64-disk}
588
-        else
589
-            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-x86_64-uec}
590
-        fi
591
-        IMAGE_URLS=${IMAGE_URLS:-"http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz"}
592
-        IMAGE_URLS+=",http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-disk.img";;
593
-    *) # Default to Cirros with kernel, ramdisk and disk image
594
-        DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec}
595
-        IMAGE_URLS=${IMAGE_URLS:-"http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec.tar.gz"};;
596
-esac
563
+DOWNLOAD_DEFAULT_IMAGES=$(trueorfalse True DOWNLOAD_DEFAULT_IMAGES)
564
+if [[ "$DOWNLOAD_DEFAULT_IMAGES" == "True" ]]; then
565
+    if [ -n $IMAGE_URLS ]; then
566
+        IMAGE_URLS+=","
567
+    fi
568
+    case "$VIRT_DRIVER" in
569
+        openvz)
570
+            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ubuntu-12.04-x86_64}
571
+            IMAGE_URLS+="http://download.openvz.org/template/precreated/ubuntu-12.04-x86_64.tar.gz";;
572
+        libvirt)
573
+            case "$LIBVIRT_TYPE" in
574
+                lxc) # the cirros root disk in the uec tarball is empty, so it will not work for lxc
575
+                    DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-rootfs}
576
+                    IMAGE_URLS+="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-rootfs.img.gz";;
577
+                *) # otherwise, use the uec style image (with kernel, ramdisk, disk)
578
+                    DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec}
579
+                    IMAGE_URLS+="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec.tar.gz";;
580
+                esac
581
+            ;;
582
+        vsphere)
583
+            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.2-i386-disk.vmdk}
584
+            IMAGE_URLS+="http://partnerweb.vmware.com/programs/vmdkimage/cirros-0.3.2-i386-disk.vmdk";;
585
+        xenserver)
586
+            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-0.3.4-x86_64-disk}
587
+            IMAGE_URLS+="http://ca.downloads.xensource.com/OpenStack/cirros-0.3.4-x86_64-disk.vhd.tgz"
588
+            IMAGE_URLS+=",http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz";;
589
+        ironic)
590
+            # Ironic can do both partition and full disk images, depending on the driver
591
+            if [[ "$IRONIC_DEPLOY_DRIVER" == "agent_ssh" ]]; then
592
+                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-x86_64-disk}
593
+            else
594
+                DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-x86_64-uec}
595
+            fi
596
+            IMAGE_URLS+="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-uec.tar.gz"
597
+            IMAGE_URLS+=",http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-x86_64-disk.img";;
598
+        *) # Default to Cirros with kernel, ramdisk and disk image
599
+            DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec}
600
+            IMAGE_URLS+="http://download.cirros-cloud.net/${CIRROS_VERSION}/cirros-${CIRROS_VERSION}-${CIRROS_ARCH}-uec.tar.gz";;
601
+    esac
602
+    DOWNLOAD_DEFAULT_IMAGES=False
603
+fi
597 604
 
598 605
 # Staging Area for New Images, have them here for at least 24hrs for nodepool
599 606
 # to cache them otherwise the failure rates in the gate are too high
... ...
@@ -606,6 +618,13 @@ if [[ "$PRECACHE_IMAGES" == "True" ]]; then
606 606
     fi
607 607
 fi
608 608
 
609
+# Detect duplicate values in IMAGE_URLS
610
+for image_url in ${IMAGE_URLS//,/ }; do
611
+    if [ $(echo "$IMAGE_URLS" | grep -o -F "$image_url" | wc -l) -gt 1 ]; then
612
+        die $LINENO "$image_url is duplicate, please remove it from IMAGE_URLS."
613
+    fi
614
+done
615
+
609 616
 # 10Gb default volume backing file size
610 617
 VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-10250M}
611 618
 
... ...
@@ -94,11 +94,6 @@ Of course, use real passwords if this machine is exposed.
94 94
     XENAPI_CONNECTION_URL="http://address_of_your_xenserver"
95 95
     VNCSERVER_PROXYCLIENT_ADDRESS=address_of_your_xenserver
96 96
 
97
-    # Download a vhd and a uec image
98
-    IMAGE_URLS="\
99
-    https://github.com/downloads/citrix-openstack/warehouse/cirros-0.3.0-x86_64-disk.vhd.tgz,\
100
-    http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-uec.tar.gz"
101
-
102 97
     # Explicitly set virt driver
103 98
     VIRT_DRIVER=xenserver
104 99