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 | |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 5 | # Test swift via the ``python-openstackclient`` command line |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 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 |
Joe Gordon | 4640026 | 2013-06-30 04:32:27 -0700 | [diff] [blame] | 12 | # only the first error that occurred. |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 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 | |
Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 36 | # If swift is not enabled we exit with exitcode 55 which mean |
| 37 | # exercise is skipped. |
Chmouel Boudjnah | 0c3a558 | 2013-03-06 10:58:33 +0100 | [diff] [blame] | 38 | is_service_enabled s-proxy || exit 55 |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 39 | |
Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 40 | # Container name |
| 41 | CONTAINER=ex-swift |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 42 | OBJECT=/etc/issue |
Dean Troyer | da85cda | 2013-02-15 11:07:14 -0600 | [diff] [blame] | 43 | |
Dean Troyer | ad10176 | 2012-06-27 22:04:40 -0500 | [diff] [blame] | 44 | |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 45 | # Testing Swift |
| 46 | # ============= |
| 47 | |
| 48 | # Check if we have to swift via keystone |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 49 | openstack object store account show || die $LINENO "Failure getting account status" |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 50 | |
| 51 | # We start by creating a test container |
Steve Martinelli | bf1b8ed | 2014-10-06 03:36:20 -0400 | [diff] [blame] | 52 | openstack container create $CONTAINER || die $LINENO "Failure creating container $CONTAINER" |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 53 | |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 54 | # add a file into it. |
| 55 | openstack object create $CONTAINER $OBJECT || die $LINENO "Failure uploading file to container $CONTAINER" |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 56 | |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 57 | # list the objects |
Steve Martinelli | bf1b8ed | 2014-10-06 03:36:20 -0400 | [diff] [blame] | 58 | openstack object list $CONTAINER || die $LINENO "Failure listing contents of container $CONTAINER" |
Todd Willey | 3e6ec23 | 2011-11-04 12:23:35 -0400 | [diff] [blame] | 59 | |
Steve Martinelli | bbe59ed | 2015-10-21 00:47:43 -0400 | [diff] [blame] | 60 | # delete the object first |
| 61 | openstack object delete $CONTAINER $OBJECT || die $LINENO "Failure deleting object $OBJECT in container $CONTAINER" |
| 62 | |
| 63 | # delete the container |
| 64 | openstack container delete $CONTAINER || die $LINENO "Failure deleting container $CONTAINER" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 65 | |
| 66 | set +o xtrace |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 67 | echo "*********************************************************************" |
| 68 | echo "SUCCESS: End DevStack Exercise: $0" |
| 69 | echo "*********************************************************************" |