blob: 9f7aed171f024221fdf669fee5d574f8db143f75 [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
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070043# Boot this image, use first AMI-format image if unset
44DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
45
Dean Troyer27e32692012-03-16 16:16:56 -050046
47# Launching a server
48# ==================
49
Anthony Youngabda4272011-12-16 20:16:20 +000050# Find a machine image to boot
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070051IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
Jesse Andrewsf6705492011-11-01 16:04:14 -070052
Anthony Youngabda4272011-12-16 20:16:20 +000053# Define secgroup
54SECGROUP=euca_secgroup
Jesse Andrewsf6705492011-11-01 16:04:14 -070055
Anthony Youngabda4272011-12-16 20:16:20 +000056# Add a secgroup
Dean Troyera9478412012-02-08 11:49:28 -060057if ! euca-describe-groups | grep -q $SECGROUP; then
Dean Troyer751c1522012-01-10 15:34:34 -060058 euca-add-group -d "$SECGROUP description" $SECGROUP
Dean Troyera9478412012-02-08 11:49:28 -060059 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 -060060 echo "Security group not created"
61 exit 1
62 fi
63fi
Anthony Youngabda4272011-12-16 20:16:20 +000064
65# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060066INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060067die_if_not_set INSTANCE "Failure launching instance"
Anthony Youngabda4272011-12-16 20:16:20 +000068
69# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060070if ! 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 -040071 echo "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070072 exit 1
73fi
74
Anthony Youngabda4272011-12-16 20:16:20 +000075# Allocate floating address
76FLOATING_IP=`euca-allocate-address | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -060077die_if_not_set FLOATING_IP "Failure allocating floating IP"
Anthony Youngabda4272011-12-16 20:16:20 +000078
Dean Troyer751c1522012-01-10 15:34:34 -060079# Associate floating address
Dean Troyer27e32692012-03-16 16:16:56 -050080euca-associate-address -i $INSTANCE $FLOATING_IP || \
81 die "Failure associating address $FLOATING_IP to $INSTANCE"
Anthony Youngabda4272011-12-16 20:16:20 +000082
Anthony Youngabda4272011-12-16 20:16:20 +000083# Authorize pinging
Dean Troyer27e32692012-03-16 16:16:56 -050084euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
85 die "Failure authorizing rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +000086
Dean Troyerc3844242011-12-30 14:27:02 -060087# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
Dean Troyerc3844242011-12-30 14:27:02 -060088if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
89 echo "Couldn't ping server with floating ip"
Anthony Youngabda4272011-12-16 20:16:20 +000090 exit 1
91fi
92
93# Revoke pinging
Dean Troyer27e32692012-03-16 16:16:56 -050094euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
95 die "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +000096
Anthony Youngabda4272011-12-16 20:16:20 +000097# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -050098euca-disassociate-address $FLOATING_IP || \
99 die "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000100
Dean Troyer751c1522012-01-10 15:34:34 -0600101# Wait just a tick for everything above to complete so release doesn't fail
102if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
103 echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
104 exit 1
105fi
106
Anthony Youngabda4272011-12-16 20:16:20 +0000107# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500108euca-release-address $FLOATING_IP || \
109 die "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000110
Dean Troyerc3844242011-12-30 14:27:02 -0600111# Wait just a tick for everything above to complete so terminate doesn't fail
112if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
113 echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
114 exit 1
115fi
116
Anthony Youngabda4272011-12-16 20:16:20 +0000117# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500118euca-terminate-instances $INSTANCE || \
119 die "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500120
Russell Bryant243b26a2012-02-22 11:19:32 -0500121# Assure it has terminated within a reasonable time
122if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
123 echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
124 exit 1
125fi
126
Russell Bryante7ed17e2012-02-21 17:43:33 -0500127# Delete group
Dean Troyer27e32692012-03-16 16:16:56 -0500128euca-delete-group $SECGROUP || \
129 die "Failure deleting security group $SECGROUP"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600130
131set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500132echo "*********************************************************************"
133echo "SUCCESS: End DevStack Exercise: $0"
134echo "*********************************************************************"