Improve exercise robustness
* Test returns and exit codes on most command invocations
* Add start and end banners to make output easier to find in
long log files
* Adds die_if_error(), die_if_not_set() and is_set() to functions
* Add some function tests
Fixes bug 944593
Change-Id: I55e2962c5fec9aad237b674732b1e922ad37a62e
diff --git a/exercises/bundle.sh b/exercises/bundle.sh
index d5c78af..e1c949c 100755
--- a/exercises/bundle.sh
+++ b/exercises/bundle.sh
@@ -2,7 +2,10 @@
# we will use the ``euca2ools`` cli tool that wraps the python boto
# library to test ec2 compatibility
-#
+
+echo "**************************************************"
+echo "Begin DevStack Exercise: $0"
+echo "**************************************************"
# This script exits on an error so that errors don't compound and you see
# only the first error that occured.
@@ -16,7 +19,12 @@
# ========
# Use openrc + stackrc + localrc for settings
-pushd $(cd $(dirname "$0")/.. && pwd)
+pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
+
+# Import common functions
+source ./functions
+
+# Import configuration
source ./openrc
# Remove old certificates
@@ -27,7 +35,7 @@
# Get Certificates
nova x509-get-root-cert
nova x509-create-cert
-popd
+popd >/dev/null
# Max time to wait for image to be registered
REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
@@ -36,10 +44,14 @@
IMAGE=bundle.img
truncate -s 5M /tmp/$IMAGE
euca-bundle-image -i /tmp/$IMAGE
+die_if_error "Failure bundling image $IMAGE"
euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
+die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
+
AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
+die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
# Wait for the image to become available
if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep '$AMI' | grep 'available'; do sleep 1; done"; then
@@ -49,3 +61,9 @@
# Clean up
euca-deregister $AMI
+die_if_error "Failure deregistering $AMI"
+
+set +o xtrace
+echo "**************************************************"
+echo "End DevStack Exercise: $0"
+echo "**************************************************"