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
diff --git a/exercises/euca.sh b/exercises/euca.sh
index 703c7aa..76e5202 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -1,11 +1,13 @@
#!/usr/bin/env bash
+# **euca.sh**
+
# we will use the ``euca2ools`` cli tool that wraps the python boto
# library to test ec2 compatibility
-echo "**************************************************"
+echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occured.
@@ -15,6 +17,7 @@
# an error. It is also useful for following allowing as the install occurs.
set -o xtrace
+
# Settings
# ========
@@ -34,6 +37,10 @@
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
+
+# Launching a server
+# ==================
+
# Find a machine image to boot
IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
@@ -64,12 +71,12 @@
die_if_not_set FLOATING_IP "Failure allocating floating IP"
# Associate floating address
-euca-associate-address -i $INSTANCE $FLOATING_IP
-die_if_error "Failure associating address $FLOATING_IP to $INSTANCE"
+euca-associate-address -i $INSTANCE $FLOATING_IP || \
+ die "Failure associating address $FLOATING_IP to $INSTANCE"
# Authorize pinging
-euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
-die_if_error "Failure authorizing rule in $SECGROUP"
+euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
+ die "Failure authorizing rule in $SECGROUP"
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
@@ -78,12 +85,12 @@
fi
# Revoke pinging
-euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
-die_if_error "Failure revoking rule in $SECGROUP"
+euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
+ die "Failure revoking rule in $SECGROUP"
# Release floating address
-euca-disassociate-address $FLOATING_IP
-die_if_error "Failure disassociating address $FLOATING_IP"
+euca-disassociate-address $FLOATING_IP || \
+ die "Failure disassociating address $FLOATING_IP"
# Wait just a tick for everything above to complete so release doesn't fail
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 @@
fi
# Release floating address
-euca-release-address $FLOATING_IP
-die_if_error "Failure releasing address $FLOATING_IP"
+euca-release-address $FLOATING_IP || \
+ die "Failure releasing address $FLOATING_IP"
# Wait just a tick for everything above to complete so terminate doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
@@ -102,8 +109,8 @@
fi
# Terminate instance
-euca-terminate-instances $INSTANCE
-die_if_error "Failure terminating instance $INSTANCE"
+euca-terminate-instances $INSTANCE || \
+ die "Failure terminating instance $INSTANCE"
# Assure it has terminated within a reasonable time
if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
@@ -112,10 +119,10 @@
fi
# Delete group
-euca-delete-group $SECGROUP
-die_if_error "Failure deleting security group $SECGROUP"
+euca-delete-group $SECGROUP || \
+ die "Failure deleting security group $SECGROUP"
set +o xtrace
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"