blob: c607c94b7b2c5696b48217c5fa88743c2e643574 [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
20# Settings
21# ========
22
Dean Troyer0bd24102012-03-08 00:33:54 -060023# Keep track of the current directory
24EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
25TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
Dean Troyer489bd2a2012-03-02 10:44:29 -060026
27# Import common functions
Dean Troyer0bd24102012-03-08 00:33:54 -060028source $TOP_DIR/functions
Dean Troyer489bd2a2012-03-02 10:44:29 -060029
Dean Troyer0bd24102012-03-08 00:33:54 -060030# Import EC2 configuration
31source $TOP_DIR/eucarc
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000032
Dean Troyer51fb4542012-03-09 22:21:59 -060033# Import exercise configuration
34source $TOP_DIR/exerciserc
35
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000036# Remove old certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060037rm -f $TOP_DIR/cacert.pem
38rm -f $TOP_DIR/cert.pem
39rm -f $TOP_DIR/pk.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000040
41# Get Certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060042nova x509-get-root-cert $TOP_DIR/cacert.pem
43nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000044
45# Max time to wait for image to be registered
46REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
47
48BUCKET=testbucket
49IMAGE=bundle.img
50truncate -s 5M /tmp/$IMAGE
Dean Troyer27e32692012-03-16 16:16:56 -050051euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000052
Dean Troyer27e32692012-03-16 16:16:56 -050053euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET"
Dean Troyer489bd2a2012-03-02 10:44:29 -060054
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000055AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060056die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000057
58# Wait for the image to become available
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000059if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | grep -q available; do sleep 1; done"; then
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000060 echo "Image $AMI not available within $REGISTER_TIMEOUT seconds"
61 exit 1
62fi
Dean Troyer80756ea2012-02-01 18:01:01 -060063
64# Clean up
Dean Troyer27e32692012-03-16 16:16:56 -050065euca-deregister $AMI || die "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 "*********************************************************************"