2011-11-01 16:04:14 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2012-03-16 16:16:56 -05:00
|
|
|
# **euca.sh**
|
|
|
|
|
2011-11-23 10:10:53 -08:00
|
|
|
# we will use the ``euca2ools`` cli tool that wraps the python boto
|
2011-11-01 16:05:40 -07:00
|
|
|
# library to test ec2 compatibility
|
2012-03-02 10:44:29 -06:00
|
|
|
|
2012-03-16 16:16:56 -05:00
|
|
|
echo "*********************************************************************"
|
2012-03-02 10:44:29 -06:00
|
|
|
echo "Begin DevStack Exercise: $0"
|
2012-03-16 16:16:56 -05:00
|
|
|
echo "*********************************************************************"
|
2011-11-01 16:04:14 -07:00
|
|
|
|
|
|
|
# This script exits on an error so that errors don't compound and you see
|
2013-06-30 04:32:27 -07:00
|
|
|
# only the first error that occurred.
|
2011-11-01 16:04:14 -07:00
|
|
|
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
|
|
|
|
|
2012-03-16 16:16:56 -05:00
|
|
|
|
2011-11-01 16:04:14 -07:00
|
|
|
# Settings
|
|
|
|
# ========
|
|
|
|
|
2012-03-08 00:33:54 -06:00
|
|
|
# Keep track of the current directory
|
|
|
|
EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
|
|
|
|
TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
|
2012-05-02 11:48:15 -05:00
|
|
|
VOLUME_SIZE=1
|
|
|
|
ATTACH_DEVICE=/dev/vdc
|
2012-03-02 10:44:29 -06:00
|
|
|
|
|
|
|
# Import common functions
|
2012-03-08 00:33:54 -06:00
|
|
|
source $TOP_DIR/functions
|
2012-03-02 10:44:29 -06:00
|
|
|
|
2012-03-08 00:33:54 -06:00
|
|
|
# Import EC2 configuration
|
|
|
|
source $TOP_DIR/eucarc
|
2011-11-01 16:04:14 -07:00
|
|
|
|
2012-03-09 22:21:59 -06:00
|
|
|
# Import exercise configuration
|
|
|
|
source $TOP_DIR/exerciserc
|
2012-01-10 15:34:34 -06:00
|
|
|
|
2014-03-17 19:47:14 -07:00
|
|
|
# Import project functions
|
2015-03-25 11:33:51 -05:00
|
|
|
source $TOP_DIR/lib/neutron-legacy
|
2014-03-17 19:47:14 -07:00
|
|
|
|
2014-01-12 19:35:43 +00:00
|
|
|
# If nova api is not enabled we exit with exitcode 55 so that
|
|
|
|
# the exercise is skipped
|
|
|
|
is_service_enabled n-api || exit 55
|
|
|
|
|
2012-01-10 15:34:34 -06:00
|
|
|
# Instance type to create
|
|
|
|
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
|
|
|
|
2013-02-15 11:07:14 -06:00
|
|
|
# Boot this image, use first AMI image if unset
|
2012-07-06 17:49:12 -07:00
|
|
|
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
|
|
|
|
|
2012-08-17 14:11:55 -05:00
|
|
|
# Security group name
|
|
|
|
SECGROUP=${SECGROUP:-euca_secgroup}
|
|
|
|
|
2012-03-16 16:16:56 -05:00
|
|
|
|
|
|
|
# Launching a server
|
|
|
|
# ==================
|
|
|
|
|
2011-12-16 20:16:20 +00:00
|
|
|
# Find a machine image to boot
|
2012-07-06 17:49:12 -07:00
|
|
|
IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
|
2013-02-26 12:38:18 -08:00
|
|
|
die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
|
2011-11-01 16:04:14 -07:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
if is_service_enabled n-cell; then
|
|
|
|
# Cells does not support security groups, so force the use of "default"
|
|
|
|
SECGROUP="default"
|
|
|
|
echo "Using the default security group because of Cells."
|
|
|
|
else
|
|
|
|
# Add a secgroup
|
|
|
|
if ! euca-describe-groups | grep -q $SECGROUP; then
|
|
|
|
euca-add-group -d "$SECGROUP description" $SECGROUP
|
|
|
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then
|
|
|
|
die $LINENO "Security group not created"
|
|
|
|
fi
|
2012-01-10 15:34:34 -06:00
|
|
|
fi
|
|
|
|
fi
|
2011-11-01 16:04:14 -07:00
|
|
|
|
2011-12-16 20:16:20 +00:00
|
|
|
# Launch it
|
2011-12-23 12:45:13 -06:00
|
|
|
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
|
2013-02-26 12:38:18 -08:00
|
|
|
die_if_not_set $LINENO INSTANCE "Failure launching instance"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
|
|
|
# Assure it has booted within a reasonable time
|
2011-12-30 14:27:02 -06:00
|
|
|
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
|
2013-02-26 12:38:18 -08:00
|
|
|
die $LINENO "server didn't become active within $RUNNING_TIMEOUT seconds"
|
2011-11-01 16:04:14 -07:00
|
|
|
fi
|
|
|
|
|
2012-08-07 10:38:44 -05:00
|
|
|
# Volumes
|
|
|
|
# -------
|
2014-03-17 19:47:14 -07:00
|
|
|
if is_service_enabled c-vol && ! is_service_enabled n-cell && [ "$VIRT_DRIVER" != "ironic" ]; then
|
2013-10-22 10:06:06 -04:00
|
|
|
VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2`
|
|
|
|
die_if_not_set $LINENO VOLUME_ZONE "Failure to find zone for volume"
|
|
|
|
|
|
|
|
VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
|
|
|
|
die_if_not_set $LINENO VOLUME "Failure to create volume"
|
|
|
|
|
|
|
|
# Test that volume has been created
|
|
|
|
VOLUME=`euca-describe-volumes $VOLUME | cut -f2`
|
|
|
|
die_if_not_set $LINENO VOLUME "Failure to get volume"
|
|
|
|
|
|
|
|
# Test volume has become available
|
|
|
|
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
|
|
|
|
die $LINENO "volume didn't become available within $RUNNING_TIMEOUT seconds"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Attach volume to an instance
|
|
|
|
euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
|
|
|
|
die $LINENO "Failure attaching volume $VOLUME to $INSTANCE"
|
|
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -A 1 in-use | grep -q attach; do sleep 1; done"; then
|
|
|
|
die $LINENO "Could not attach $VOLUME to $INSTANCE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Detach volume from an instance
|
|
|
|
euca-detach-volume $VOLUME || \
|
|
|
|
die $LINENO "Failure detaching volume $VOLUME to $INSTANCE"
|
2012-08-07 10:38:44 -05:00
|
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
|
2013-02-26 12:38:18 -08:00
|
|
|
die $LINENO "Could not detach $VOLUME to $INSTANCE"
|
2012-08-07 10:38:44 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove volume
|
|
|
|
euca-delete-volume $VOLUME || \
|
2013-02-26 12:38:18 -08:00
|
|
|
die $LINENO "Failure to delete volume"
|
2012-08-07 10:38:44 -05:00
|
|
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
|
2013-10-22 10:06:06 -04:00
|
|
|
die $LINENO "Could not delete $VOLUME"
|
2012-08-07 10:38:44 -05:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Volume Tests Skipped"
|
|
|
|
fi
|
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
if is_service_enabled n-cell; then
|
|
|
|
echo "Floating IP Tests Skipped because of Cells."
|
|
|
|
else
|
|
|
|
# Allocate floating address
|
|
|
|
FLOATING_IP=`euca-allocate-address | cut -f2`
|
|
|
|
die_if_not_set $LINENO FLOATING_IP "Failure allocating floating IP"
|
2013-08-06 15:25:01 +02:00
|
|
|
# describe all instances at this moment
|
|
|
|
euca-describe-instances
|
2013-07-24 03:56:13 -07:00
|
|
|
# Associate floating address
|
|
|
|
euca-associate-address -i $INSTANCE $FLOATING_IP || \
|
|
|
|
die $LINENO "Failure associating address $FLOATING_IP to $INSTANCE"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# Authorize pinging
|
|
|
|
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
|
|
|
|
die $LINENO "Failure authorizing rule in $SECGROUP"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
|
2015-04-16 08:58:32 -04:00
|
|
|
ping_check $FLOATING_IP $ASSOCIATE_TIMEOUT "$PUBLIC_NETWORK_NAME"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# Revoke pinging
|
|
|
|
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
|
|
|
|
die $LINENO "Failure revoking rule in $SECGROUP"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# Release floating address
|
|
|
|
euca-disassociate-address $FLOATING_IP || \
|
|
|
|
die $LINENO "Failure disassociating address $FLOATING_IP"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# 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
|
|
|
|
die $LINENO "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
|
|
|
|
fi
|
2012-01-10 15:34:34 -06:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# Release floating address
|
|
|
|
euca-release-address $FLOATING_IP || \
|
|
|
|
die $LINENO "Failure releasing address $FLOATING_IP"
|
2011-12-16 20:16:20 +00:00
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
# 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
|
|
|
|
die $LINENO "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
|
|
|
|
fi
|
2011-12-30 14:27:02 -06:00
|
|
|
fi
|
|
|
|
|
2011-12-16 20:16:20 +00:00
|
|
|
# Terminate instance
|
2012-03-16 16:16:56 -05:00
|
|
|
euca-terminate-instances $INSTANCE || \
|
2013-02-26 12:38:18 -08:00
|
|
|
die $LINENO "Failure terminating instance $INSTANCE"
|
2012-02-21 17:43:33 -05:00
|
|
|
|
2012-12-28 11:08:20 +11:00
|
|
|
# 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.
|
2013-06-10 00:23:38 +00:00
|
|
|
if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -ve '\(InstanceNotFound\|InvalidInstanceID\.NotFound\)' | grep -q $INSTANCE; do sleep 1; done"; then
|
2013-02-26 12:38:18 -08:00
|
|
|
die $LINENO "server didn't terminate within $TERMINATE_TIMEOUT seconds"
|
2012-02-22 11:19:32 -05:00
|
|
|
fi
|
|
|
|
|
2013-07-24 03:56:13 -07:00
|
|
|
if [[ "$SECGROUP" = "default" ]] ; then
|
|
|
|
echo "Skipping deleting default security group"
|
|
|
|
else
|
|
|
|
# Delete secgroup
|
|
|
|
euca-delete-group $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
|
|
|
|
fi
|
2012-03-02 10:44:29 -06:00
|
|
|
|
|
|
|
set +o xtrace
|
2012-03-16 16:16:56 -05:00
|
|
|
echo "*********************************************************************"
|
|
|
|
echo "SUCCESS: End DevStack Exercise: $0"
|
|
|
|
echo "*********************************************************************"
|