blob: dce36aa31f86509de8101f4f545fb02ada118435 [file] [log] [blame]
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +00001#!/usr/bin/env bash
2
Dean Troyer27e32692012-03-16 16:16:56 -05003# **bundle.sh**
Dean Troyer489bd2a2012-03-02 10:44:29 -06004
Dean Troyer27e32692012-03-16 16:16:56 -05005# we will use the ``euca2ools`` cli tool that wraps the python boto
6# library to test ec2 bundle upload compatibility
7
8echo "*********************************************************************"
Dean Troyer489bd2a2012-03-02 10:44:29 -06009echo "Begin DevStack Exercise: $0"
Dean Troyer27e32692012-03-16 16:16:56 -050010echo "*********************************************************************"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000011
12# This script exits on an error so that errors don't compound and you see
13# only the first error that occured.
14set -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.
18set -o xtrace
19
Dean Troyerad101762012-06-27 22:04:40 -050020
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000021# Settings
22# ========
23
Dean Troyer0bd24102012-03-08 00:33:54 -060024# Keep track of the current directory
25EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
26TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
Dean Troyer489bd2a2012-03-02 10:44:29 -060027
28# Import common functions
Dean Troyer0bd24102012-03-08 00:33:54 -060029source $TOP_DIR/functions
Dean Troyer489bd2a2012-03-02 10:44:29 -060030
Dean Troyer0bd24102012-03-08 00:33:54 -060031# Import EC2 configuration
32source $TOP_DIR/eucarc
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000033
Dean Troyer51fb4542012-03-09 22:21:59 -060034# Import exercise configuration
35source $TOP_DIR/exerciserc
36
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000037# Remove old certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060038rm -f $TOP_DIR/cacert.pem
39rm -f $TOP_DIR/cert.pem
40rm -f $TOP_DIR/pk.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000041
42# Get Certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060043nova x509-get-root-cert $TOP_DIR/cacert.pem
44nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000045
46# Max time to wait for image to be registered
47REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
48
49BUCKET=testbucket
50IMAGE=bundle.img
51truncate -s 5M /tmp/$IMAGE
Nachi Ueno07115eb2013-02-26 12:38:18 -080052euca-bundle-image -i /tmp/$IMAGE || die $LINENO "Failure bundling image $IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000053
Nachi Ueno07115eb2013-02-26 12:38:18 -080054euca-upload-bundle --debug -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die $LINENO "Failure uploading bundle $IMAGE to $BUCKET"
Dean Troyer489bd2a2012-03-02 10:44:29 -060055
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000056AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080057die_if_not_set $LINENO AMI "Failure registering $BUCKET/$IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000058
59# Wait for the image to become available
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000060if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | grep -q available; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080061 die $LINENO "Image $AMI not available within $REGISTER_TIMEOUT seconds"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000062fi
Dean Troyer80756ea2012-02-01 18:01:01 -060063
64# Clean up
Nachi Ueno07115eb2013-02-26 12:38:18 -080065euca-deregister $AMI || die $LINENO "Failure deregistering $AMI"
Dean Troyer489bd2a2012-03-02 10:44:29 -060066
67set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -050068echo "*********************************************************************"
69echo "SUCCESS: End DevStack Exercise: $0"
70echo "*********************************************************************"