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/exercise.sh b/exercise.sh
index dd45c5a..2072b23 100755
--- a/exercise.sh
+++ b/exercise.sh
@@ -1,6 +1,13 @@
 #!/usr/bin/env bash
 
-source ./stackrc
+# **exercise.sh**
+
+# Keep track of the current devstack directory.
+TOP_DIR=$(cd $(dirname "$0") && pwd)
+
+# Load local configuration
+source $TOP_DIR/stackrc
+
 # Run everything in the exercises/ directory that isn't explicitly disabled
 
 # comma separated list of script basenames to skip
@@ -21,9 +28,9 @@
     if [[ "$SKIP_EXERCISES" =~ $script ]] ; then
         skips="$skips $script"
     else
-        echo =========================
+        echo "====================================================================="
         echo Running $script
-        echo =========================
+        echo "====================================================================="
         $EXERCISE_DIR/$script.sh
         if [[ $? -ne 0 ]] ; then
             failures="$failures $script"
@@ -34,8 +41,7 @@
 done
 
 # output status of exercise run
-echo =========================
-echo =========================
+echo "====================================================================="
 for script in $skips; do
     echo SKIP $script
 done
@@ -45,6 +51,7 @@
 for script in $failures; do
     echo FAILED $script
 done
+echo "====================================================================="
 
 if [ -n "$failures" ] ; then
     exit 1
diff --git a/exercises/boot_from_volume.sh b/exercises/boot_from_volume.sh
index 8d39703..c707b47 100755
--- a/exercises/boot_from_volume.sh
+++ b/exercises/boot_from_volume.sh
@@ -8,9 +8,9 @@
 #  *  Format and install an os onto the volume
 #  *  Detach volume from builder, and then boot volume-backed instance
 
-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.
@@ -46,9 +46,12 @@
 # Default floating IP pool name
 DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
 
+
+# Launching servers
+# =================
+
 # Grab the id of the image to launch
 IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
-
 die_if_not_set IMAGE "Failure getting image"
 
 # Instance and volume names
@@ -88,7 +91,8 @@
 chmod 600 $KEY_FILE
 
 # Boot our instance
-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'`
+VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | get_field 2`
+die_if_not_set VM_UUID "Failure launching $INSTANCE_NAME"
 
 # check that the status is active within ACTIVE_TIMEOUT seconds
 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 @@
 fi
 
 # Allocate floating ip
-FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | cut -d '|' -f2 | tr -d ' '`
+FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
 
 # Make sure the ip gets allocated
 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
@@ -133,7 +137,7 @@
 
 # FIXME (anthony) - python-novaclient should accept a volume_name for the attachment param?
 DEVICE=/dev/vdb
-VOLUME_ID=`nova volume-list | grep $VOL_NAME  | cut -d '|' -f 2 | tr -d ' '`
+VOLUME_ID=`nova volume-list | grep $VOL_NAME  | get_field 1`
 nova volume-attach $INSTANCE_NAME $VOLUME_ID $DEVICE
 
 # Wait till volume is attached
@@ -192,7 +196,8 @@
 # The format of mapping is:
 # <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
 # Leaving the middle two fields blank appears to do-the-right-thing
