Skip to content

Commit 27e3269

Browse files
author
Dean Troyer
committed
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
1 parent 09407d9 commit 27e3269

File tree

12 files changed

+154
-148
lines changed

12 files changed

+154
-148
lines changed

exercise.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env bash
22

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+
411
# Run everything in the exercises/ directory that isn't explicitly disabled
512

613
# comma separated list of script basenames to skip
@@ -21,9 +28,9 @@ for script in $basenames; do
2128
if [[ "$SKIP_EXERCISES" =~ $script ]] ; then
2229
skips="$skips $script"
2330
else
24-
echo =========================
31+
echo "====================================================================="
2532
echo Running $script
26-
echo =========================
33+
echo "====================================================================="
2734
$EXERCISE_DIR/$script.sh
2835
if [[ $? -ne 0 ]] ; then
2936
failures="$failures $script"
@@ -34,8 +41,7 @@ for script in $basenames; do
3441
done
3542

3643
# output status of exercise run
37-
echo =========================
38-
echo =========================
44+
echo "====================================================================="
3945
for script in $skips; do
4046
echo SKIP $script
4147
done
@@ -45,6 +51,7 @@ done
4551
for script in $failures; do
4652
echo FAILED $script
4753
done
54+
echo "====================================================================="
4855

4956
if [ -n "$failures" ] ; then
5057
exit 1

exercises/boot_from_volume.sh

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# * Format and install an os onto the volume
99
# * Detach volume from builder, and then boot volume-backed instance
1010

11-
echo "**************************************************"
11+
echo "*********************************************************************"
1212
echo "Begin DevStack Exercise: $0"
13-
echo "**************************************************"
13+
echo "*********************************************************************"
1414

1515
# This script exits on an error so that errors don't compound and you see
1616
# only the first error that occured.
@@ -46,9 +46,12 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
4646
# Default floating IP pool name
4747
DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
4848

49+
50+
# Launching servers
51+
# =================
52+
4953
# Grab the id of the image to launch
5054
IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
51-
5255
die_if_not_set IMAGE "Failure getting image"
5356

5457
# Instance and volume names
@@ -88,7 +91,8 @@ nova keypair-add $KEY_NAME > $KEY_FILE
8891
chmod 600 $KEY_FILE
8992

9093
# 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'`
94+
VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | get_field 2`
95+
die_if_not_set VM_UUID "Failure launching $INSTANCE_NAME"
9296

9397
# check that the status is active within ACTIVE_TIMEOUT seconds
9498
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
105109
fi
106110

107111
# Allocate floating ip
108-
FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | cut -d '|' -f2 | tr -d ' '`
112+
FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
109113

110114
# Make sure the ip gets allocated
111115
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
133137

134138
# FIXME (anthony) - python-novaclient should accept a volume_name for the attachment param?
135139
DEVICE=/dev/vdb
136-
VOLUME_ID=`nova volume-list | grep $VOL_NAME | cut -d '|' -f 2 | tr -d ' '`
140+
VOLUME_ID=`nova volume-list | grep $VOL_NAME | get_field 1`
137141
nova volume-attach $INSTANCE_NAME $VOLUME_ID $DEVICE
138142

