blob: d7042794311796531c040e03a7908eeafe69e9b9 [file] [log] [blame]
Jesse Andrewsf6705492011-11-01 16:04:14 -07001#!/usr/bin/env bash
2
Dean Troyer27e32692012-03-16 16:16:56 -05003# **euca.sh**
4
Jesse Andrews9c7c9082011-11-23 10:10:53 -08005# we will use the ``euca2ools`` cli tool that wraps the python boto
Jesse Andrews9f186342011-11-01 16:05:40 -07006# library to test ec2 compatibility
Dean Troyer489bd2a2012-03-02 10:44:29 -06007
Dean Troyer27e32692012-03-16 16:16:56 -05008echo "*********************************************************************"
Dean Troyer489bd2a2012-03-02 10:44:29 -06009echo "Begin DevStack Exercise: $0"
Dean Troyer27e32692012-03-16 16:16:56 -050010echo "*********************************************************************"
Jesse Andrewsf6705492011-11-01 16:04:14 -070011
Jesse Andrewsf6705492011-11-01 16:04:14 -070012# 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
Dean Troyer27e32692012-03-16 16:16:56 -050020
Jesse Andrewsf6705492011-11-01 16:04:14 -070021# Settings
22# ========
23
Dean Troyer0bd24102012-03-08 00:33:54 -060024# Keep track of the current directory
25EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
26TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
Dean Troyer67787e62012-05-02 11:48:15 -050027VOLUME_SIZE=1
28ATTACH_DEVICE=/dev/vdc
Dean Troyer489bd2a2012-03-02 10:44:29 -060029
30# Import common functions
Dean Troyer0bd24102012-03-08 00:33:54 -060031source $TOP_DIR/functions
Dean Troyer489bd2a2012-03-02 10:44:29 -060032
Dean Troyer0bd24102012-03-08 00:33:54 -060033# Import EC2 configuration
34source $TOP_DIR/eucarc
Jesse Andrewsf6705492011-11-01 16:04:14 -070035
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070036# Import quantum functions if needed
37if is_service_enabled quantum; then
38 source $TOP_DIR/lib/quantum
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070039fi
40
Dean Troyer51fb4542012-03-09 22:21:59 -060041# Import exercise configuration
42source $TOP_DIR/exerciserc
Dean Troyer751c1522012-01-10 15:34:34 -060043
44# Instance type to create
45DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
46
Dean Troyerda85cda2013-02-15 11:07:14 -060047# Boot this image, use first AMI image if unset
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070048DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
49
Dean Troyer96288ba2012-08-17 14:11:55 -050050# Security group name
51SECGROUP=${SECGROUP:-euca_secgroup}
52
Dean Troyer27e32692012-03-16 16:16:56 -050053
54# Launching a server
55# ==================
56
Anthony Youngabda4272011-12-16 20:16:20 +000057# Find a machine image to boot
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070058IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
Nachi Ueno07115eb2013-02-26 12:38:18 -080059die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
Jesse Andrewsf6705492011-11-01 16:04:14 -070060
Anthony Youngabda4272011-12-16 20:16:20 +000061# Add a secgroup
Dean Troyera9478412012-02-08 11:49:28 -060062if ! euca-describe-groups | grep -q $SECGROUP; then
Dean Troyer751c1522012-01-10 15:34:34 -060063 euca-add-group -d "$SECGROUP description" $SECGROUP
Dean Troyera9478412012-02-08 11:49:28 -060064 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080065 die $LINENO "Security group not created"
Dean Troyer751c1522012-01-10 15:34:34 -060066 fi
67fi
Anthony Youngabda4272011-12-16 20:16:20 +000068
69# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060070INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080071die_if_not_set $LINENO INSTANCE "Failure launching instance"
Anthony Youngabda4272011-12-16 20:16:20 +000072
73# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060074if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080075 die $LINENO "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070076fi
77
Chuck Short37258952012-08-07 10:38:44 -050078# Volumes
79# -------
Joe Gordon6fd28112012-11-13 16:55:41 -080080if [[ "$ENABLED_SERVICES" =~ "c-vol" ]]; then
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000081 VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080082 die_if_not_set $LINENO VOLUME_ZONE "Failure to find zone for volume"
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000083
Chuck Short37258952012-08-07 10:38:44 -050084 VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080085 die_if_not_set $LINENO VOLUME "Failure to create volume"
Chuck Short37258952012-08-07 10:38:44 -050086
87 # Test that volume has been created
88 VOLUME=`euca-describe-volumes | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080089 die_if_not_set $LINENO VOLUME "Failure to get volume"
Chuck Short37258952012-08-07 10:38:44 -050090
91 # Test volume has become available
Mate Lakat1e32d0a2012-12-07 12:46:15 +000092 if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080093 die $LINENO "volume didnt become available within $RUNNING_TIMEOUT seconds"
Chuck Short37258952012-08-07 10:38:44 -050094 fi
95
96 # Attach volume to an instance
97 euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -080098 die $LINENO "Failure attaching volume $VOLUME to $INSTANCE"
Chris Yeohc2fc5f82013-04-22 10:33:07 +093099 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -A 1 in-use | grep -q attach; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800100 die $LINENO "Could not attach $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500101 fi
102
103 # Detach volume from an instance
104 euca-detach-volume $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800105 die $LINENO "Failure detaching volume $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500106 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800107 die $LINENO "Could not detach $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500108 fi
109
110 # Remove volume
111 euca-delete-volume $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800112 die $LINENO "Failure to delete volume"
Chuck Short37258952012-08-07 10:38:44 -0500113 if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800114 die $LINENO "Could not delete $VOLUME"
Chuck Short37258952012-08-07 10:38:44 -0500115 fi
116else
117 echo "Volume Tests Skipped"
118fi
119
Anthony Youngabda4272011-12-16 20:16:20 +0000120# Allocate floating address
121FLOATING_IP=`euca-allocate-address | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -0800122die_if_not_set $LINENO FLOATING_IP "Failure allocating floating IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000123
Dean Troyer751c1522012-01-10 15:34:34 -0600124# Associate floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500125euca-associate-address -i $INSTANCE $FLOATING_IP || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800126 die $LINENO "Failure associating address $FLOATING_IP to $INSTANCE"
Anthony Youngabda4272011-12-16 20:16:20 +0000127
Anthony Youngabda4272011-12-16 20:16:20 +0000128# Authorize pinging
Dean Troyer27e32692012-03-16 16:16:56 -0500129euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800130 die $LINENO "Failure authorizing rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000131
Dean Troyerc3844242011-12-30 14:27:02 -0600132# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
Nachi Uenofda946e2012-10-24 17:26:02 -0700133ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
Anthony Youngabda4272011-12-16 20:16:20 +0000134
135# Revoke pinging
Dean Troyer27e32692012-03-16 16:16:56 -0500136euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800137 die $LINENO "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000138
Anthony Youngabda4272011-12-16 20:16:20 +0000139# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500140euca-disassociate-address $FLOATING_IP || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800141 die $LINENO "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000142
Dean Troyer751c1522012-01-10 15:34:34 -0600143# Wait just a tick for everything above to complete so release doesn't fail
144if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800145 die $LINENO "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
Dean Troyer751c1522012-01-10 15:34:34 -0600146fi
147
Anthony Youngabda4272011-12-16 20:16:20 +0000148# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500149euca-release-address $FLOATING_IP || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800150 die $LINENO "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000151
Dean Troyerc3844242011-12-30 14:27:02 -0600152# Wait just a tick for everything above to complete so terminate doesn't fail
153if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800154 die $LINENO "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
Dean Troyerc3844242011-12-30 14:27:02 -0600155fi
156
Anthony Youngabda4272011-12-16 20:16:20 +0000157# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500158euca-terminate-instances $INSTANCE || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800159 die $LINENO "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500160
Michael Still796342c2012-12-28 11:08:20 +1100161# Assure it has terminated within a reasonable time. The behaviour of this
162# case changed with bug/836978. Requesting the status of an invalid instance
163# will now return an error message including the instance id, so we need to
164# filter that out.
Attila Fazekasa1e1b5c2013-01-16 08:38:17 +0100165if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -ve \"\\\(InstanceNotFound\\\|InvalidInstanceID\[.\]NotFound\\\)\" | grep -q $INSTANCE; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800166 die $LINENO "server didn't terminate within $TERMINATE_TIMEOUT seconds"
Russell Bryant243b26a2012-02-22 11:19:32 -0500167fi
168
Dean Troyerda85cda2013-02-15 11:07:14 -0600169# Delete secgroup
Nachi Ueno07115eb2013-02-26 12:38:18 -0800170euca-delete-group $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600171
172set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500173echo "*********************************************************************"
174echo "SUCCESS: End DevStack Exercise: $0"
175echo "*********************************************************************"