Browse code

Fix selection of image(s) tested by tempest.

The variable DEFAULT_IMAGE_NAME is set to 'cirros-0.3.0-x86_64-uec' by default.
This will cause configure_tempest to 'exit 1' and abort stack.sh if an image
with that name is not uploaded to glance. According to the relevant code
comment, this behaviour is incorrect. Updated code to match behaviour described
in comment: If image with name matching DEFAULT_IMAGE_NAME exists, use it for
both primary and secondary test image otherwise select first image and, if
available, second image listed by glance. Will still 'exit 1' if no images
are available at all (though it probably shouldn't).

Change-Id: I92773d4afd52cf533d16772ae2a087e23e206f8c
Fixes: bug #1092713

Cody A.W. Somerville authored on 2012/12/21 16:10:45
Showing 1 changed files
... ...
@@ -85,30 +85,34 @@ function configure_tempest() {
85 85
     # first image returned and set ``image_uuid_alt`` to the second,
86 86
     # if there is more than one returned...
87 87
     # ... Also ensure we only take active images, so we don't get snapshots in process
88
-    image_lines=`glance image-list`
89
-    IFS=$'\n\r'
90
-    images=""
91
-    for line in $image_lines; do
92
-        if [ -z $DEFAULT_IMAGE_NAME ]; then
93
-            images="$images `echo $line | grep -v "^\(ID\|+--\)" | grep -v "\(aki\|ari\)" | grep 'active' | cut -d' ' -f2`"
94
-        else
95
-            images="$images `echo $line | grep -v "^\(ID\|+--\)" | grep -v "\(aki\|ari\)" | grep 'active' | grep "$DEFAULT_IMAGE_NAME" | cut -d' ' -f2`"
88
+    declare -a images
89
+
90
+    while read -r IMAGE_NAME IMAGE_UUID; do
91
+        if [ "$IMAGE_NAME" = "$DEFAULT_IMAGE_NAME" ]; then
92
+            image_uuid="$IMAGE_UUID"
93
+            image_uuid_alt="$IMAGE_UUID"
96 94
         fi
97
-    done
98
-    # Create array of image UUIDs...
99
-    IFS=" "
100
-    images=($images)
101
-    num_images=${#images[*]}
102
-    echo "Found $num_images images"
103
-    if [[ $num_images -eq 0 ]]; then
104
-        echo "Found no valid images to use!"
105
-        exit 1
106
-    fi
107
-    image_uuid=${images[0]}
108
-    image_uuid_alt=$image_uuid
109
-    if [[ $num_images -gt 1 ]]; then
110
-        image_uuid_alt=${images[1]}
111
-    fi
95
+        images+=($IMAGE_UUID)
96
+    done < <(glance image-list --status=active | awk -F'|' '!/^(+--)|ID|aki|ari/ { print $3,$2 }')
97
+
98
+    case "${#images[*]}" in
99
+        0)
100
+            echo "Found no valid images to use!"
101
+            exit 1
102
+            ;;
103
+        1)
104
+            if [ -z "$image_uuid" ]; then
105
+                image_uuid=${images[0]}
106
+                image_uuid_alt=${images[0]}
107
+            fi
108
+            ;;
109
+        *)
110
+            if [ -z "$image_uuid" ]; then
111
+                image_uuid=${images[0]}
112
+                image_uuid_alt=${images[1]}
113
+            fi
114
+            ;;
115
+    esac
112 116
 
113 117
     # Create tempest.conf from tempest.conf.sample
114 118
     # copy every time, because the image UUIDS are going to change