Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 3 | # **bundle.sh** |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 4 | |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 5 | # we will use the ``euca2ools`` cli tool that wraps the python boto |
| 6 | # library to test ec2 bundle upload compatibility |
| 7 | |
| 8 | echo "*********************************************************************" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 9 | echo "Begin DevStack Exercise: $0" |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 10 | echo "*********************************************************************" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 11 | |
| 12 | # 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] | 13 | # only the first error that occurred. |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 14 | set -o errexit |
| 15 | |
| 16 | # Print the commands being run so that we can see the command that triggers |
| 17 | # an error. It is also useful for following allowing as the install occurs. |
| 18 | set -o xtrace |
| 19 | |
Dean Troyer | ad10176 | 2012-06-27 22:04:40 -0500 | [diff] [blame] | 20 | |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 21 | # Settings |
| 22 | # ======== |
| 23 | |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 24 | # Keep track of the current directory |
| 25 | EXERCISE_DIR=$(cd $(dirname "$0") && pwd) |
| 26 | TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 27 | |
| 28 | # Import common functions |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 29 | source $TOP_DIR/functions |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 30 | |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 31 | # Import EC2 configuration |
| 32 | source $TOP_DIR/eucarc |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 33 | |
Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 34 | # Import exercise configuration |
| 35 | source $TOP_DIR/exerciserc |
| 36 | |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 37 | # Remove old certificates |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 38 | rm -f $TOP_DIR/cacert.pem |
| 39 | rm -f $TOP_DIR/cert.pem |
| 40 | rm -f $TOP_DIR/pk.pem |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 41 | |
Kiall Mac Innes | a16c821 | 2014-01-12 19:35:43 +0000 | [diff] [blame] | 42 | # If nova api is not enabled we exit with exitcode 55 so that |
| 43 | # the exercise is skipped |
| 44 | is_service_enabled n-api || exit 55 |
| 45 | |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 46 | # Get Certificates |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 47 | nova x509-get-root-cert $TOP_DIR/cacert.pem |
| 48 | nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 49 | |
| 50 | # Max time to wait for image to be registered |
| 51 | REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15} |
| 52 | |
| 53 | BUCKET=testbucket |
| 54 | IMAGE=bundle.img |
| 55 | truncate -s 5M /tmp/$IMAGE |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 56 | euca-bundle-image -i /tmp/$IMAGE || die $LINENO "Failure bundling image $IMAGE" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 57 | |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 58 | euca-upload-bundle --debug -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die $LINENO "Failure uploading bundle $IMAGE to $BUCKET" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 59 | |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 60 | AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2` |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 61 | die_if_not_set $LINENO AMI "Failure registering $BUCKET/$IMAGE" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 62 | |
| 63 | # Wait for the image to become available |
Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 64 | if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | grep -q available; do sleep 1; done"; then |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 65 | die $LINENO "Image $AMI not available within $REGISTER_TIMEOUT seconds" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 66 | fi |
Dean Troyer | 80756ea | 2012-02-01 18:01:01 -0600 | [diff] [blame] | 67 | |
| 68 | # Clean up |
Nachi Ueno | 07115eb | 2013-02-26 12:38:18 -0800 | [diff] [blame] | 69 | euca-deregister $AMI || die $LINENO "Failure deregistering $AMI" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 70 | |
| 71 | set +o xtrace |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 72 | echo "*********************************************************************" |
| 73 | echo "SUCCESS: End DevStack Exercise: $0" |
| 74 | echo "*********************************************************************" |