139143
# Wait till volume is attached
@@ -192,7 +196,8 @@ nova volume-detach $INSTANCE_NAME $VOLUME_ID
192196
# The format of mapping is:
193197
# <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
194198
# 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'`
199+
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`
200+
die_if_not_set VOL_VM_UUID "Failure launching $VOL_INSTANCE_NAME"
196201

197202
# Check that the status is active within ACTIVE_TIMEOUT seconds
198203
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
201206
fi
202207

203208
# Add floating ip to our server
204-
nova remove-floating-ip $VM_UUID $FLOATING_IP
209+
nova remove-floating-ip $VM_UUID $FLOATING_IP
205210

206211
# Gratuitous sleep, probably hiding a race condition :/
207212
sleep 1
@@ -221,7 +226,8 @@ echo "success!"
221226
EOF
222227

223228
# Delete volume backed instance
224-
nova delete $VOL_INSTANCE_NAME
229+
nova delete $VOL_INSTANCE_NAME || \
230+
die "Failure deleting instance volume $VOL_INSTANCE_NAME"
225231

226232
# Wait till our volume is no longer in-use
227233
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 |
230236
fi
231237

232238
# Delete the volume
233-
nova volume-delete $VOL_NAME
239+
nova volume-delete $VOL_NAME || \
240+
die "Failure deleting volume $VOLUME_NAME"
234241

235242
# Delete instance
236-
nova delete $INSTANCE_NAME
243+
nova delete $INSTANCE_NAME || \
244+
die "Failure deleting instance $INSTANCE_NAME"
237245

238246
# Wait for termination
239247
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;
242250
fi
243251

244252
# De-allocate the floating ip
245-
nova floating-ip-delete $FLOATING_IP
253+
nova floating-ip-delete $FLOATING_IP || \
254+
die "Failure deleting floating IP $FLOATING_IP"
246255

247-
# Delete secgroup
248-
nova secgroup-delete $SECGROUP
256+
# Delete a secgroup
257+
nova secgroup-delete $SECGROUP || \
258+
die "Failure deleting security group $SECGROUP"
249259

250260
set +o xtrace
251-
echo "**************************************************"
252-
echo "End DevStack Exercise: $0"
253-
echo "**************************************************"
261+
echo "*********************************************************************"
262+
echo "SUCCESS: End DevStack Exercise: $0"
263+
echo "*********************************************************************"

exercises/bundle.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env bash
22

3+
# **bundle.sh**
4+
35
# 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
57

6-
echo "**************************************************"
8+
echo "*********************************************************************"
79
echo "Begin DevStack Exercise: $0"
8-
echo "**************************************************"
10+
echo "*********************************************************************"
911

1012
# This script exits on an error so that errors don't compound and you see
1113
# only the first error that occured.
@@ -46,12 +48,9 @@ REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
4648
BUCKET=testbucket
4749
IMAGE=bundle.img
4850
truncate -s 5M /tmp/$IMAGE
49-
euca-bundle-image -i /tmp/$IMAGE
50-
die_if_error "Failure bundling image $IMAGE"
51-
51+
euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE"
5252

53-
euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
54-
die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
53+
euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET"
5554

5655
AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
5756
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
6362
fi
6463

6564
# Clean up
66-
euca-deregister $AMI
67-
die_if_error "Failure deregistering $AMI"
65+
euca-deregister $AMI || die "Failure deregistering $AMI"
6866

6967
set +o xtrace
70-
echo "**************************************************"
71-
echo "End DevStack Exercise: $0"
72-
echo "**************************************************"
68+
echo "*********************************************************************"
69+
echo "SUCCESS: End DevStack Exercise: $0"
70+
echo "*********************************************************************"

exercises/client-args.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# Test OpenStack client authentication aguemnts handling
44

5-
echo "**************************************************"
5+
echo "*********************************************************************"
66
echo "Begin DevStack Exercise: $0"
7-
echo "**************************************************"
7+
echo "*********************************************************************"
88

99
# Settings
1010
# ========
@@ -135,8 +135,8 @@ report "Nova" $STATUS_NOVA
135135
report "Glance" $STATUS_GLANCE
136136
report "Swift" $STATUS_SWIFT
137137

138-
echo "**************************************************"
139-
echo "End DevStack Exercise: $0"
140-
echo "**************************************************"
138+
echo "*********************************************************************"
139+
echo "SUCCESS: End DevStack Exercise: $0"
140+
echo "*********************************************************************"
141141

142142
exit $RETURN

exercises/client-env.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# Test OpenStack client enviroment variable handling
44

5-
echo "**************************************************"
5+
echo "*********************************************************************"
66
echo "Begin DevStack Exercise: $0"
7-
echo "**************************************************"
7+
echo "*********************************************************************"
88

99
# Verify client workage
1010
VERIFY=${1:-""}
@@ -149,8 +149,8 @@ report "EC2" $STATUS_EC2
149149
report "Glance" $STATUS_GLANCE
150150
report "Swift" $STATUS_SWIFT
151151

152-
echo "**************************************************"
153-
echo "End DevStack Exercise: $0"
154-
echo "**************************************************"
152+
echo "*********************************************************************"
153+
echo "SUCCESS: End DevStack Exercise: $0"
154+
echo "*********************************************************************"
155155

156156
exit $RETURN

exercises/euca.sh

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env bash
22

3+
# **euca.sh**
4+
35
# we will use the ``euca2ools`` cli tool that wraps the python boto
46
# library to test ec2 compatibility
57

6-
echo "**************************************************"
8+
echo "*********************************************************************"
79
echo "Begin DevStack Exercise: $0"
8-
echo "**************************************************"
10+
echo "*********************************************************************"
911

1012
# This script exits on an error so that errors don't compound and you see
1113
# only the first error that occured.
@@ -15,6 +17,7 @@ set -o errexit
1517
# an error. It is also useful for following allowing as the install occurs.
1618
set -o xtrace
1719

20+
1821
# Settings
1922
# ========
2023

@@ -34,6 +37,10 @@ source $TOP_DIR/exerciserc
3437
# Instance type to create
3538
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
3639

40+
41+
# Launching a server
42+
# ==================
43+
3744
# Find a machine image to boot
3845
IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
3946

@@ -64,12 +71,12 @@ FLOATING_IP=`euca-allocate-address | cut -f2`
6471
die_if_not_set FLOATING_IP "Failure allocating floating IP"
6572

6673
# Associate floating address
67-
euca-associate-address -i $INSTANCE $FLOATING_IP
68-
die_if_error "Failure associating address $FLOATING_IP to $INSTANCE"
74+
euca-associate-address -i $INSTANCE $FLOATING_IP || \
75+
die "Failure associating address $FLOATING_IP to $INSTANCE"
6976

7077
# 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"
78+
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
79+
die "Failure authorizing rule in $SECGROUP"
7380

7481
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
7582
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
7885
fi
7986

8087
# 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"
88+
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
89+
die "Failure revoking rule in $SECGROUP"
8390

8491
# Release floating address
85-
euca-disassociate-address $FLOATING_IP
86-
die_if_error "Failure disassociating address $FLOATING_IP"
92+
euca-disassociate-address $FLOATING_IP || \
93+
die "Failure disassociating address $FLOATING_IP"
8794

8895
# Wait just a tick for everything above to complete so release doesn't fail
8996
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
9299
fi
93100

94101
# Release floating address
95-
euca-release-address $FLOATING_IP
96-
die_if_error "Failure releasing address $FLOATING_IP"
102+
euca-release-address $FLOATING_IP || \
103+
die "Failure releasing address $FLOATING_IP"
97104

98105
# Wait just a tick for everything above to complete so terminate doesn't fail
99106
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 $
102109
fi
103110

104111
# Terminate instance
105-
euca-terminate-instances $INSTANCE
106-
die_if_error "Failure terminating instance $INSTANCE"
112+
euca-terminate-instances $INSTANCE || \
113+
die "Failure terminating instance $INSTANCE"
107114

108115
# Assure it has terminated within a reasonable time
109116
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 |
112119
fi
113120

114121
# Delete group
115-
euca-delete-group $SECGROUP
116-
die_if_error "Failure deleting security group $SECGROUP"
122+
euca-delete-group $SECGROUP || \
123+
die "Failure deleting security group $SECGROUP"
117124

118125
set +o xtrace
119-
echo "**************************************************"
120-
echo "End DevStack Exercise: $0"
121-
echo "**************************************************"
126+
echo "*********************************************************************"
127+
echo "SUCCESS: End DevStack Exercise: $0"
128+
echo "*********************************************************************"

0 commit comments

Comments
 (0)