Browse code

Simplify die_if_error

* Replace die_if_error() with the simpler die()
* Attempt to clean up unnecessary trace output
* Formatting cleanups on all exercise scripts

Change-Id: I72a542b3a59ee9bf12bee6bcc605edd7579205e0

Dean Troyer authored on 2012/03/17 06:16:56
Showing 12 changed files
... ...
@@ -1,6 +1,13 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-source ./stackrc
3
+# **exercise.sh**
4
+
5
+# Keep track of the current devstack directory.
6
+TOP_DIR=$(cd $(dirname "$0") && pwd)
7
+
8
+# Load local configuration
9
+source $TOP_DIR/stackrc
10
+
4 11
 # Run everything in the exercises/ directory that isn't explicitly disabled
5 12
 
6 13
 # comma separated list of script basenames to skip
... ...
@@ -21,9 +28,9 @@ for script in $basenames; do
21 21
     if [[ "$SKIP_EXERCISES" =~ $script ]] ; then
22 22
         skips="$skips $script"
23 23
     else
24
-        echo =========================
24
+        echo "====================================================================="
25 25
         echo Running $script
26
-        echo =========================
26
+        echo "====================================================================="
27 27
         $EXERCISE_DIR/$script.sh
28 28
         if [[ $? -ne 0 ]] ; then
29 29
             failures="$failures $script"
... ...
@@ -34,8 +41,7 @@ for script in $basenames; do
34 34
 done
35 35
 
36 36
 # output status of exercise run
37
-echo =========================
38
-echo =========================
37
+echo "====================================================================="
39 38
 for script in $skips; do
40 39
     echo SKIP $script
41 40
 done
... ...
@@ -45,6 +51,7 @@ done
45 45
 for script in $failures; do
46 46
     echo FAILED $script
47 47
 done
48
+echo "====================================================================="
48 49
 
49 50
 if [ -n "$failures" ] ; then
50 51
     exit 1
... ...
@@ -8,9 +8,9 @@
8 8
 #  *  Format and install an os onto the volume
9 9
 #  *  Detach volume from builder, and then boot volume-backed instance
10 10
 
11
-echo "**************************************************"
11
+echo "*********************************************************************"
12 12
 echo "Begin DevStack Exercise: $0"
13
-echo "**************************************************"
13
+echo "*********************************************************************"
14 14
 
15 15
 # This script exits on an error so that errors don't compound and you see
16 16
 # only the first error that occured.
... ...
@@ -46,9 +46,12 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
46 46
 # Default floating IP pool name
47 47
 DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
48 48
 
49
+
50
+# Launching servers
51
+# =================
52
+
49 53
 # Grab the id of the image to launch
50 54
 IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
51
-
52 55
 die_if_not_set IMAGE "Failure getting image"
53 56
 
54 57
 # Instance and volume names
... ...
@@ -88,7 +91,8 @@ nova keypair-add $KEY_NAME > $KEY_FILE
88 88
 chmod 600 $KEY_FILE
89 89
 
90 90
 # Boot our instance
91
-VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
91
+VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | get_field 2`
92
+die_if_not_set VM_UUID "Failure launching $INSTANCE_NAME"
92 93
 
93 94
 # check that the status is active within ACTIVE_TIMEOUT seconds
94 95
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
... ...
@@ -105,7 +109,7 @@ if [ "$FREE_ALL_FLOATING_IPS" = "True" ]; then
105 105
 fi
106 106
 
107 107
 # Allocate floating ip
108
-FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | cut -d '|' -f2 | tr -d ' '`
108
+FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
109 109
 
110 110
 # Make sure the ip gets allocated
111 111
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -133,7 +137,7 @@ fi
133 133
 
134 134
 # FIXME (anthony) - python-novaclient should accept a volume_name for the attachment param?
135 135
 DEVICE=/dev/vdb
