blob: 47bacac3ae298b38fcf4a4b4d31e40dba91a8a27 [file] [log] [blame]
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +00001#!/usr/bin/env bash
2
3# we will use the ``euca2ools`` cli tool that wraps the python boto
4# library to test ec2 compatibility
Dean Troyer489bd2a2012-03-02 10:44:29 -06005
6echo "**************************************************"
7echo "Begin DevStack Exercise: $0"
8echo "**************************************************"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +00009
10# This script exits on an error so that errors don't compound and you see
11# only the first error that occured.
12set -o errexit
13
14# Print the commands being run so that we can see the command that triggers
15# an error. It is also useful for following allowing as the install occurs.
16set -o xtrace
17
18# Settings
19# ========
20
Dean Troyer0bd24102012-03-08 00:33:54 -060021# Keep track of the current directory
22EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
23TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
Dean Troyer489bd2a2012-03-02 10:44:29 -060024
25# Import common functions
Dean Troyer0bd24102012-03-08 00:33:54 -060026source $TOP_DIR/functions
Dean Troyer489bd2a2012-03-02 10:44:29 -060027
Dean Troyer0bd24102012-03-08 00:33:54 -060028# Import EC2 configuration
29source $TOP_DIR/eucarc
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000030
31# Remove old certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060032rm -f $TOP_DIR/cacert.pem
33rm -f $TOP_DIR/cert.pem
34rm -f $TOP_DIR/pk.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000035
36# Get Certificates
Dean Troyer0bd24102012-03-08 00:33:54 -060037nova x509-get-root-cert $TOP_DIR/cacert.pem
38nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000039
40# Max time to wait for image to be registered
41REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
42
43BUCKET=testbucket
44IMAGE=bundle.img
45truncate -s 5M /tmp/$IMAGE
46euca-bundle-image -i /tmp/$IMAGE
Dean Troyer489bd2a2012-03-02 10:44:29 -060047die_if_error "Failure bundling image $IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000048
49
50euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
Dean Troyer489bd2a2012-03-02 10:44:29 -060051die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
52
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000053AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060054die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
Vishvananda Ishaya75bbd752012-01-19 23:28:46 +000055
56# Wait for the image to become available
57if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep '$AMI' | grep 'available'; do sleep 1; done"; then
58 echo "Image $AMI not available within $REGISTER_TIMEOUT seconds"
59 exit 1
60fi
Dean Troyer80756ea2012-02-01 18:01:01 -060061
62# Clean up
63euca-deregister $AMI
Dean Troyer489bd2a2012-03-02 10:44:29 -060064die_if_error "Failure deregistering $AMI"
65
66set +o xtrace
67echo "**************************************************"
68echo "End DevStack Exercise: $0"
69echo "**************************************************"