f6705491 |
#!/usr/bin/env bash
|
27e32699 |
# **euca.sh**
|
9c7c9083 |
# we will use the ``euca2ools`` cli tool that wraps the python boto |
9f186345 |
# library to test ec2 compatibility |
489bd2a6 |
|
27e32699 |
echo "*********************************************************************" |
489bd2a6 |
echo "Begin DevStack Exercise: $0" |
27e32699 |
echo "*********************************************************************" |
f6705491 |
# This script exits on an error so that errors don't compound and you see
# only the first error that occured.
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
|
27e32699 |
|
f6705491 |
# Settings
# ========
|
0bd2410d |
# Keep track of the current directory
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd) |
67787e6b |
VOLUME_SIZE=1
ATTACH_DEVICE=/dev/vdc |
489bd2a6 |
# Import common functions |
0bd2410d |
source $TOP_DIR/functions |
489bd2a6 |
|
0bd2410d |
# Import EC2 configuration
source $TOP_DIR/eucarc |
f6705491 |
|
5db5bfa2 |
# Import quantum functions if needed
if is_service_enabled quantum; then
source $TOP_DIR/lib/quantum
fi
|
51fb454f |
# Import exercise configuration
source $TOP_DIR/exerciserc |
751c1524 |
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
da85cdad |
# Boot this image, use first AMI image if unset |
c0c6f006 |
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
|
96288ba9 |
# Security group name
SECGROUP=${SECGROUP:-euca_secgroup}
|
27e32699 |
# Launching a server
# ==================
|
abda427a |
# Find a machine image to boot |
c0c6f006 |
IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1` |
07115eb5 |
die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME" |
f6705491 |
|
abda427a |
# Add a secgroup |
a9478413 |
if ! euca-describe-groups | grep -q $SECGROUP; then |
751c1524 |
euca-add-group -d "$SECGROUP description" $SECGROUP |
a9478413 |
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Security group not created" |
751c1524 |
fi
fi |
f6705491 |
|
abda427a |
# Launch it |
1d6e0e19 |
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2` |
07115eb5 |
die_if_not_set $LINENO INSTANCE "Failure launching instance" |
abda427a |
# Assure it has booted within a reasonable time |
c384424e |
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then |
07115eb5 |
die $LINENO "server didn't become active within $RUNNING_TIMEOUT seconds" |
f6705491 |
fi
|
37258958 |
# Volumes
# ------- |
6fd28117 |
if [[ "$ENABLED_SERVICES" =~ "c-vol" ]]; then |
dc9e2880 |
VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2` |
07115eb5 |
die_if_not_set $LINENO VOLUME_ZONE "Failure to find zone for volume" |
dc9e2880 |
|
37258958 |
VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2` |
07115eb5 |
die_if_not_set $LINENO VOLUME "Failure to create volume" |
37258958 |
# Test that volume has been created
VOLUME=`euca-describe-volumes | cut -f2` |
07115eb5 |
die_if_not_set $LINENO VOLUME "Failure to get volume" |
37258958 |
# Test volume has become available |
1e32d0ab |
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then |
07115eb5 |
die $LINENO "volume didnt become available within $RUNNING_TIMEOUT seconds" |
37258958 |
fi
# Attach volume to an instance
euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \ |
07115eb5 |
die $LINENO "Failure attaching volume $VOLUME to $INSTANCE" |
37258958 |
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q in-use; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Could not attach $VOLUME to $INSTANCE" |
37258958 |
fi
# Detach volume from an instance
euca-detach-volume $VOLUME || \ |
07115eb5 |
die $LINENO "Failure detaching volume $VOLUME to $INSTANCE" |
37258958 |
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Could not detach $VOLUME to $INSTANCE" |
37258958 |
fi
# Remove volume
euca-delete-volume $VOLUME || \ |
07115eb5 |
die $LINENO "Failure to delete volume" |
37258958 |
if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Could not delete $VOLUME" |
37258958 |
fi
else
echo "Volume Tests Skipped"
fi
|
abda427a |
# Allocate floating address
FLOATING_IP=`euca-allocate-address | cut -f2` |
07115eb5 |
die_if_not_set $LINENO FLOATING_IP "Failure allocating floating IP" |
abda427a |
|
751c1524 |
# Associate floating address |
27e32699 |
euca-associate-address -i $INSTANCE $FLOATING_IP || \ |
07115eb5 |
die $LINENO "Failure associating address $FLOATING_IP to $INSTANCE" |
abda427a |
# Authorize pinging |
27e32699 |
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \ |
07115eb5 |
die $LINENO "Failure authorizing rule in $SECGROUP" |
abda427a |
|
c384424e |
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds |
fda946e3 |
ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT |
abda427a |
# Revoke pinging |
27e32699 |
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \ |
07115eb5 |
die $LINENO "Failure revoking rule in $SECGROUP" |
abda427a |
# Release floating address |
27e32699 |
euca-disassociate-address $FLOATING_IP || \ |
07115eb5 |
die $LINENO "Failure disassociating address $FLOATING_IP" |
abda427a |
|
751c1524 |
# Wait just a tick for everything above to complete so release doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds" |
751c1524 |
fi
|
abda427a |
# Release floating address |
27e32699 |
euca-release-address $FLOATING_IP || \ |
07115eb5 |
die $LINENO "Failure releasing address $FLOATING_IP" |
abda427a |
|
c384424e |
# Wait just a tick for everything above to complete so terminate doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then |
07115eb5 |
die $LINENO "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds" |
c384424e |
fi
|
abda427a |
# Terminate instance |
27e32699 |
euca-terminate-instances $INSTANCE || \ |
07115eb5 |
die $LINENO "Failure terminating instance $INSTANCE" |
e7ed17ee |
|
796342c0 |
# Assure it has terminated within a reasonable time. The behaviour of this
# case changed with bug/836978. Requesting the status of an invalid instance
# will now return an error message including the instance id, so we need to
# filter that out. |
a1e1b5c1 |
if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -ve \"\\\(InstanceNotFound\\\|InvalidInstanceID\[.\]NotFound\\\)\" | grep -q $INSTANCE; do sleep 1; done"; then |
07115eb5 |
die $LINENO "server didn't terminate within $TERMINATE_TIMEOUT seconds" |
243b26a8 |
fi
|
da85cdad |
# Delete secgroup |
07115eb5 |
euca-delete-group $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP" |
489bd2a6 |
set +o xtrace |
27e32699 |
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************" |