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 |
| 13 | # only the first error that occured. |
| 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 | |
| 42 | # Get Certificates |
Dean Troyer | 0bd2410 | 2012-03-08 00:33:54 -0600 | [diff] [blame] | 43 | nova x509-get-root-cert $TOP_DIR/cacert.pem |
| 44 | nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 45 | |
| 46 | # Max time to wait for image to be registered |
| 47 | REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15} |
| 48 | |
| 49 | BUCKET=testbucket |
| 50 | IMAGE=bundle.img |
| 51 | truncate -s 5M /tmp/$IMAGE |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 52 | euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 53 | |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 54 | euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 55 | |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 56 | AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2` |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 57 | die_if_not_set AMI "Failure registering $BUCKET/$IMAGE" |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 58 | |
| 59 | # Wait for the image to become available |
Chmouel Boudjnah | 77b0e1d | 2012-02-29 16:55:43 +0000 | [diff] [blame] | 60 | if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | grep -q available; do sleep 1; done"; then |
Vishvananda Ishaya | 75bbd75 | 2012-01-19 23:28:46 +0000 | [diff] [blame] | 61 | echo "Image $AMI not available within $REGISTER_TIMEOUT seconds" |
| 62 | exit 1 |
| 63 | fi |
Dean Troyer | 80756ea | 2012-02-01 18:01:01 -0600 | [diff] [blame] | 64 | |
| 65 | # Clean up |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 66 | euca-deregister $AMI || die "Failure deregistering $AMI" |
Dean Troyer | 489bd2a | 2012-03-02 10:44:29 -0600 | [diff] [blame] | 67 | |
| 68 | set +o xtrace |
Dean Troyer | 27e3269 | 2012-03-16 16:16:56 -0500 | [diff] [blame] | 69 | echo "*********************************************************************" |
| 70 | echo "SUCCESS: End DevStack Exercise: $0" |
| 71 | echo "*********************************************************************" |