blob: 58b5d9143d45c148227069839d8cbe96a387de13 [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
Dean Troyer51fb4542012-03-09 22:21:59 -060036# Import exercise configuration
37source $TOP_DIR/exerciserc
Dean Troyer751c1522012-01-10 15:34:34 -060038
39# Instance type to create
40DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
41
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070042# Boot this image, use first AMI-format image if unset
43DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
44
Dean Troyer96288ba2012-08-17 14:11:55 -050045# Security group name
46SECGROUP=${SECGROUP:-euca_secgroup}
47
Dean Troyer27e32692012-03-16 16:16:56 -050048
49# Launching a server
50# ==================
51
Anthony Youngabda4272011-12-16 20:16:20 +000052# Find a machine image to boot
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070053IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
Jesse Andrewsf6705492011-11-01 16:04:14 -070054
Anthony Youngabda4272011-12-16 20:16:20 +000055# Add a secgroup
Dean Troyera9478412012-02-08 11:49:28 -060056if ! euca-describe-groups | grep -q $SECGROUP; then
Dean Troyer751c1522012-01-10 15:34:34 -060057 euca-add-group -d "$SECGROUP description" $SECGROUP
Dean Troyera9478412012-02-08 11:49:28 -060058 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then
Dean Troyer751c1522012-01-10 15:34:34 -060059 echo "Security group not created"
60 exit 1
61 fi
62fi
Anthony Youngabda4272011-12-16 20:16:20 +000063
64# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060065INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060066die_if_not_set INSTANCE "Failure launching instance"
Anthony Youngabda4272011-12-16 20:16:20 +000067
68# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060069if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
Todd Willey9a3066f2011-11-05 11:02:34 -040070 echo "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070071 exit 1
72fi
73
Chuck Short37258952012-08-07 10:38:44 -050074# Volumes
75# -------
76if [[ "$ENABLED_SERVICES" =~ "n-vol" || "$ENABLED_SERVICES" =~ "c-vol" ]]; then
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000077 VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2`
78 die_if_not_set VOLUME_ZONE "Failure to find zone for volume"
79
Chuck Short37258952012-08-07 10:38:44 -050080 VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
81 die_if_not_set VOLUME "Failure to create volume"
82
83 # Test that volume has been created
84 VOLUME=`euca-describe-volumes | cut -f2`
Vishvananda Ishayadc9e2882012-09-21 23:20:06 +000085 die_if_not_set VOLUME "Failure to get volume"
Chuck Short37258952012-08-07 10:38:44 -050086
87 # Test volume has become available
88 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
89 echo "volume didnt become available within $RUNNING_TIMEOUT seconds"
90 exit 1
91 fi
92
93 # Attach volume to an instance
94 euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
95 die "Failure attaching volume $VOLUME to $INSTANCE"
96 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q in-use; do sleep 1; done"; then
97 echo "Could not attach $VOLUME to $INSTANCE"
98 exit 1
99 fi
100
101 # Detach volume from an instance
102 euca-detach-volume $VOLUME || \
103 die "Failure detaching volume $VOLUME to $INSTANCE"
104 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
105 echo "Could not detach $VOLUME to $INSTANCE"
106 exit 1
107 fi
108
109 # Remove volume
110 euca-delete-volume $VOLUME || \
111 die "Failure to delete volume"
112 if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
113 echo "Could not delete $VOLUME"
114 exit 1
115 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`
Dean Troyer489bd2a2012-03-02 10:44:29 -0600122die_if_not_set 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 || \
126 die "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 || \
130 die "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
Dean Troyerc3844242011-12-30 14:27:02 -0600133if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
134 echo "Couldn't ping server with floating ip"
Anthony Youngabda4272011-12-16 20:16:20 +0000135 exit 1
136fi
137
138# Revoke pinging
Dean Troyer27e32692012-03-16 16:16:56 -0500139euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
140 die "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000141
Anthony Youngabda4272011-12-16 20:16:20 +0000142# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500143euca-disassociate-address $FLOATING_IP || \
144 die "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000145
Dean Troyer751c1522012-01-10 15:34:34 -0600146# Wait just a tick for everything above to complete so release doesn't fail
147if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
148 echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
149 exit 1
150fi
151
Anthony Youngabda4272011-12-16 20:16:20 +0000152# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500153euca-release-address $FLOATING_IP || \
154 die "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000155
Dean Troyerc3844242011-12-30 14:27:02 -0600156# Wait just a tick for everything above to complete so terminate doesn't fail
157if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
158 echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
159 exit 1
160fi
161
Anthony Youngabda4272011-12-16 20:16:20 +0000162# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500163euca-terminate-instances $INSTANCE || \
164 die "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500165
Russell Bryant243b26a2012-02-22 11:19:32 -0500166# Assure it has terminated within a reasonable time
Dean Troyer96288ba2012-08-17 14:11:55 -0500167if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q $INSTANCE; do sleep 1; done"; then
Russell Bryant243b26a2012-02-22 11:19:32 -0500168 echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
169 exit 1
170fi
171
Russell Bryante7ed17e2012-02-21 17:43:33 -0500172# Delete group
Dean Troyer96288ba2012-08-17 14:11:55 -0500173euca-delete-group $SECGROUP || die "Failure deleting security group $SECGROUP"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600174
175set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500176echo "*********************************************************************"
177echo "SUCCESS: End DevStack Exercise: $0"
178echo "*********************************************************************"