75bbd75d |
#!/usr/bin/env bash
|
27e32699 |
# **bundle.sh**
|
75bbd75d |
# we will use the ``euca2ools`` cli tool that wraps the python boto |
27e32699 |
# library to test ec2 bundle upload compatibility |
489bd2a6 |
|
27e32699 |
echo "*********************************************************************" |
489bd2a6 |
echo "Begin DevStack Exercise: $0" |
27e32699 |
echo "*********************************************************************" |
75bbd75d |
# This script exits on an error so that errors don't compound and you see |
4640026c |
# only the first error that occurred. |
75bbd75d |
set -o errexit
# Print the commands being run so that we can see the command that triggers
# an error. It is also useful for following allowing as the install occurs.
set -o xtrace
|
ad101767 |
|
75bbd75d |
# Settings
# ========
|
0bd2410d |
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) |
489bd2a6 |
# Import common functions |
0bd2410d |
source $TOP_DIR/functions |
489bd2a6 |
|
0bd2410d |
# Import EC2 configuration
source $TOP_DIR/eucarc |
75bbd75d |
|
51fb454f |
# Import exercise configuration
source $TOP_DIR/exerciserc
|
75bbd75d |
# Remove old certificates |
0bd2410d |
rm -f $TOP_DIR/cacert.pem
rm -f $TOP_DIR/cert.pem
rm -f $TOP_DIR/pk.pem |
75bbd75d |
|
a16c8210 |
# If nova api is not enabled we exit with exitcode 55 so that
# the exercise is skipped
is_service_enabled n-api || exit 55
|
75bbd75d |
# Get Certificates |
0bd2410d |
nova x509-get-root-cert $TOP_DIR/cacert.pem
nova x509-create-cert $TOP_DIR/pk.pem $TOP_DIR/cert.pem |
75bbd75d |
# Max time to wait for image to be registered
REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
BUCKET=testbucket
IMAGE=bundle.img
truncate -s 5M /tmp/$IMAGE |
07115eb5 |
euca-bundle-image -i /tmp/$IMAGE || die $LINENO "Failure bundling image $IMAGE" |
75bbd75d |
|
07115eb5 |
euca-upload-bundle --debug -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die $LINENO "Failure uploading bundle $IMAGE to $BUCKET" |
489bd2a6 |
|
75bbd75d |
AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2` |
07115eb5 |
die_if_not_set $LINENO AMI "Failure registering $BUCKET/$IMAGE" |
75bbd75d |
# Wait for the image to become available |
77b0e1d8 |
if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | grep -q available; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Image $AMI not available within $REGISTER_TIMEOUT seconds" |
75bbd75d |
fi |
80756ea7 |
# Clean up |
07115eb5 |
euca-deregister $AMI || die $LINENO "Failure deregistering $AMI" |
489bd2a6 |
set +o xtrace |
27e32699 |
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************" |