136
-VOLUME_ID=`nova volume-list | grep $VOL_NAME  | cut -d '|' -f 2 | tr -d ' '`
136
+VOLUME_ID=`nova volume-list | grep $VOL_NAME  | get_field 1`
137 137
 nova volume-attach $INSTANCE_NAME $VOLUME_ID $DEVICE
138 138
 
139 139
 # Wait till volume is attached
... ...
@@ -192,7 +196,8 @@ nova volume-detach $INSTANCE_NAME $VOLUME_ID
192 192
 # The format of mapping is:
193 193
 # <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
194 194
 # Leaving the middle two fields blank appears to do-the-right-thing
195
-VOL_VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block_device_mapping vda=$VOLUME_ID:::0 --security_groups=$SECGROUP --key_name $KEY_NAME $VOL_INSTANCE_NAME | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
195
+VOL_VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block_device_mapping vda=$VOLUME_ID:::0 --security_groups=$SECGROUP --key_name $KEY_NAME $VOL_INSTANCE_NAME | grep ' id ' | get_field 2`
196
+die_if_not_set VOL_VM_UUID "Failure launching $VOL_INSTANCE_NAME"
196 197
 
197 198
 # Check that the status is active within ACTIVE_TIMEOUT seconds
198 199
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VOL_VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
... ...
@@ -201,7 +206,7 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VOL_VM_UUID | grep status
201 201
 fi
202 202
 
203 203
 # Add floating ip to our server
204
-nova remove-floating-ip  $VM_UUID $FLOATING_IP
204
+nova remove-floating-ip $VM_UUID $FLOATING_IP
205 205
 
206 206
 # Gratuitous sleep, probably hiding a race condition :/
207 207
 sleep 1
... ...
@@ -221,7 +226,8 @@ echo "success!"
221 221
 EOF
222 222
 
223 223
 # Delete volume backed instance
224
-nova delete $VOL_INSTANCE_NAME
224
+nova delete $VOL_INSTANCE_NAME || \
225
+    die "Failure deleting instance volume $VOL_INSTANCE_NAME"
225 226
 
226 227
 # Wait till our volume is no longer in-use
227 228
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
... ...
@@ -230,10 +236,12 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME |
230 230
 fi
231 231
 
232 232
 # Delete the volume
233
-nova volume-delete $VOL_NAME
233
+nova volume-delete $VOL_NAME || \
234
+    die "Failure deleting volume $VOLUME_NAME"
234 235
 
235 236
 # Delete instance
236
-nova delete $INSTANCE_NAME
237
+nova delete $INSTANCE_NAME || \
238
+    die "Failure deleting instance $INSTANCE_NAME"
237 239
 
238 240
 # Wait for termination
239 241
 if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1; done"; then
... ...
@@ -242,12 +250,14 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1;
242 242
 fi
243 243
 
244 244
 # De-allocate the floating ip
245
-nova floating-ip-delete $FLOATING_IP
245
+nova floating-ip-delete $FLOATING_IP || \
246
+    die "Failure deleting floating IP $FLOATING_IP"
246 247
 
247
-# Delete secgroup
248
-nova secgroup-delete $SECGROUP
248
+# Delete a secgroup
249
+nova secgroup-delete $SECGROUP || \
250
+    die "Failure deleting security group $SECGROUP"
249 251
 
250 252
 set +o xtrace
251
-echo "**************************************************"
252
-echo "End DevStack Exercise: $0"
253
-echo "**************************************************"
253
+echo "*********************************************************************"
254
+echo "SUCCESS: End DevStack Exercise: $0"
255
+echo "*********************************************************************"
... ...
@@ -1,11 +1,13 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+# **bundle.sh**
4
+
3 5
 # we will use the ``euca2ools`` cli tool that wraps the python boto
4
-# library to test ec2 compatibility
6
+# library to test ec2 bundle upload compatibility
5 7
 
6
-echo "**************************************************"
8
+echo "*********************************************************************"
7 9
 echo "Begin DevStack Exercise: $0"
8
-echo "**************************************************"
10
+echo "*********************************************************************"
9 11
 
10 12
 # This script exits on an error so that errors don't compound and you see
11 13
 # only the first error that occured.
... ...
@@ -46,12 +48,9 @@ REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
46 46
 BUCKET=testbucket
47 47
 IMAGE=bundle.img
48 48
 truncate -s 5M /tmp/$IMAGE
49
-euca-bundle-image -i /tmp/$IMAGE
50
-die_if_error "Failure bundling image $IMAGE"
51
-
49
+euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE"
52 50
 
53
-euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
54
-die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
51
+euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET"
55 52
 
56 53
 AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
57 54
 die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
... ...
@@ -63,10 +62,9 @@ if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | g
63 63
 fi
64 64
 
65 65
 # Clean up
66
-euca-deregister $AMI
67
-die_if_error "Failure deregistering $AMI"
66
+euca-deregister $AMI || die "Failure deregistering $AMI"
68 67
 
69 68
 set +o xtrace
70
-echo "**************************************************"
71
-echo "End DevStack Exercise: $0"
72
-echo "**************************************************"
69
+echo "*********************************************************************"
70
+echo "SUCCESS: End DevStack Exercise: $0"
71
+echo "*********************************************************************"
... ...
@@ -2,9 +2,9 @@
2 2
 
3 3
 # Test OpenStack client authentication aguemnts handling
4 4
 
5
-echo "**************************************************"
5
+echo "*********************************************************************"
6 6
 echo "Begin DevStack Exercise: $0"
7
-echo "**************************************************"
7
+echo "*********************************************************************"
8 8
 
9 9
 # Settings
10 10
 # ========
... ...
@@ -135,8 +135,8 @@ report "Nova" $STATUS_NOVA
135 135
 report "Glance" $STATUS_GLANCE
136 136
 report "Swift" $STATUS_SWIFT
137 137
 
138
-echo "**************************************************"
139
-echo "End DevStack Exercise: $0"
140
-echo "**************************************************"
138
+echo "*********************************************************************"
139
+echo "SUCCESS: End DevStack Exercise: $0"
140
+echo "*********************************************************************"
141 141
 
142 142
 exit $RETURN
... ...
@@ -2,9 +2,9 @@
2 2
 
3 3
 # Test OpenStack client enviroment variable handling
4 4
 
5
-echo "**************************************************"
5
+echo "*********************************************************************"
6 6
 echo "Begin DevStack Exercise: $0"
7
-echo "**************************************************"
7
+echo "*********************************************************************"
8 8
 
9 9
 # Verify client workage
10 10
 VERIFY=${1:-""}
... ...
@@ -149,8 +149,8 @@ report "EC2" $STATUS_EC2
149 149
 report "Glance" $STATUS_GLANCE
150 150
 report "Swift" $STATUS_SWIFT
151 151
 
152
-echo "**************************************************"
153
-echo "End DevStack Exercise: $0"
154
-echo "**************************************************"
152
+echo "*********************************************************************"
153
+echo "SUCCESS: End DevStack Exercise: $0"
154
+echo "*********************************************************************"
155 155
 
156 156
 exit $RETURN
... ...
@@ -1,11 +1,13 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+# **euca.sh**
4
+
3 5
 # we will use the ``euca2ools`` cli tool that wraps the python boto
4 6
 # library to test ec2 compatibility
5 7
 
6
-echo "**************************************************"
8
+echo "*********************************************************************"
7 9
 echo "Begin DevStack Exercise: $0"
8
-echo "**************************************************"
10
+echo "*********************************************************************"
9 11
 
10 12
 # This script exits on an error so that errors don't compound and you see
11 13
 # only the first error that occured.
... ...
@@ -15,6 +17,7 @@ set -o errexit
15 15
 # an error.  It is also useful for following allowing as the install occurs.
16 16
 set -o xtrace
17 17
 
18
+
18 19
 # Settings
19 20
 # ========
20 21
 
... ...
@@ -34,6 +37,10 @@ source $TOP_DIR/exerciserc
34 34
 # Instance type to create
35 35
 DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
36 36
 
37
+
38
+# Launching a server
39
+# ==================
40
+
37 41
 # Find a machine image to boot
38 42
 IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
39 43
 
... ...
@@ -64,12 +71,12 @@ FLOATING_IP=`euca-allocate-address | cut -f2`
64 64
 die_if_not_set FLOATING_IP "Failure allocating floating IP"
65 65
 
66 66
 # Associate floating address
67
-euca-associate-address -i $INSTANCE $FLOATING_IP
68
-die_if_error "Failure associating address $FLOATING_IP to $INSTANCE"
67
+euca-associate-address -i $INSTANCE $FLOATING_IP || \
68
+    die "Failure associating address $FLOATING_IP to $INSTANCE"
69 69
 
70 70
 # Authorize pinging
71
-euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
72
-die_if_error "Failure authorizing rule in $SECGROUP"
71
+euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
72
+    die "Failure authorizing rule in $SECGROUP"
73 73
 
74 74
 # Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
75 75
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -78,12 +85,12 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
78 78
 fi
79 79
 
80 80
 # Revoke pinging
81
-euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
82
-die_if_error "Failure revoking rule in $SECGROUP"
81
+euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
82
+    die "Failure revoking rule in $SECGROUP"
83 83
 
84 84
 # Release floating address
85
-euca-disassociate-address $FLOATING_IP
86
-die_if_error "Failure disassociating address $FLOATING_IP"
85
+euca-disassociate-address $FLOATING_IP || \
86
+    die "Failure disassociating address $FLOATING_IP"
87 87
 
88 88
 # Wait just a tick for everything above to complete so release doesn't fail
89 89
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -92,8 +99,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INS
92 92
 fi
93 93
 
94 94
 # Release floating address
95
-euca-release-address $FLOATING_IP
96
-die_if_error "Failure releasing address $FLOATING_IP"
95
+euca-release-address $FLOATING_IP || \
96
+    die "Failure releasing address $FLOATING_IP"
97 97
 
98 98
 # Wait just a tick for everything above to complete so terminate doesn't fail
99 99
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -102,8 +109,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $
102 102
 fi
103 103
 
104 104
 # Terminate instance
105
-euca-terminate-instances $INSTANCE
106
-die_if_error "Failure terminating instance $INSTANCE"
105
+euca-terminate-instances $INSTANCE || \
106
+    die "Failure terminating instance $INSTANCE"
107 107
 
108 108
 # Assure it has terminated within a reasonable time
109 109
 if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
... ...
@@ -112,10 +119,10 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE |
112 112
 fi
113 113
 
114 114
 # Delete group
115
-euca-delete-group $SECGROUP
116
-die_if_error "Failure deleting security group $SECGROUP"
115
+euca-delete-group $SECGROUP || \
116
+    die "Failure deleting security group $SECGROUP"
117 117
 
118 118
 set +o xtrace
119
-echo "**************************************************"
120
-echo "End DevStack Exercise: $0"
121
-echo "**************************************************"
119
+echo "*********************************************************************"
120
+echo "SUCCESS: End DevStack Exercise: $0"
121
+echo "*********************************************************************"
... ...
@@ -1,15 +1,13 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
-# **exercise.sh** - using the cloud can be fun
3
+# **floating_ips.sh** - using the cloud can be fun
4 4
 
5 5
 # we will use the ``nova`` cli tool provided by the ``python-novaclient``
6
-# package
7
-#
6
+# package to work out the instance connectivity
8 7
 
9
-
10
-echo "**************************************************"
8
+echo "*********************************************************************"
11 9
 echo "Begin DevStack Exercise: $0"
12
-echo "**************************************************"
10
+echo "*********************************************************************"
13 11
 
14 12
 # This script exits on an error so that errors don't compound and you see
15 13
 # only the first error that occured.
... ...
@@ -51,6 +49,7 @@ DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
51 51
 # Additional floating IP pool and range
52 52
 TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
53 53
 
54
+
54 55
 # Launching a server
55 56
 # ==================
56 57
 
... ...
@@ -162,8 +161,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $
162 162
 fi
163 163
 
164 164
 # add floating ip to our server
165
-nova add-floating-ip $VM_UUID $FLOATING_IP
166
-die_if_error "Failure adding floating IP $FLOATING_IP to $NAME"
165
+nova add-floating-ip $VM_UUID $FLOATING_IP || \
166
+    die "Failure adding floating IP $FLOATING_IP to $NAME"
167 167
 
168 168
 # test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
169 169
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
... ...
@@ -182,8 +181,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep $TES
182 182
 fi
183 183
 
184 184
 # dis-allow icmp traffic (ping)
185
-nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0
186
-die_if_error "Failure deleting security group rule from $SECGROUP"
185
+nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deleting security group rule from $SECGROUP"
187 186
 
188 187
 # FIXME (anthony): make xs support security groups
189 188
 if [ "$VIRT_DRIVER" != "xenserver" ]; then
... ...
@@ -196,16 +194,13 @@ if [ "$VIRT_DRIVER" != "xenserver" ]; then
196 196
 fi
197 197
 
198 198
 # de-allocate the floating ip
199
-nova floating-ip-delete $FLOATING_IP
200
-die_if_error "Failure deleting floating IP $FLOATING_IP"
199
+nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
201 200
 
202 201
 # Delete second floating IP
203
-nova floating-ip-delete $TEST_FLOATING_IP
204
-die_if_error "Failure deleting floating IP $TEST_FLOATING_IP"
202
+nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
205 203
 
206 204
 # shutdown the server
207
-nova delete $VM_UUID
208
-die_if_error "Failure deleting instance $NAME"
205
+nova delete $VM_UUID || die "Failure deleting instance $NAME"
209 206
 
210 207
 # make sure the VM shuts down within a reasonable time
211 208
 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
... ...
@@ -214,10 +209,9 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while nova show $VM_UUID | grep status |
214 214
 fi
215 215
 
216 216
 # Delete a secgroup
217
-nova secgroup-delete $SECGROUP
218
-die_if_error "Failure deleting security group $SECGROUP"
217
+nova secgroup-delete $SECGROUP || die "Failure deleting security group $SECGROUP"
219 218
 
220 219
 set +o xtrace
221
-echo "**************************************************"
222
-echo "End DevStack Exercise: $0"
223
-echo "**************************************************"
220
+echo "*********************************************************************"
221
+echo "SUCCESS: End DevStack Exercise: $0"
222
+echo "*********************************************************************"
... ...
@@ -1,10 +1,12 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+# **swift.sh**
4
+
3 5
 # Test swift via the command line tools that ship with it.
4 6
 
5
-echo "**************************************************"
7
+echo "*********************************************************************"
6 8
 echo "Begin DevStack Exercise: $0"
7
-echo "**************************************************"
9
+echo "*********************************************************************"
8 10
 
9 11
 # This script exits on an error so that errors don't compound and you see
10 12
 # only the first error that occured.
... ...
@@ -39,27 +41,22 @@ CONTAINER=ex-swift
39 39
 # =============
40 40
 
41 41
 # Check if we have to swift via keystone
42
-swift stat
43
-die_if_error "Failure geting status"
42
+swift stat || die "Failure geting status"
44 43
 
45 44
 # We start by creating a test container
46
-swift post $CONTAINER
47
-die_if_error "Failure creating container $CONTAINER"
45
+swift post $CONTAINER || die "Failure creating container $CONTAINER"
48 46
 
49 47
 # add some files into it.
50
-swift upload $CONTAINER /etc/issue
51
-die_if_error "Failure uploading file to container $CONTAINER"
48
+swift upload $CONTAINER /etc/issue || die "Failure uploading file to container $CONTAINER"
52 49
 
53 50
 # list them
54
-swift list $CONTAINER
55
-die_if_error "Failure listing contents of container $CONTAINER"
51
+swift list $CONTAINER || die "Failure listing contents of container $CONTAINER"
56 52
 
57 53
 # And we may want to delete them now that we have tested that
58 54
 # everything works.
59
-swift delete $CONTAINER
60
-die_if_error "Failure deleting container $CONTAINER"
55
+swift delete $CONTAINER || die "Failure deleting container $CONTAINER"
61 56
 
62 57
 set +o xtrace
63
-echo "**************************************************"
64
-echo "End DevStack Exercise: $0"
65
-echo "**************************************************"
58
+echo "*********************************************************************"
59
+echo "SUCCESS: End DevStack Exercise: $0"
60
+echo "*********************************************************************"
... ...
@@ -1,10 +1,12 @@
1 1
 #!/usr/bin/env bash
2 2
 
3
+# **volumes.sh**
4
+
3 5
 # Test nova volumes with the nova command from python-novaclient
4 6
 
5
-echo "**************************************************"
7
+echo "*********************************************************************"
6 8
 echo "Begin DevStack Exercise: $0"
7
-echo "**************************************************"
9
+echo "*********************************************************************"
8 10
 
9 11
 # This script exits on an error so that errors don't compound and you see
10 12
 # only the first error that occured.
... ...
@@ -37,6 +39,7 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
37 37
 # Boot this image, use first AMi image if unset
38 38
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
39 39
 
40
+
40 41
 # Launching a server
41 42
 # ==================
42 43
 
... ...
@@ -136,8 +139,8 @@ die_if_not_set VOL_ID "Failure retrieving volume ID for $VOL_NAME"
136 136
 
137 137
 # Attach to server
138 138
 DEVICE=/dev/vdb
139
-nova volume-attach $VM_UUID $VOL_ID $DEVICE
140
-die_if_error "Failure attaching volume $VOL_NAME to $NAME"
139
+nova volume-attach $VM_UUID $VOL_ID $DEVICE || \
140
+    die "Failure attaching volume $VOL_NAME to $NAME"
141 141
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then
142 142
     echo "Volume $VOL_NAME not attached to $NAME"
143 143
     exit 1
... ...
@@ -151,26 +154,23 @@ if [[ "$VOL_ATTACH" != $VM_UUID ]]; then
151 151
 fi
152 152
 
153 153
 # Detach volume
154
-nova volume-detach $VM_UUID $VOL_ID
155
-die_if_error "Failure detaching volume $VOL_NAME from $NAME"
154
+nova volume-detach $VM_UUID $VOL_ID || die "Failure detaching volume $VOL_NAME from $NAME"
156 155
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
157 156
     echo "Volume $VOL_NAME not detached from $NAME"
158 157
     exit 1
159 158
 fi
160 159
 
161 160
 # Delete volume
162
-nova volume-delete $VOL_ID
163
-die_if_error "Failure deleting volume $VOL_NAME"
161
+nova volume-delete $VOL_ID || die "Failure deleting volume $VOL_NAME"
164 162
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME; do sleep 1; done"; then
165 163
     echo "Volume $VOL_NAME not deleted"
166 164
     exit 1
167 165
 fi
168 166
 
169 167
 # shutdown the server
170
-nova delete $NAME
171
-die_if_error "Failure deleting instance $NAME"
168
+nova delete $NAME || die "Failure deleting instance $NAME"
172 169
 
173 170
 set +o xtrace
174
-echo "**************************************************"
175
-echo "End DevStack Exercise: $0"
176
-echo "**************************************************"
171
+echo "*********************************************************************"
172
+echo "SUCCESS: End DevStack Exercise: $0"
173
+echo "*********************************************************************"
... ...
@@ -1,5 +1,9 @@
1 1
 # functions - Common functions used by DevStack components
2 2
 
3
+# Save trace setting
4
+XTRACE=$(set +o | grep xtrace)
5
+set +o xtrace
6
+
3 7
 
4 8
 # apt-get wrapper to set arguments correctly
5 9
 # apt_get package [package ...]
... ...
@@ -22,15 +26,13 @@ function cp_it {
22 22
 }
23 23
 
24 24
 
25
-# Checks the exit code of the last command and prints "message"
26
-# if it is non-zero and exits
27
-# die_if_error "message"
28
-function die_if_error() {
25
+# Prints "message" and exits
26
+# die "message"
27
+function die() {
29 28
     local exitcode=$?
30
-    if [ $exitcode != 0 ]; then
31
-        echo $@
32
-        exit $exitcode
33
-    fi
29
+    set +o xtrace
30
+    echo $@
31
+    exit $exitcode
34 32
 }
35 33
 
36 34
 
... ...
@@ -39,12 +41,16 @@ function die_if_error() {
39 39
 # NOTE: env-var is the variable name without a '$'
40 40
 # die_if_not_set env-var "message"
41 41
 function die_if_not_set() {
42
-    local exitcode=$?
43
-    local evar=$1; shift
44
-    if ! is_set $evar || [ $exitcode != 0 ]; then
45
-        echo $@
46
-        exit 99
47
-    fi
42
+    (
43
+        local exitcode=$?
44
+        set +o xtrace
45
+        local evar=$1; shift
46
+        if ! is_set $evar || [ $exitcode != 0 ]; then
47
+            set +o xtrace
48
+            echo $@
49
+            exit -1
50
+        fi
51
+    )
48 52
 }
49 53
 
50 54
 
... ...
@@ -143,3 +149,6 @@ function trueorfalse() {
143 143
     [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
144 144
     echo "$default"
145 145
 }
146
+
147
+# Restore xtrace
148
+$XTRACE
146 149
\ No newline at end of file
... ...
@@ -133,8 +133,7 @@ if [[ $EUID -eq 0 ]]; then
133 133
     exit 1
134 134
 else
135 135
     # We're not root, make sure sudo is available
136
-    dpkg -l sudo
137
-    die_if_error "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
136
+    dpkg -l sudo || die "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
138 137
 
139 138
     # UEC images /etc/sudoers does not have a '#includedir'. add one.
140 139
     sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
... ...
@@ -11,43 +11,28 @@ source $TOP/functions
11 11
 source $TOP/openrc
12 12
 
13 13
 
14
-echo "Testing die_if_error()"
15
-
16
-bash -c "source $TOP/functions; true; die_if_error 'not OK'"
17
-if [[ $? != 0 ]]; then
18
-    echo "die_if_error [true] Failed"
19
-fi
20
-
21
-bash -c "source $TOP/functions; false; die_if_error 'OK'"
22
-if [[ $? = 0 ]]; then
23
-    echo "die_if_error [false] Failed"
24
-else
25
-    echo 'OK'
26
-fi
27
-
28
-
29 14
 echo "Testing die_if_not_set()"
30 15
 
31
-bash -c "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
16
+bash -cx "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
32 17
 if [[ $? != 0 ]]; then
33 18
     echo "die_if_not_set [X='Y' true] Failed"
34 19
 else
35 20
     echo 'OK'
36 21
 fi
37 22
 
38
-bash -c "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
23
+bash -cx "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
39 24
 if [[ $? = 0 ]]; then
40 25
     echo "die_if_not_set [X='' true] Failed"
41 26
 fi
42 27
 
43
-bash -c "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
28
+bash -cx "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
44 29
 if [[ $? != 0 ]]; then
45 30
     echo "die_if_not_set [X='Y' false] Failed"
46 31
 else
47 32
     echo 'OK'
48 33
 fi
49 34
 
50
-bash -c "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
35
+bash -cx "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
51 36
 if [[ $? = 0 ]]; then
52 37
     echo "die_if_not_set [X='' false] Failed"
53 38
 fi