Browse code

Increase exercise robustness

* increase some timeouts
* tolerate existing security groups and rules
* add optional DEFAULT_IMAGE_NAME to select the image to boot
* fix image lists via glance

Change-Id: I31ae743e602f69a2c9f872273273f542fc4afda3

Dean Troyer authored on 2012/01/11 06:34:34
Showing 4 changed files
... ...
@@ -20,6 +20,18 @@ pushd $(cd $(dirname "$0")/.. && pwd)
20 20
 source ./openrc
21 21
 popd
22 22
 
23
+# Max time to wait while vm goes from build to active state
24
+ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
25
+
26
+# Max time till the vm is bootable
27
+BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
28
+
29
+# Max time to wait for proper association and dis-association.
30
+ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
31
+
32
+# Instance type to create
33
+DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
34
+
23 35
 # Find a machine image to boot
24 36
 IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
25 37
 
... ...
@@ -27,10 +39,15 @@ IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
27 27
 SECGROUP=euca_secgroup
28 28
 
29 29
 # Add a secgroup
30
-euca-add-group -d description $SECGROUP
30
+if ! euca-describe-group | grep -q $SECGROUP; then
31
+    euca-add-group -d "$SECGROUP description" $SECGROUP
32
+    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-group | grep -q $SECGROUP; do sleep 1; done"; then
33
+        echo "Security group not created"
34
+        exit 1
35
+    fi
36
+fi
31 37
 
32 38
 # Launch it
33
-DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
34 39
 INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
35 40
 
36 41
 # Assure it has booted within a reasonable time
... ...
@@ -42,15 +59,13 @@ fi
42 42
 # Allocate floating address
43 43
 FLOATING_IP=`euca-allocate-address | cut -f2`
44 44
 
45
-# Release floating address
45
+# Associate floating address
46 46
 euca-associate-address -i $INSTANCE $FLOATING_IP
47 47
 
48
-
49 48
 # Authorize pinging
50 49
 euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
51 50
 
52 51
 # Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
53
-ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
54 52
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
55 53
     echo "Couldn't ping server with floating ip"
56 54
     exit 1
... ...
@@ -65,6 +80,12 @@ euca-delete-group $SECGROUP
65 65
 # Release floating address
66 66
 euca-disassociate-address $FLOATING_IP
67 67
 
68
+# Wait just a tick for everything above to complete so release doesn't fail
69
+if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
70
+    echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
71
+    exit 1
72
+fi
73
+
68 74
 # Release floating address
69 75
 euca-release-address $FLOATING_IP
70 76
 
... ...
@@ -24,9 +24,28 @@ pushd $(cd $(dirname "$0")/.. && pwd)
24 24
 source ./openrc
25 25
 popd
26 26
 
27
-# Set some defaults
27
+# Max time to wait while vm goes from build to active state
28
+ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
29
+
30
+# Max time till the vm is bootable
31
+BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
32
+
33
+# Max time to wait for proper association and dis-association.
34
+ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
35
+
36
+# Instance type to create
37
+DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
28 38
 
39
+# Boot this image, use first AMi image if unset
40
+DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
41
+
42
+# Security group name
43
+SECGROUP=${SECGROUP:-test_secgroup}
44
+
45
+# Default floating IP pool name
29 46
 DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
47
+
48
+# Additional floating IP pool and range
30 49
 TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
31 50
 
32 51
 # Get a token for clients that don't support service catalog
... ...
@@ -51,28 +70,32 @@ nova list
51 51
 nova image-list
52 52
 
53 53
 # But we recommend using glance directly
54
-glance -A $TOKEN index
54
+glance -f -A $TOKEN index
55 55
 
56
-# Let's grab the id of the first AMI image to launch
57
-IMAGE=`glance -A $TOKEN index | egrep ami | cut -d" " -f1`
56
+# Grab the id of the image to launch
57
+IMAGE=`glance -f -A $TOKEN index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
58 58
 
59 59
 # Security Groups
60 60
 # ---------------
61
-SECGROUP=test_secgroup
62 61
 
63 62
 # List of secgroups:
64 63
 nova secgroup-list
65 64
 
66 65
 # Create a secgroup
67
-nova secgroup-create $SECGROUP "test_secgroup description"
66
+if ! nova secgroup-list | grep -q $SECGROUP; then
67
+    nova secgroup-create $SECGROUP "$SECGROUP description"
68
+    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
69
+        echo "Security group not created"
70
+        exit 1
71
+    fi
72
+fi
68 73
 
69
-# determine flavor
70
-# ----------------
74
+# determinine instance type
75
+# -------------------------
71 76
 
72
-# List of flavors:
77
+# List of instance types:
73 78
 nova flavor-list
74 79
 
75
-DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
76 80
 INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
77 81
 if [[ -z "$INSTANCE_TYPE" ]]; then
78 82
     # grab the first flavor in the list to launch if default doesn't exist
... ...
@@ -81,7 +104,7 @@ fi
81 81
 
82 82
 NAME="myserver"
83 83
 
84
-nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP
84
+VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
85 85
 
86 86
 # Testing
87 87
 # =======
... ...
@@ -93,23 +116,14 @@ nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGRO
93 93
 # Waiting for boot
94 94
 # ----------------
95 95
 
96
-# Max time to wait while vm goes from build to active state
97
-ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-10}
98
-
99
-# Max time till the vm is bootable
100
-BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
101
-
102
-# Max time to wait for proper association and dis-association.
103
-ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
104
-
105 96
 # check that the status is active within ACTIVE_TIMEOUT seconds
106
-if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $NAME | grep status | grep -q ACTIVE; do sleep 1; done"; then
97
+if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
107 98
     echo "server didn't become active!"
108 99
     exit 1
109 100
 fi
110 101
 
111 102
 # get the IP of the server
112
-IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
103
+IP=`nova show $VM_UUID | grep "private network" | cut -d"|" -f3`
113 104
 
114 105
 # for single node deployments, we can ping private ips
115 106
 MULTI_HOST=${MULTI_HOST:-0}
... ...
@@ -129,8 +143,14 @@ fi
129 129
 # Security Groups & Floating IPs
130 130
 # ------------------------------
131 131
 
132
-# allow icmp traffic (ping)
133
-nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
132
+if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
133
+    # allow icmp traffic (ping)
134
+    nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
135
+    if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list-rules $SECGROUP | grep -q icmp; do sleep 1; done"; then
136
+        echo "Security group rule not created"
137
+        exit 1
138
+    fi
139
+fi
134 140
 
135 141
 # List rules for a secgroup
136 142
 nova secgroup-list-rules $SECGROUP
... ...
@@ -145,7 +165,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $
145 145
 fi
146 146
 
147 147
 # add floating ip to our server
148
-nova add-floating-ip $NAME $FLOATING_IP
148
+nova add-floating-ip $VM_UUID $FLOATING_IP
149 149
 
150 150
 # test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
151 151
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -153,7 +173,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
153 153
     exit 1
154 154
 fi
155 155
 
156
-# Allocate an IP from it
156
+# Allocate an IP from second floating pool
157 157
 TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | cut -d '|' -f2`