-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'`
+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`
+die_if_not_set VOL_VM_UUID "Failure launching $VOL_INSTANCE_NAME"
 
 # Check that the status is active within ACTIVE_TIMEOUT seconds
 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 @@
 fi
 
 # Add floating ip to our server
-nova remove-floating-ip  $VM_UUID $FLOATING_IP
+nova remove-floating-ip $VM_UUID $FLOATING_IP
 
 # Gratuitous sleep, probably hiding a race condition :/
 sleep 1
@@ -221,7 +226,8 @@
 EOF
 
 # Delete volume backed instance
-nova delete $VOL_INSTANCE_NAME
+nova delete $VOL_INSTANCE_NAME || \
+    die "Failure deleting instance volume $VOL_INSTANCE_NAME"
 
 # Wait till our volume is no longer in-use
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
@@ -230,10 +236,12 @@
 fi
 
 # Delete the volume
-nova volume-delete $VOL_NAME
+nova volume-delete $VOL_NAME || \
+    die "Failure deleting volume $VOLUME_NAME"
 
 # Delete instance
-nova delete $INSTANCE_NAME
+nova delete $INSTANCE_NAME || \
+    die "Failure deleting instance $INSTANCE_NAME"
 
 # Wait for termination
 if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1; done"; then
@@ -242,12 +250,14 @@
 fi
 
 # De-allocate the floating ip
-nova floating-ip-delete $FLOATING_IP
+nova floating-ip-delete $FLOATING_IP || \
+    die "Failure deleting floating IP $FLOATING_IP"
 
-# Delete secgroup
-nova secgroup-delete $SECGROUP
+# Delete a secgroup
+nova secgroup-delete $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 "*********************************************************************"
diff --git a/exercises/bundle.sh b/exercises/bundle.sh
index a165d55..c607c94 100755
--- a/exercises/bundle.sh
+++ b/exercises/bundle.sh
@@ -1,11 +1,13 @@
 #!/usr/bin/env bash
 
-# we will use the ``euca2ools`` cli tool that wraps the python boto
-# library to test ec2 compatibility
+# **bundle.sh**
 
-echo "**************************************************"
+# we will use the ``euca2ools`` cli tool that wraps the python boto
+# library to test ec2 bundle upload compatibility
+
+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.
@@ -46,12 +48,9 @@
 BUCKET=testbucket
 IMAGE=bundle.img
 truncate -s 5M /tmp/$IMAGE
-euca-bundle-image -i /tmp/$IMAGE
-die_if_error "Failure bundling image $IMAGE"
+euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE"
 
-
-euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
-die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
+euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET"
 
 AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
 die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
@@ -63,10 +62,9 @@
 fi
 
 # Clean up
-euca-deregister $AMI
-die_if_error "Failure deregistering $AMI"
+euca-deregister $AMI || die "Failure deregistering $AMI"
 
 set +o xtrace
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"
diff --git a/exercises/client-args.sh b/exercises/client-args.sh
index 7cb7c45..66fddcf 100755
--- a/exercises/client-args.sh
+++ b/exercises/client-args.sh
@@ -2,9 +2,9 @@
 
 # Test OpenStack client authentication aguemnts handling
 
-echo "**************************************************"
+echo "*********************************************************************"
 echo "Begin DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
 
 # Settings
 # ========
@@ -135,8 +135,8 @@
 report "Glance" $STATUS_GLANCE
 report "Swift" $STATUS_SWIFT
 
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"
 
 exit $RETURN
diff --git a/exercises/client-env.sh b/exercises/client-env.sh
index 0f17275..af2c4c2 100755
--- a/exercises/client-env.sh
+++ b/exercises/client-env.sh
@@ -2,9 +2,9 @@
 
 # Test OpenStack client enviroment variable handling
 
-echo "**************************************************"
+echo "*********************************************************************"
 echo "Begin DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
 
 # Verify client workage
 VERIFY=${1:-""}
@@ -149,8 +149,8 @@
 report "Glance" $STATUS_GLANCE
 report "Swift" $STATUS_SWIFT
 
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"
 
 exit $RETURN
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 "*********************************************************************"
diff --git a/exercises/floating_ips.sh b/exercises/floating_ips.sh
index f2b9d03..9974b4b 100755
--- a/exercises/floating_ips.sh
+++ b/exercises/floating_ips.sh
@@ -1,15 +1,13 @@
 #!/usr/bin/env bash
 
-# **exercise.sh** - using the cloud can be fun
+# **floating_ips.sh** - using the cloud can be fun
 
 # we will use the ``nova`` cli tool provided by the ``python-novaclient``
-# package
-#
+# package to work out the instance connectivity
 
-
-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.
@@ -51,6 +49,7 @@
 # Additional floating IP pool and range
 TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
 
+
 # Launching a server
 # ==================
 
@@ -162,8 +161,8 @@
 fi
 
 # add floating ip to our server
-nova add-floating-ip $VM_UUID $FLOATING_IP
-die_if_error "Failure adding floating IP $FLOATING_IP to $NAME"
+nova add-floating-ip $VM_UUID $FLOATING_IP || \
+    die "Failure adding floating IP $FLOATING_IP to $NAME"
 
 # 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
@@ -182,8 +181,7 @@
 fi
 
 # dis-allow icmp traffic (ping)
-nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0
-die_if_error "Failure deleting security group rule from $SECGROUP"
+nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deleting security group rule from $SECGROUP"
 
 # FIXME (anthony): make xs support security groups
 if [ "$VIRT_DRIVER" != "xenserver" ]; then
@@ -196,16 +194,13 @@
 fi
 
 # de-allocate the floating ip
-nova floating-ip-delete $FLOATING_IP
-die_if_error "Failure deleting floating IP $FLOATING_IP"
+nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
 
 # Delete second floating IP
-nova floating-ip-delete $TEST_FLOATING_IP
-die_if_error "Failure deleting floating IP $TEST_FLOATING_IP"
+nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
 
 # shutdown the server
-nova delete $VM_UUID
-die_if_error "Failure deleting instance $NAME"
+nova delete $VM_UUID || die "Failure deleting instance $NAME"
 
 # make sure the VM shuts down within a reasonable time
 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 @@
 fi
 
 # Delete a secgroup
-nova secgroup-delete $SECGROUP
-die_if_error "Failure deleting security group $SECGROUP"
+nova secgroup-delete $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 "*********************************************************************"
diff --git a/exercises/swift.sh b/exercises/swift.sh
index b70b85f..d8b41a3 100755
--- a/exercises/swift.sh
+++ b/exercises/swift.sh
@@ -1,10 +1,12 @@
 #!/usr/bin/env bash
 
+# **swift.sh**
+
 # Test swift via the command line tools that ship with it.
 
-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.
@@ -39,27 +41,22 @@
 # =============
 
 # Check if we have to swift via keystone
-swift stat
-die_if_error "Failure geting status"
+swift stat || die "Failure geting status"
 
 # We start by creating a test container
-swift post $CONTAINER
-die_if_error "Failure creating container $CONTAINER"
+swift post $CONTAINER || die "Failure creating container $CONTAINER"
 
 # add some files into it.
-swift upload $CONTAINER /etc/issue
-die_if_error "Failure uploading file to container $CONTAINER"
+swift upload $CONTAINER /etc/issue || die "Failure uploading file to container $CONTAINER"
 
 # list them
-swift list $CONTAINER
-die_if_error "Failure listing contents of container $CONTAINER"
+swift list $CONTAINER || die "Failure listing contents of container $CONTAINER"
 
 # And we may want to delete them now that we have tested that
 # everything works.
-swift delete $CONTAINER
-die_if_error "Failure deleting container $CONTAINER"
+swift delete $CONTAINER || die "Failure deleting container $CONTAINER"
 
 set +o xtrace
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"
diff --git a/exercises/volumes.sh b/exercises/volumes.sh
index 77c3498..1abbecc 100755
--- a/exercises/volumes.sh
+++ b/exercises/volumes.sh
@@ -1,10 +1,12 @@
 #!/usr/bin/env bash
 
+# **volumes.sh**
+
 # Test nova volumes with the nova command from python-novaclient
 
-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.
@@ -37,6 +39,7 @@
 # Boot this image, use first AMi image if unset
 DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
 
+
 # Launching a server
 # ==================
 
@@ -136,8 +139,8 @@
 
 # Attach to server
 DEVICE=/dev/vdb
-nova volume-attach $VM_UUID $VOL_ID $DEVICE
-die_if_error "Failure attaching volume $VOL_NAME to $NAME"
+nova volume-attach $VM_UUID $VOL_ID $DEVICE || \
+    die "Failure attaching volume $VOL_NAME to $NAME"
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then
     echo "Volume $VOL_NAME not attached to $NAME"
     exit 1
@@ -151,26 +154,23 @@
 fi
 
 # Detach volume
-nova volume-detach $VM_UUID $VOL_ID
-die_if_error "Failure detaching volume $VOL_NAME from $NAME"
+nova volume-detach $VM_UUID $VOL_ID || die "Failure detaching volume $VOL_NAME from $NAME"
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
     echo "Volume $VOL_NAME not detached from $NAME"
     exit 1
 fi
 
 # Delete volume
-nova volume-delete $VOL_ID
-die_if_error "Failure deleting volume $VOL_NAME"
+nova volume-delete $VOL_ID || die "Failure deleting volume $VOL_NAME"
 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME; do sleep 1; done"; then
     echo "Volume $VOL_NAME not deleted"
     exit 1
 fi
 
 # shutdown the server
-nova delete $NAME
-die_if_error "Failure deleting instance $NAME"
+nova delete $NAME || die "Failure deleting instance $NAME"
 
 set +o xtrace
-echo "**************************************************"
-echo "End DevStack Exercise: $0"
-echo "**************************************************"
+echo "*********************************************************************"
+echo "SUCCESS: End DevStack Exercise: $0"
+echo "*********************************************************************"
diff --git a/functions b/functions
index c4d56a2..7fd37c0 100644
--- a/functions
+++ b/functions
@@ -1,5 +1,9 @@
 # functions - Common functions used by DevStack components
 
+# Save trace setting
+XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
 
 # apt-get wrapper to set arguments correctly
 # apt_get package [package ...]
@@ -22,15 +26,13 @@
 }
 
 
-# Checks the exit code of the last command and prints "message"
-# if it is non-zero and exits
-# die_if_error "message"
-function die_if_error() {
+# Prints "message" and exits
+# die "message"
+function die() {
     local exitcode=$?
-    if [ $exitcode != 0 ]; then
-        echo $@
-        exit $exitcode
-    fi
+    set +o xtrace
+    echo $@
+    exit $exitcode
 }
 
 
@@ -39,12 +41,16 @@
 # NOTE: env-var is the variable name without a '$'
 # die_if_not_set env-var "message"
 function die_if_not_set() {
-    local exitcode=$?
-    local evar=$1; shift
-    if ! is_set $evar || [ $exitcode != 0 ]; then
-        echo $@
-        exit 99
-    fi
+    (
+        local exitcode=$?
+        set +o xtrace
+        local evar=$1; shift
+        if ! is_set $evar || [ $exitcode != 0 ]; then
+            set +o xtrace
+            echo $@
+            exit -1
+        fi
+    )
 }
 
 
@@ -143,3 +149,6 @@
     [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
     echo "$default"
 }
+
+# Restore xtrace
+$XTRACE
\ No newline at end of file
diff --git a/stack.sh b/stack.sh
index 6c12c96..3beb8b7 100755
--- a/stack.sh
+++ b/stack.sh
@@ -133,8 +133,7 @@
     exit 1
 else
     # We're not root, make sure sudo is available
-    dpkg -l sudo
-    die_if_error "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
+    dpkg -l sudo || die "Sudo is required.  Re-run stack.sh as root ONE TIME ONLY to set up sudo."
 
     # UEC images /etc/sudoers does not have a '#includedir'. add one.
     sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
diff --git a/tests/functions.sh b/tests/functions.sh
index 0fd76cc..69e8c0a 100755
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -11,43 +11,28 @@
 source $TOP/openrc
 
 
-echo "Testing die_if_error()"
-
-bash -c "source $TOP/functions; true; die_if_error 'not OK'"
-if [[ $? != 0 ]]; then
-    echo "die_if_error [true] Failed"
-fi
-
-bash -c "source $TOP/functions; false; die_if_error 'OK'"
-if [[ $? = 0 ]]; then
-    echo "die_if_error [false] Failed"
-else
-    echo 'OK'
-fi
-
-
 echo "Testing die_if_not_set()"
 
-bash -c "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
+bash -cx "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
 if [[ $? != 0 ]]; then
     echo "die_if_not_set [X='Y' true] Failed"
 else
     echo 'OK'
 fi
 
-bash -c "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
+bash -cx "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
 if [[ $? = 0 ]]; then
     echo "die_if_not_set [X='' true] Failed"
 fi
 
-bash -c "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
+bash -cx "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
 if [[ $? != 0 ]]; then
     echo "die_if_not_set [X='Y' false] Failed"
 else
     echo 'OK'
 fi
 
-bash -c "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
+bash -cx "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
 if [[ $? = 0 ]]; then
     echo "die_if_not_set [X='' false] Failed"
 fi