| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
|  | 2 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 3 | # **swift.sh** | 
|  | 4 |  | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 5 | # Test swift via the command line tools that ship with it. | 
|  | 6 |  | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 7 | echo "*********************************************************************" | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 8 | echo "Begin DevStack Exercise: $0" | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 9 | echo "*********************************************************************" | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 10 |  | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 11 | # This script exits on an error so that errors don't compound and you see | 
|  | 12 | # only the first error that occured. | 
|  | 13 | set -o errexit | 
|  | 14 |  | 
|  | 15 | # Print the commands being run so that we can see the command that triggers | 
|  | 16 | # an error.  It is also useful for following allowing as the install occurs. | 
|  | 17 | set -o xtrace | 
|  | 18 |  | 
|  | 19 |  | 
|  | 20 | # Settings | 
|  | 21 | # ======== | 
|  | 22 |  | 
| Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 23 | # Keep track of the current directory | 
|  | 24 | EXERCISE_DIR=$(cd $(dirname "$0") && pwd) | 
|  | 25 | TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 26 |  | 
|  | 27 | # Import common functions | 
| Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 28 | source $TOP_DIR/functions | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 29 |  | 
|  | 30 | # Import configuration | 
| Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 31 | source $TOP_DIR/openrc | 
|  | 32 |  | 
|  | 33 | # Import exercise configuration | 
|  | 34 | source $TOP_DIR/exerciserc | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 35 |  | 
|  | 36 | # Container name | 
|  | 37 | CONTAINER=ex-swift | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 38 |  | 
| Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 39 | # If swift is not enabled we exit with exitcode 55 which mean | 
|  | 40 | # exercise is skipped. | 
|  | 41 | is_service_enabled swift || exit 55 | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 42 |  | 
|  | 43 | # Testing Swift | 
|  | 44 | # ============= | 
|  | 45 |  | 
|  | 46 | # Check if we have to swift via keystone | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 47 | swift stat || die "Failure geting status" | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 48 |  | 
|  | 49 | # We start by creating a test container | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 50 | swift post $CONTAINER || die "Failure creating container $CONTAINER" | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 51 |  | 
|  | 52 | # add some files into it. | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 53 | swift upload $CONTAINER /etc/issue || die "Failure uploading file to container $CONTAINER" | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 54 |  | 
|  | 55 | # list them | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 56 | swift list $CONTAINER || die "Failure listing contents of container $CONTAINER" | 
| Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 57 |  | 
|  | 58 | # And we may want to delete them now that we have tested that | 
|  | 59 | # everything works. | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 60 | swift delete $CONTAINER || die "Failure deleting container $CONTAINER" | 
| Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 61 |  | 
|  | 62 | set +o xtrace | 
| Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 63 | echo "*********************************************************************" | 
|  | 64 | echo "SUCCESS: End DevStack Exercise: $0" | 
|  | 65 | echo "*********************************************************************" |