blob: 64c001423661057b42e766dc7574e4d0086c74d4 [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
Joe Gordon46400262013-06-30 04:32:27 -070013# only the first error that occurred.
Jesse Andrewsf6705492011-11-01 16:04:14 -070014set -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
Mark McClainb05c8762013-07-06 23:29:39 -040036# Import neutron functions if needed
37if is_service_enabled neutron; then
38 source $TOP_DIR/lib/neutron
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
Dean Troyer2aa2a892013-08-04 19:53:19 -050044# Skip if the hypervisor is Docker
45[[ "$VIRT_DRIVER" == "docker" ]] && exit 55
46
Dean Troyer751c1522012-01-10 15:34:34 -060047# Instance type to create
48DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
49
Dean Troyerda85cda2013-02-15 11:07:14 -060050# Boot this image, use first AMI image if unset
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070051DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
52
Dean Troyer96288ba2012-08-17 14:11:55 -050053# Security group name
54SECGROUP=${SECGROUP:-euca_secgroup}
55
Dean Troyer27e32692012-03-16 16:16:56 -050056
57# Launching a server
58# ==================
59
Anthony Youngabda4272011-12-16 20:16:20 +000060# Find a machine image to boot
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070061IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
Nachi Ueno07115eb2013-02-26 12:38:18 -080062die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
Jesse Andrewsf6705492011-11-01 16:04:14 -070063
Chris Behrensc62c2b92013-07-24 03:56:13 -070064if is_service_enabled n-cell; then
65 # Cells does not support security groups, so force the use of "default"
66 SECGROUP="default"
67 echo "Using the default security group because of Cells."
68else
69 # Add a secgroup
70 if ! euca-describe-groups | grep -q $SECGROUP; then
71 euca-add-group -d "$SECGROUP description" $SECGROUP
72 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then
73 die $LINENO "Security group not created"
74 fi
Dean Troyer751c1522012-01-10 15:34:34 -060075 fi
76fi
Anthony Youngabda4272011-12-16 20:16:20 +000077
78# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060079INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080080die_if_not_set $LINENO INSTANCE "Failure launching instance"
Anthony Youngabda4272011-12-16 20:16:20 +000081
82# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060083if ! 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 -080084 die $LINENO "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070085fi
86
Chuck Short37258952012-08-07 10:38:44 -050087# Volumes
88# -------
Chris Behrensc62c2b92013-07-24 03:56:13 -070089if is_service_enabled c-vol && ! is_service_enabled n-cell; then
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000090 VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080091 die_if_not_set $LINENO VOLUME_ZONE "Failure to find zone for volume"
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000092
Chuck Short37258952012-08-07 10:38:44 -050093 VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080094 die_if_not_set $LINENO VOLUME "Failure to create volume"
Chuck Short37258952012-08-07 10:38:44 -050095
96 # Test that volume has been created
Kui Shia8a11cf2013-06-16 10:11:46 +080097 VOLUME=`euca-describe-volumes $VOLUME | cut -f2`
Nachi Ueno07115eb2013-02-26 12:38:18 -080098 die_if_not_set $LINENO VOLUME "Failure to get volume"
Chuck Short37258952012-08-07 10:38:44 -050099
100 # Test volume has become available
Mate Lakat1e32d0a2012-12-07 12:46:15 +0000101 if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
Joe Gordon46400262013-06-30 04:32:27 -0700102 die $LINENO "volume didn't become available within $RUNNING_TIMEOUT seconds"
Chuck Short37258952012-08-07 10:38:44 -0500103 fi
104
105 # Attach volume to an instance
106 euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800107 die $LINENO "Failure attaching volume $VOLUME to $INSTANCE"
Chris Yeohc2fc5f82013-04-22 10:33:07 +0930108 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 -0800109 die $LINENO "Could not attach $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500110 fi
111
112 # Detach volume from an instance
113 euca-detach-volume $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800114 die $LINENO "Failure detaching volume $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500115 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 -0800116 die $LINENO "Could not detach $VOLUME to $INSTANCE"
Chuck Short37258952012-08-07 10:38:44 -0500117 fi
118
119 # Remove volume
120 euca-delete-volume $VOLUME || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800121 die $LINENO "Failure to delete volume"
Chuck Short37258952012-08-07 10:38:44 -0500122 if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800123 die $LINENO "Could not delete $VOLUME"
Chuck Short37258952012-08-07 10:38:44 -0500124 fi
125else
126 echo "Volume Tests Skipped"
127fi
128
Chris Behrensc62c2b92013-07-24 03:56:13 -0700129if is_service_enabled n-cell; then
130 echo "Floating IP Tests Skipped because of Cells."
131else
132 # Allocate floating address
133 FLOATING_IP=`euca-allocate-address | cut -f2`
134 die_if_not_set $LINENO FLOATING_IP "Failure allocating floating IP"
Attila Fazekas1a794a32013-08-06 15:25:01 +0200135 # describe all instances at this moment
136 euca-describe-instances
Chris Behrensc62c2b92013-07-24 03:56:13 -0700137 # Associate floating address
138 euca-associate-address -i $INSTANCE $FLOATING_IP || \
139 die $LINENO "Failure associating address $FLOATING_IP to $INSTANCE"
Anthony Youngabda4272011-12-16 20:16:20 +0000140
Chris Behrensc62c2b92013-07-24 03:56:13 -0700141 # Authorize pinging
142 euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
143 die $LINENO "Failure authorizing rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000144
Chris Behrensc62c2b92013-07-24 03:56:13 -0700145 # Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
146 ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
Anthony Youngabda4272011-12-16 20:16:20 +0000147
Chris Behrensc62c2b92013-07-24 03:56:13 -0700148 # Revoke pinging
149 euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
150 die $LINENO "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000151
Chris Behrensc62c2b92013-07-24 03:56:13 -0700152 # Release floating address
153 euca-disassociate-address $FLOATING_IP || \
154 die $LINENO "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000155
Chris Behrensc62c2b92013-07-24 03:56:13 -0700156 # Wait just a tick for everything above to complete so release doesn't fail
157 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
158 die $LINENO "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
159 fi
Dean Troyer751c1522012-01-10 15:34:34 -0600160
Chris Behrensc62c2b92013-07-24 03:56:13 -0700161 # Release floating address
162 euca-release-address $FLOATING_IP || \
163 die $LINENO "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000164
Chris Behrensc62c2b92013-07-24 03:56:13 -0700165 # Wait just a tick for everything above to complete so terminate doesn't fail
166 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
167 die $LINENO "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
168 fi
Dean Troyerc3844242011-12-30 14:27:02 -0600169fi
170
Anthony Youngabda4272011-12-16 20:16:20 +0000171# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500172euca-terminate-instances $INSTANCE || \
Nachi Ueno07115eb2013-02-26 12:38:18 -0800173 die $LINENO "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500174
Michael Still796342c2012-12-28 11:08:20 +1100175# Assure it has terminated within a reasonable time. The behaviour of this
176# case changed with bug/836978. Requesting the status of an invalid instance
177# will now return an error message including the instance id, so we need to
178# filter that out.
Jeremy Stanley18b09062013-06-10 00:23:38 +0000179if ! 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 -0800180 die $LINENO "server didn't terminate within $TERMINATE_TIMEOUT seconds"
Russell Bryant243b26a2012-02-22 11:19:32 -0500181fi
182
Chris Behrensc62c2b92013-07-24 03:56:13 -0700183if [[ "$SECGROUP" = "default" ]] ; then
184 echo "Skipping deleting default security group"
185else
186 # Delete secgroup
187 euca-delete-group $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
188fi
Dean Troyer489bd2a2012-03-02 10:44:29 -0600189
190set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500191echo "*********************************************************************"
192echo "SUCCESS: End DevStack Exercise: $0"
193echo "*********************************************************************"