blob: 67150e4422d57fbb98f3682e446e362e097a36ae [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
Anthony Youngabda4272011-12-16 20:16:20 +000023# Find a machine image to boot
Jesse Andrews9c7c9082011-11-23 10:10:53 -080024IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
Jesse Andrewsf6705492011-11-01 16:04:14 -070025
Anthony Youngabda4272011-12-16 20:16:20 +000026# Define secgroup
27SECGROUP=euca_secgroup
Jesse Andrewsf6705492011-11-01 16:04:14 -070028
Anthony Youngabda4272011-12-16 20:16:20 +000029# Add a secgroup
30euca-add-group -d description $SECGROUP
31
32# Launch it
33INSTANCE=`euca-run-instances -g $SECGROUP -t m1.tiny $IMAGE | grep INSTANCE | cut -f2`
34
35# Assure it has booted within a reasonable time
Todd Willey9a3066f2011-11-05 11:02:34 -040036if ! timeout $RUNNING_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
37 echo "server didn't become active within $RUNNING_TIMEOUT seconds"
Jesse Andrewsf6705492011-11-01 16:04:14 -070038 exit 1
39fi
40
Anthony Youngabda4272011-12-16 20:16:20 +000041# Allocate floating address
42FLOATING_IP=`euca-allocate-address | cut -f2`
43
44# Release floating address
45euca-associate-address -i $INSTANCE $FLOATING_IP
46
47
48# Authorize pinging
49euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
50
51# Max time till the vm is bootable
52BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
53if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
54 echo "Couldn't ping server"
55 exit 1
56fi
57
58# Revoke pinging
59euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
60
61# Delete group
62euca-delete-group $SECGROUP
63
64# Release floating address
65euca-disassociate-address $FLOATING_IP
66
67# Release floating address
68euca-release-address $FLOATING_IP
69
70# Terminate instance
Jesse Andrewsf6705492011-11-01 16:04:14 -070071euca-terminate-instances $INSTANCE