blob: 4a538c63592fc6ed242a4acdd2eb033142ee3f56 [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_ZONE=cinder
28VOLUME_SIZE=1
29ATTACH_DEVICE=/dev/vdc
Dean Troyer489bd2a2012-03-02 10:44:29 -060030
31# Import common functions
Dean Troyer0bd24102012-03-08 00:33:54 -060032source $TOP_DIR/functions
Dean Troyer489bd2a2012-03-02 10:44:29 -060033
Dean Troyer0bd24102012-03-08 00:33:54 -060034# Import EC2 configuration
35source $TOP_DIR/eucarc
Jesse Andrewsf6705492011-11-01 16:04:14 -070036
Dean Troyer51fb4542012-03-09 22:21:59 -060037# Import exercise configuration
38source $TOP_DIR/exerciserc
Dean Troyer751c1522012-01-10 15:34:34 -060039
40# Instance type to create
41DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
42
Dean Troyer27e32692012-03-16 16:16:56 -050043
44# Launching a server
45# ==================
46
Anthony Youngabda4272011-12-16 20:16:20 +000047# Find a machine image to boot
Jesse Andrews9c7c9082011-11-23 10:10:53 -080048IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
Jesse Andrewsf6705492011-11-01 16:04:14 -070049
Anthony Youngabda4272011-12-16 20:16:20 +000050# Define secgroup
51SECGROUP=euca_secgroup
Jesse Andrewsf6705492011-11-01 16:04:14 -070052
Anthony Youngabda4272011-12-16 20:16:20 +000053# Add a secgroup
Dean Troyera9478412012-02-08 11:49:28 -060054if ! euca-describe-groups | grep -q $SECGROUP; then
Dean Troyer751c1522012-01-10 15:34:34 -060055 euca-add-group -d "$SECGROUP description" $SECGROUP
Dean Troyera9478412012-02-08 11:49:28 -060056 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 -060057 echo "Security group not created"
58 exit 1
59 fi
60fi
Anthony Youngabda4272011-12-16 20:16:20 +000061
62# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060063INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060064die_if_not_set INSTANCE "Failure launching instance"
Anthony Youngabda4272011-12-16 20:16:20 +000065
66# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060067if ! 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 -040068 echo "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070069 exit 1
70fi
71
Anthony Youngabda4272011-12-16 20:16:20 +000072# Allocate floating address
73FLOATING_IP=`euca-allocate-address | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060074die_if_not_set FLOATING_IP "Failure allocating floating IP"
Anthony Youngabda4272011-12-16 20:16:20 +000075
Dean Troyer751c1522012-01-10 15:34:34 -060076# Associate floating address
Dean Troyer27e32692012-03-16 16:16:56 -050077euca-associate-address -i $INSTANCE $FLOATING_IP || \
78 die "Failure associating address $FLOATING_IP to $INSTANCE"
Anthony Youngabda4272011-12-16 20:16:20 +000079
Anthony Youngabda4272011-12-16 20:16:20 +000080# Authorize pinging
Dean Troyer27e32692012-03-16 16:16:56 -050081euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
82 die "Failure authorizing rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +000083
Dean Troyerc3844242011-12-30 14:27:02 -060084# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
Dean Troyerc3844242011-12-30 14:27:02 -060085if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
86 echo "Couldn't ping server with floating ip"
Anthony Youngabda4272011-12-16 20:16:20 +000087 exit 1
88fi
89
90# Revoke pinging
Dean Troyer27e32692012-03-16 16:16:56 -050091euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
92 die "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +000093
Anthony Youngabda4272011-12-16 20:16:20 +000094# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -050095euca-disassociate-address $FLOATING_IP || \
96 die "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +000097
Dean Troyer751c1522012-01-10 15:34:34 -060098# Wait just a tick for everything above to complete so release doesn't fail
99if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
100 echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
101 exit 1
102fi
103
Anthony Youngabda4272011-12-16 20:16:20 +0000104# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500105euca-release-address $FLOATING_IP || \
106 die "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000107
Dean Troyerc3844242011-12-30 14:27:02 -0600108# Wait just a tick for everything above to complete so terminate doesn't fail
109if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
110 echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
111 exit 1
112fi
113
Anthony Youngabda4272011-12-16 20:16:20 +0000114# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500115euca-terminate-instances $INSTANCE || \
116 die "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500117
Russell Bryant243b26a2012-02-22 11:19:32 -0500118# Assure it has terminated within a reasonable time
119if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
120 echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
121 exit 1
122fi
123
Russell Bryante7ed17e2012-02-21 17:43:33 -0500124# Delete group
Dean Troyer27e32692012-03-16 16:16:56 -0500125euca-delete-group $SECGROUP || \
126 die "Failure deleting security group $SECGROUP"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600127
128set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500129echo "*********************************************************************"
130echo "SUCCESS: End DevStack Exercise: $0"
131echo "*********************************************************************"