blob: fd11622722358cafa0b17d52d17a5455d96f7b96 [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)
Vishvananda Ishaya8efdbac2012-09-21 00:23:41 +000027VOLUME_ZONE=nova
Dean Troyer67787e62012-05-02 11:48:15 -050028VOLUME_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 Troyer96288ba2012-08-17 14:11:55 -050046# Security group name
47SECGROUP=${SECGROUP:-euca_secgroup}
48
Dean Troyer27e32692012-03-16 16:16:56 -050049
50# Launching a server
51# ==================
52
Anthony Youngabda4272011-12-16 20:16:20 +000053# Find a machine image to boot
Devananda van der Veenc0c6f002012-07-06 17:49:12 -070054IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
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
Chuck Short37258952012-08-07 10:38:44 -050075# Volumes
76# -------
77if [[ "$ENABLED_SERVICES" =~ "n-vol" || "$ENABLED_SERVICES" =~ "c-vol" ]]; then
78 VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
79 die_if_not_set VOLUME "Failure to create volume"
80
81 # Test that volume has been created
82 VOLUME=`euca-describe-volumes | cut -f2`
83
84 # Test volume has become available
85 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
86 echo "volume didnt become available within $RUNNING_TIMEOUT seconds"
87 exit 1
88 fi
89
90 # Attach volume to an instance
91 euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
92 die "Failure attaching volume $VOLUME to $INSTANCE"
93 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q in-use; do sleep 1; done"; then
94 echo "Could not attach $VOLUME to $INSTANCE"
95 exit 1
96 fi
97
98 # Detach volume from an instance
99 euca-detach-volume $VOLUME || \
100 die "Failure detaching volume $VOLUME to $INSTANCE"
101 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
102 echo "Could not detach $VOLUME to $INSTANCE"
103 exit 1
104 fi
105
106 # Remove volume
107 euca-delete-volume $VOLUME || \
108 die "Failure to delete volume"
109 if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
110 echo "Could not delete $VOLUME"
111 exit 1
112 fi
113else
114 echo "Volume Tests Skipped"
115fi
116
Anthony Youngabda4272011-12-16 20:16:20 +0000117# Allocate floating address
118FLOATING_IP=`euca-allocate-address | cut -f2`
Dean Troyer489bd2a2012-03-02 10:44:29 -0600119die_if_not_set FLOATING_IP "Failure allocating floating IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000120
Dean Troyer751c1522012-01-10 15:34:34 -0600121# Associate floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500122euca-associate-address -i $INSTANCE $FLOATING_IP || \
123 die "Failure associating address $FLOATING_IP to $INSTANCE"
Anthony Youngabda4272011-12-16 20:16:20 +0000124
Anthony Youngabda4272011-12-16 20:16:20 +0000125# Authorize pinging
Dean Troyer27e32692012-03-16 16:16:56 -0500126euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
127 die "Failure authorizing rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000128
Dean Troyerc3844242011-12-30 14:27:02 -0600129# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
Dean Troyerc3844242011-12-30 14:27:02 -0600130if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
131 echo "Couldn't ping server with floating ip"
Anthony Youngabda4272011-12-16 20:16:20 +0000132 exit 1
133fi
134
135# Revoke pinging
Dean Troyer27e32692012-03-16 16:16:56 -0500136euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
137 die "Failure revoking rule in $SECGROUP"
Anthony Youngabda4272011-12-16 20:16:20 +0000138
Anthony Youngabda4272011-12-16 20:16:20 +0000139# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500140euca-disassociate-address $FLOATING_IP || \
141 die "Failure disassociating address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000142
Dean Troyer751c1522012-01-10 15:34:34 -0600143# Wait just a tick for everything above to complete so release doesn't fail
144if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
145 echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
146 exit 1
147fi
148
Anthony Youngabda4272011-12-16 20:16:20 +0000149# Release floating address
Dean Troyer27e32692012-03-16 16:16:56 -0500150euca-release-address $FLOATING_IP || \
151 die "Failure releasing address $FLOATING_IP"
Anthony Youngabda4272011-12-16 20:16:20 +0000152
Dean Troyerc3844242011-12-30 14:27:02 -0600153# Wait just a tick for everything above to complete so terminate doesn't fail
154if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
155 echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
156 exit 1
157fi
158
Anthony Youngabda4272011-12-16 20:16:20 +0000159# Terminate instance
Dean Troyer27e32692012-03-16 16:16:56 -0500160euca-terminate-instances $INSTANCE || \
161 die "Failure terminating instance $INSTANCE"
Russell Bryante7ed17e2012-02-21 17:43:33 -0500162
Russell Bryant243b26a2012-02-22 11:19:32 -0500163# Assure it has terminated within a reasonable time
Dean Troyer96288ba2012-08-17 14:11:55 -0500164if ! 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 -0500165 echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
166 exit 1
167fi
168
Russell Bryante7ed17e2012-02-21 17:43:33 -0500169# Delete group
Dean Troyer96288ba2012-08-17 14:11:55 -0500170euca-delete-group $SECGROUP || die "Failure deleting security group $SECGROUP"
Dean Troyer489bd2a2012-03-02 10:44:29 -0600171
172set +o xtrace
Dean Troyer27e32692012-03-16 16:16:56 -0500173echo "*********************************************************************"
174echo "SUCCESS: End DevStack Exercise: $0"
175echo "*********************************************************************"