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/swift.sh b/exercises/swift.sh
index 95443df..7609637 100755
--- a/exercises/swift.sh
+++ b/exercises/swift.sh
@@ -2,6 +2,10 @@
# Test swift via the command line tools that ship with it.
+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.
set -o errexit
@@ -15,9 +19,17 @@
# ========
# 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
-popd
+popd >/dev/null
+
+# Container name
+CONTAINER=ex-swift
# Testing Swift
@@ -25,16 +37,26 @@
# Check if we have to swift via keystone
swift stat
+die_if_error "Failure geting status"
# We start by creating a test container
-swift post testcontainer
+swift post $CONTAINER
+die_if_error "Failure creating container $CONTAINER"
# add some files into it.
-swift upload testcontainer /etc/issue
+swift upload $CONTAINER /etc/issue
+die_if_error "Failure uploading file to container $CONTAINER"
# list them
-swift list testcontainer
+swift list $CONTAINER
+die_if_error "Failure listing contents of container $CONTAINER"
# And we may want to delete them now that we have tested that
# everything works.
-swift delete testcontainer
+swift delete $CONTAINER
+die_if_error "Failure deleting container $CONTAINER"
+
+set +o xtrace
+echo "**************************************************"
+echo "End DevStack Exercise: $0"
+echo "**************************************************"