158 158
 
159 159
 # list floating addresses
... ...
@@ -182,11 +202,10 @@ nova floating-ip-delete $FLOATING_IP
182 182
 nova floating-ip-delete $TEST_FLOATING_IP
183 183
 
184 184
 # shutdown the server
185
-nova delete $NAME
185
+nova delete $VM_UUID
186 186
 
187 187
 # Delete a secgroup
188 188
 nova secgroup-delete $SECGROUP
189 189
 
190 190
 # FIXME: validate shutdown within 5 seconds
191 191
 # (nova show $NAME returns 1 or status != ACTIVE)?
192
-
... ...
@@ -19,6 +19,21 @@ pushd $(cd $(dirname "$0")/.. && pwd)
19 19
 source ./openrc
20 20
 popd
21 21
 
22
+# Max time to wait while vm goes from build to active state
23
+ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
24
+
25
+# Max time till the vm is bootable
26
+BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
27
+
28
+# Max time to wait for proper association and dis-association.
29
+ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
30
+
31
+# Instance type to create
32
+DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
33
+
34
+# Boot this image, use first AMi image if unset
35
+DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
36
+
22 37
 # Get a token for clients that don't support service catalog
23 38
 # ==========================================================
24 39
 
... ...
@@ -41,10 +56,10 @@ nova list
41 41
 nova image-list
42 42
 
43 43
 # But we recommend using glance directly
44
-glance -A $TOKEN index
44
+glance -f -A $TOKEN index
45 45
 
46
-# Let's grab the id of the first AMI image to launch
47
-IMAGE=`glance -A $TOKEN index | egrep ami | head -1 | cut -d" " -f1`
46
+# Grab the id of the image to launch
47
+IMAGE=`glance -f -A $TOKEN index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
48 48
 
49 49
 # determinine instance type
50 50
 # -------------------------
... ...
@@ -52,7 +67,6 @@ IMAGE=`glance -A $TOKEN index | egrep ami | head -1 | cut -d" " -f1`
52 52
 # List of instance types:
53 53
 nova flavor-list
54 54
 
55
-DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
56 55
 INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
57 56
 if [[ -z "$INSTANCE_TYPE" ]]; then
58 57
     # grab the first flavor in the list to launch if default doesn't exist
... ...
@@ -73,24 +87,14 @@ VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_group
73 73
 # Waiting for boot
74 74
 # ----------------
75 75
 
76
-# Max time to wait while vm goes from build to active state
77
-ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
78
-
79
-# Max time till the vm is bootable
80
-BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
81
-
82
-# Max time to wait for proper association and dis-association.
83
-ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
84
-
85 76
 # check that the status is active within ACTIVE_TIMEOUT seconds
86
-if ! timeout $BOOT_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
77
+if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
87 78
     echo "server didn't become active!"
88 79
     exit 1
89 80
 fi
90 81
 
91 82
 # get the IP of the server
92 83
 IP=`nova show $VM_UUID | grep "private network" | cut -d"|" -f3`
93
-#VM_UUID=`nova list | grep $NAME | head -1 | cut -d'|' -f2 | sed 's/ //g'`
94 84
 
95 85
 # for single node deployments, we can ping private ips
96 86
 MULTI_HOST=${MULTI_HOST:-0}
... ...
@@ -53,13 +53,13 @@ export EC2_SECRET_KEY=${ADMIN_PASSWORD:-secrete}
53 53
 # export NOVACLIENT_DEBUG=1
54 54
 
55 55
 # Max time till the vm is bootable
56
-export BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
56
+export BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
57 57
 
58 58
 # Max time to wait while vm goes from build to active state
59
-export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-10}
59
+export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
60 60
 
61 61
 # Max time from run instance command until it is running
62 62
 export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
63 63
 
64 64
 # Max time to wait for proper IP association and dis-association.
65
-export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
65
+export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}