Increase exercise robustness
* increase some timeouts * tolerate existing security groups and rules * add optional DEFAULT_IMAGE_NAME to select the image to boot * fix image lists via glance Change-Id: I31ae743e602f69a2c9f872273273f542fc4afda3
This commit is contained in:
parent
19721bc79d
commit
751c15243f
@ -20,6 +20,18 @@ pushd $(cd $(dirname "$0")/.. && pwd)
|
|||||||
source ./openrc
|
source ./openrc
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
# Max time to wait while vm goes from build to active state
|
||||||
|
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time till the vm is bootable
|
||||||
|
BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time to wait for proper association and dis-association.
|
||||||
|
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
|
||||||
|
|
||||||
|
# Instance type to create
|
||||||
|
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
||||||
|
|
||||||
# Find a machine image to boot
|
# Find a machine image to boot
|
||||||
IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
|
IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
|
||||||
|
|
||||||
@ -27,10 +39,15 @@ IMAGE=`euca-describe-images | grep machine | cut -f2 | head -n1`
|
|||||||
SECGROUP=euca_secgroup
|
SECGROUP=euca_secgroup
|
||||||
|
|
||||||
# Add a secgroup
|
# Add a secgroup
|
||||||
euca-add-group -d description $SECGROUP
|
if ! euca-describe-group | grep -q $SECGROUP; then
|
||||||
|
euca-add-group -d "$SECGROUP description" $SECGROUP
|
||||||
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-group | grep -q $SECGROUP; do sleep 1; done"; then
|
||||||
|
echo "Security group not created"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Launch it
|
# Launch it
|
||||||
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
|
||||||
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
|
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
|
||||||
|
|
||||||
# Assure it has booted within a reasonable time
|
# Assure it has booted within a reasonable time
|
||||||
@ -42,15 +59,13 @@ fi
|
|||||||
# Allocate floating address
|
# Allocate floating address
|
||||||
FLOATING_IP=`euca-allocate-address | cut -f2`
|
FLOATING_IP=`euca-allocate-address | cut -f2`
|
||||||
|
|
||||||
# Release floating address
|
# Associate floating address
|
||||||
euca-associate-address -i $INSTANCE $FLOATING_IP
|
euca-associate-address -i $INSTANCE $FLOATING_IP
|
||||||
|
|
||||||
|
|
||||||
# Authorize pinging
|
# Authorize pinging
|
||||||
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
|
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
|
||||||
|
|
||||||
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
|
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
|
||||||
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
|
|
||||||
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
|
||||||
echo "Couldn't ping server with floating ip"
|
echo "Couldn't ping server with floating ip"
|
||||||
exit 1
|
exit 1
|
||||||
@ -65,6 +80,12 @@ euca-delete-group $SECGROUP
|
|||||||
# Release floating address
|
# Release floating address
|
||||||
euca-disassociate-address $FLOATING_IP
|
euca-disassociate-address $FLOATING_IP
|
||||||
|
|
||||||
|
# Wait just a tick for everything above to complete so release doesn't fail
|
||||||
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
|
||||||
|
echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Release floating address
|
# Release floating address
|
||||||
euca-release-address $FLOATING_IP
|
euca-release-address $FLOATING_IP
|
||||||
|
|
||||||
|
@ -24,9 +24,28 @@ pushd $(cd $(dirname "$0")/.. && pwd)
|
|||||||
source ./openrc
|
source ./openrc
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# Set some defaults
|
# Max time to wait while vm goes from build to active state
|
||||||
|
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time till the vm is bootable
|
||||||
|
BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time to wait for proper association and dis-association.
|
||||||
|
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
|
||||||
|
|
||||||
|
# Instance type to create
|
||||||
|
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
||||||
|
|
||||||
|
# Boot this image, use first AMi image if unset
|
||||||
|
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
|
||||||
|
|
||||||
|
# Security group name
|
||||||
|
SECGROUP=${SECGROUP:-test_secgroup}
|
||||||
|
|
||||||
|
# Default floating IP pool name
|
||||||
DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
|
DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
|
||||||
|
|
||||||
|
# Additional floating IP pool and range
|
||||||
TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
|
TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
|
||||||
|
|
||||||
# Get a token for clients that don't support service catalog
|
# Get a token for clients that don't support service catalog
|
||||||
@ -51,28 +70,32 @@ nova list
|
|||||||
nova image-list
|
nova image-list
|
||||||
|
|
||||||
# But we recommend using glance directly
|
# But we recommend using glance directly
|
||||||
glance -A $TOKEN index
|
glance -f -A $TOKEN index
|
||||||
|
|
||||||
# Let's grab the id of the first AMI image to launch
|
# Grab the id of the image to launch
|
||||||
IMAGE=`glance -A $TOKEN index | egrep ami | cut -d" " -f1`
|
IMAGE=`glance -f -A $TOKEN index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
|
||||||
|
|
||||||
# Security Groups
|
# Security Groups
|
||||||
# ---------------
|
# ---------------
|
||||||
SECGROUP=test_secgroup
|
|
||||||
|
|
||||||
# List of secgroups:
|
# List of secgroups:
|
||||||
nova secgroup-list
|
nova secgroup-list
|
||||||
|
|
||||||
# Create a secgroup
|
# Create a secgroup
|
||||||
nova secgroup-create $SECGROUP "test_secgroup description"
|
if ! nova secgroup-list | grep -q $SECGROUP; then
|
||||||
|
nova secgroup-create $SECGROUP "$SECGROUP description"
|
||||||
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list | grep -q $SECGROUP; do sleep 1; done"; then
|
||||||
|
echo "Security group not created"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# determine flavor
|
# determinine instance type
|
||||||
# ----------------
|
# -------------------------
|
||||||
|
|
||||||
# List of flavors:
|
# List of instance types:
|
||||||
nova flavor-list
|
nova flavor-list
|
||||||
|
|
||||||
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
|
||||||
INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
|
INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
|
||||||
if [[ -z "$INSTANCE_TYPE" ]]; then
|
if [[ -z "$INSTANCE_TYPE" ]]; then
|
||||||
# grab the first flavor in the list to launch if default doesn't exist
|
# grab the first flavor in the list to launch if default doesn't exist
|
||||||
@ -81,7 +104,7 @@ fi
|
|||||||
|
|
||||||
NAME="myserver"
|
NAME="myserver"
|
||||||
|
|
||||||
nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP
|
VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGROUP | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
# =======
|
# =======
|
||||||
@ -93,23 +116,14 @@ nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_groups=$SECGRO
|
|||||||
# Waiting for boot
|
# Waiting for boot
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|
||||||
# Max time to wait while vm goes from build to active state
|
|
||||||
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-10}
|
|
||||||
|
|
||||||
# Max time till the vm is bootable
|
|
||||||
BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
|
|
||||||
|
|
||||||
# Max time to wait for proper association and dis-association.
|
|
||||||
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
|
|
||||||
|
|
||||||
# check that the status is active within ACTIVE_TIMEOUT seconds
|
# check that the status is active within ACTIVE_TIMEOUT seconds
|
||||||
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $NAME | grep status | grep -q ACTIVE; do sleep 1; done"; then
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
|
||||||
echo "server didn't become active!"
|
echo "server didn't become active!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get the IP of the server
|
# get the IP of the server
|
||||||
IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
|
IP=`nova show $VM_UUID | grep "private network" | cut -d"|" -f3`
|
||||||
|
|
||||||
# for single node deployments, we can ping private ips
|
# for single node deployments, we can ping private ips
|
||||||
MULTI_HOST=${MULTI_HOST:-0}
|
MULTI_HOST=${MULTI_HOST:-0}
|
||||||
@ -129,8 +143,14 @@ fi
|
|||||||
# Security Groups & Floating IPs
|
# Security Groups & Floating IPs
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
|
||||||
# allow icmp traffic (ping)
|
if ! nova secgroup-list-rules $SECGROUP | grep -q icmp; then
|
||||||
nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
|
# allow icmp traffic (ping)
|
||||||
|
nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
|
||||||
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova secgroup-list-rules $SECGROUP | grep -q icmp; do sleep 1; done"; then
|
||||||
|
echo "Security group rule not created"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# List rules for a secgroup
|
# List rules for a secgroup
|
||||||
nova secgroup-list-rules $SECGROUP
|
nova secgroup-list-rules $SECGROUP
|
||||||
@ -145,7 +165,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# add floating ip to our server
|
# add floating ip to our server
|
||||||
nova add-floating-ip $NAME $FLOATING_IP
|
nova add-floating-ip $VM_UUID $FLOATING_IP
|
||||||
|
|
||||||
# test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
|
# test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
|
||||||
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
|
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sleep 1; done"; then
|
||||||
@ -153,7 +173,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Allocate an IP from it
|
# Allocate an IP from second floating pool
|
||||||
TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | cut -d '|' -f2`
|
TEST_FLOATING_IP=`nova floating-ip-create $TEST_FLOATING_POOL | grep $TEST_FLOATING_POOL | cut -d '|' -f2`
|
||||||
|
|
||||||
# list floating addresses
|
# list floating addresses
|
||||||
@ -182,11 +202,10 @@ nova floating-ip-delete $FLOATING_IP
|
|||||||
nova floating-ip-delete $TEST_FLOATING_IP
|
nova floating-ip-delete $TEST_FLOATING_IP
|
||||||
|
|
||||||
# shutdown the server
|
# shutdown the server
|
||||||
nova delete $NAME
|
nova delete $VM_UUID
|
||||||
|
|
||||||
# Delete a secgroup
|
# Delete a secgroup
|
||||||
nova secgroup-delete $SECGROUP
|
nova secgroup-delete $SECGROUP
|
||||||
|
|
||||||
# FIXME: validate shutdown within 5 seconds
|
# FIXME: validate shutdown within 5 seconds
|
||||||
# (nova show $NAME returns 1 or status != ACTIVE)?
|
# (nova show $NAME returns 1 or status != ACTIVE)?
|
||||||
|
|
||||||
|
@ -19,6 +19,21 @@ pushd $(cd $(dirname "$0")/.. && pwd)
|
|||||||
source ./openrc
|
source ./openrc
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
# Max time to wait while vm goes from build to active state
|
||||||
|
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time till the vm is bootable
|
||||||
|
BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
|
||||||
|
|
||||||
|
# Max time to wait for proper association and dis-association.
|
||||||
|
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
|
||||||
|
|
||||||
|
# Instance type to create
|
||||||
|
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
||||||
|
|
||||||
|
# Boot this image, use first AMi image if unset
|
||||||
|
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
|
||||||
|
|
||||||
# Get a token for clients that don't support service catalog
|
# Get a token for clients that don't support service catalog
|
||||||
# ==========================================================
|
# ==========================================================
|
||||||
|
|
||||||
@ -41,10 +56,10 @@ nova list
|
|||||||
nova image-list
|
nova image-list
|
||||||
|
|
||||||
# But we recommend using glance directly
|
# But we recommend using glance directly
|
||||||
glance -A $TOKEN index
|
glance -f -A $TOKEN index
|
||||||
|
|
||||||
# Let's grab the id of the first AMI image to launch
|
# Grab the id of the image to launch
|
||||||
IMAGE=`glance -A $TOKEN index | egrep ami | head -1 | cut -d" " -f1`
|
IMAGE=`glance -f -A $TOKEN index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
|
||||||
|
|
||||||
# determinine instance type
|
# determinine instance type
|
||||||
# -------------------------
|
# -------------------------
|
||||||
@ -52,7 +67,6 @@ IMAGE=`glance -A $TOKEN index | egrep ami | head -1 | cut -d" " -f1`
|
|||||||
# List of instance types:
|
# List of instance types:
|
||||||
nova flavor-list
|
nova flavor-list
|
||||||
|
|
||||||
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
|
|
||||||
INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
|
INSTANCE_TYPE=`nova flavor-list | grep $DEFAULT_INSTANCE_TYPE | cut -d"|" -f2`
|
||||||
if [[ -z "$INSTANCE_TYPE" ]]; then
|
if [[ -z "$INSTANCE_TYPE" ]]; then
|
||||||
# grab the first flavor in the list to launch if default doesn't exist
|
# grab the first flavor in the list to launch if default doesn't exist
|
||||||
@ -73,24 +87,14 @@ VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE $NAME --security_group
|
|||||||
# Waiting for boot
|
# Waiting for boot
|
||||||
# ----------------
|
# ----------------
|
||||||
|
|
||||||
# Max time to wait while vm goes from build to active state
|
|
||||||
ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
|
|
||||||
|
|
||||||
# Max time till the vm is bootable
|
|
||||||
BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
|
|
||||||
|
|
||||||
# Max time to wait for proper association and dis-association.
|
|
||||||
ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
|
|
||||||
|
|
||||||
# check that the status is active within ACTIVE_TIMEOUT seconds
|
# check that the status is active within ACTIVE_TIMEOUT seconds
|
||||||
if ! timeout $BOOT_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
|
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
|
||||||
echo "server didn't become active!"
|
echo "server didn't become active!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get the IP of the server
|
# get the IP of the server
|
||||||
IP=`nova show $VM_UUID | grep "private network" | cut -d"|" -f3`
|
IP=`nova show $VM_UUID | grep "private network" | cut -d"|" -f3`
|
||||||
#VM_UUID=`nova list | grep $NAME | head -1 | cut -d'|' -f2 | sed 's/ //g'`
|
|
||||||
|
|
||||||
# for single node deployments, we can ping private ips
|
# for single node deployments, we can ping private ips
|
||||||
MULTI_HOST=${MULTI_HOST:-0}
|
MULTI_HOST=${MULTI_HOST:-0}
|
||||||
|
6
openrc
6
openrc
@ -53,13 +53,13 @@ export EC2_SECRET_KEY=${ADMIN_PASSWORD:-secrete}
|
|||||||
# export NOVACLIENT_DEBUG=1
|
# export NOVACLIENT_DEBUG=1
|
||||||
|
|
||||||
# Max time till the vm is bootable
|
# Max time till the vm is bootable
|
||||||
export BOOT_TIMEOUT=${BOOT_TIMEOUT:-15}
|
export BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
|
||||||
|
|
||||||
# Max time to wait while vm goes from build to active state
|
# Max time to wait while vm goes from build to active state
|
||||||
export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-10}
|
export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
|
||||||
|
|
||||||
# Max time from run instance command until it is running
|
# Max time from run instance command until it is running
|
||||||
export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
|
export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
|
||||||
|
|
||||||
# Max time to wait for proper IP association and dis-association.
|
# Max time to wait for proper IP association and dis-association.
|
||||||
export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-10}
|
export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
|
||||||
|
Loading…
Reference in New Issue
Block a user