blob: 86cd67321e395a641240f099142e38aedf6cc8c1 [file] [log] [blame]
Jesse Andrewsf6705492011-11-01 16:04:14 -07001#!/usr/bin/env bash
2
Jesse Andrews9c7c9082011-11-23 10:10:53 -08003# we will use the ``euca2ools`` cli tool that wraps the python boto
Jesse Andrews9f186342011-11-01 16:05:40 -07004# library to test ec2 compatibility
Jesse Andrewsf6705492011-11-01 16:04:14 -07005#
6
Jesse Andrewsf6705492011-11-01 16:04:14 -07007# This script exits on an error so that errors don't compound and you see
8# only the first error that occured.
9set -o errexit
10
11# Print the commands being run so that we can see the command that triggers
12# an error. It is also useful for following allowing as the install occurs.
13set -o xtrace
14
Jesse Andrewsf6705492011-11-01 16:04:14 -070015# Settings
16# ========
17
18# Use openrc + stackrc + localrc for settings
Jesse Andrews787af012011-11-01 16:44:19 -070019pushd $(cd $(dirname "$0")/.. && pwd)
Jesse Andrewsf6705492011-11-01 16:04:14 -070020source ./openrc
Jesse Andrews787af012011-11-01 16:44:19 -070021popd
Jesse Andrewsf6705492011-11-01 16:04:14 -070022
Dean Troyer751c1522012-01-10 15:34:34 -060023# Max time to wait while vm goes from build to active state
24ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
25
26# Max time till the vm is bootable
27BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
28
29# Max time to wait for proper association and dis-association.
30ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
31
32# Instance type to create
33DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
34
Anthony Youngabda4272011-12-16 20:16:20 +000035# Find a machine image to boot
Jesse Andrews9c7c9082011-11-23 10:10:53 -080036IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
Jesse Andrewsf6705492011-11-01 16:04:14 -070037
Anthony Youngabda4272011-12-16 20:16:20 +000038# Define secgroup
39SECGROUP=euca_secgroup
Jesse Andrewsf6705492011-11-01 16:04:14 -070040
Anthony Youngabda4272011-12-16 20:16:20 +000041# Add a secgroup
Dean Troyera9478412012-02-08 11:49:28 -060042if ! euca-describe-groups | grep -q $SECGROUP; then
Dean Troyer751c1522012-01-10 15:34:34 -060043 euca-add-group -d "$SECGROUP description" $SECGROUP
Dean Troyera9478412012-02-08 11:49:28 -060044 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 -060045 echo "Security group not created"
46 exit 1
47 fi
48fi
Anthony Youngabda4272011-12-16 20:16:20 +000049
50# Launch it
Dean Troyer1d6e0e12011-12-23 12:45:13 -060051INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
Anthony Youngabda4272011-12-16 20:16:20 +000052
53# Assure it has booted within a reasonable time
Dean Troyerc3844242011-12-30 14:27:02 -060054if ! 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 -040055 echo "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070056 exit 1
57fi
58
Anthony Youngabda4272011-12-16 20:16:20 +000059# Allocate floating address
60FLOATING_IP=`euca-allocate-address | cut -f2`
61
Dean Troyer751c1522012-01-10 15:34:34 -060062# Associate floating address
Anthony Youngabda4272011-12-16 20:16:20 +000063euca-associate-address -i $INSTANCE $FLOATING_IP
64
Anthony Youngabda4272011-12-16 20:16:20 +000065# Authorize pinging
66euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
67
Dean Troyerc3844242011-12-30 14:27:02 -060068# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
Dean Troyerc3844242011-12-30 14:27:02 -060069if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
70 echo "Couldn't ping server with floating ip"
Anthony Youngabda4272011-12-16 20:16:20 +000071 exit 1
72fi
73
74# Revoke pinging
75euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
76
Anthony Youngabda4272011-12-16 20:16:20 +000077# Release floating address
78euca-disassociate-address $FLOATING_IP
79
Dean Troyer751c1522012-01-10 15:34:34 -060080# Wait just a tick for everything above to complete so release doesn't fail
81if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
82 echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
83 exit 1
84fi
85
Anthony Youngabda4272011-12-16 20:16:20 +000086# Release floating address
87euca-release-address $FLOATING_IP
88
Dean Troyerc3844242011-12-30 14:27:02 -060089# Wait just a tick for everything above to complete so terminate doesn't fail
90if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
91 echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
92 exit 1
93fi
94
Anthony Youngabda4272011-12-16 20:16:20 +000095# Terminate instance
Jesse Andrewsf6705492011-11-01 16:04:14 -070096euca-terminate-instances $INSTANCE
Russell Bryante7ed17e2012-02-21 17:43:33 -050097
Russell Bryant243b26a2012-02-22 11:19:32 -050098# Assure it has terminated within a reasonable time
99if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
100 echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
101 exit 1
102fi
103
Russell Bryante7ed17e2012-02-21 17:43:33 -0500104# Delete group
105euca-delete-group $SECGROUP