Simplify die_if_error

* Replace die_if_error() with the simpler die()
* Attempt to clean up unnecessary trace output
* Formatting cleanups on all exercise scripts

Change-Id: I72a542b3a59ee9bf12bee6bcc605edd7579205e0
This commit is contained in:
Dean Troyer 2012-03-16 16:16:56 -05:00
parent 09407d90a8
commit 27e326995a
12 changed files with 155 additions and 149 deletions

View File

@ -1,6 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source ./stackrc # **exercise.sh**
# Keep track of the current devstack directory.
TOP_DIR=$(cd $(dirname "$0") && pwd)
# Load local configuration
source $TOP_DIR/stackrc
# Run everything in the exercises/ directory that isn't explicitly disabled # Run everything in the exercises/ directory that isn't explicitly disabled
# comma separated list of script basenames to skip # comma separated list of script basenames to skip
@ -21,9 +28,9 @@ for script in $basenames; do
if [[ "$SKIP_EXERCISES" =~ $script ]] ; then if [[ "$SKIP_EXERCISES" =~ $script ]] ; then
skips="$skips $script" skips="$skips $script"
else else
echo ========================= echo "====================================================================="
echo Running $script echo Running $script
echo ========================= echo "====================================================================="
$EXERCISE_DIR/$script.sh $EXERCISE_DIR/$script.sh
if [[ $? -ne 0 ]] ; then if [[ $? -ne 0 ]] ; then
failures="$failures $script" failures="$failures $script"
@ -34,8 +41,7 @@ for script in $basenames; do
done done
# output status of exercise run # output status of exercise run
echo ========================= echo "====================================================================="
echo =========================
for script in $skips; do for script in $skips; do
echo SKIP $script echo SKIP $script
done done
@ -45,6 +51,7 @@ done
for script in $failures; do for script in $failures; do
echo FAILED $script echo FAILED $script
done done
echo "====================================================================="
if [ -n "$failures" ] ; then if [ -n "$failures" ] ; then
exit 1 exit 1

View File

@ -8,9 +8,9 @@
# * Format and install an os onto the volume # * Format and install an os onto the volume
# * Detach volume from builder, and then boot volume-backed instance # * Detach volume from builder, and then boot volume-backed instance
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -46,9 +46,12 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Default floating IP pool name # Default floating IP pool name
DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova} DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
# Launching servers
# =================
# Grab the id of the image to launch # Grab the id of the image to launch
IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1` IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
die_if_not_set IMAGE "Failure getting image" die_if_not_set IMAGE "Failure getting image"
# Instance and volume names # Instance and volume names
@ -88,7 +91,8 @@ nova keypair-add $KEY_NAME > $KEY_FILE
chmod 600 $KEY_FILE chmod 600 $KEY_FILE
# Boot our instance # Boot our instance
VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'` VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --security_groups=$SECGROUP --key_name $KEY_NAME $INSTANCE_NAME | grep ' id ' | get_field 2`
die_if_not_set VM_UUID "Failure launching $INSTANCE_NAME"
# 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 $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
@ -105,7 +109,7 @@ if [ "$FREE_ALL_FLOATING_IPS" = "True" ]; then
fi fi
# Allocate floating ip # Allocate floating ip
FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | cut -d '|' -f2 | tr -d ' '` FLOATING_IP=`nova floating-ip-create | grep $DEFAULT_FLOATING_POOL | get_field 1`
# Make sure the ip gets allocated # Make sure the ip gets allocated
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep -q $FLOATING_IP; do sleep 1; done"; then
@ -133,7 +137,7 @@ fi
# FIXME (anthony) - python-novaclient should accept a volume_name for the attachment param? # FIXME (anthony) - python-novaclient should accept a volume_name for the attachment param?
DEVICE=/dev/vdb DEVICE=/dev/vdb
VOLUME_ID=`nova volume-list | grep $VOL_NAME | cut -d '|' -f 2 | tr -d ' '` VOLUME_ID=`nova volume-list | grep $VOL_NAME | get_field 1`
nova volume-attach $INSTANCE_NAME $VOLUME_ID $DEVICE nova volume-attach $INSTANCE_NAME $VOLUME_ID $DEVICE
# Wait till volume is attached # Wait till volume is attached
@ -192,7 +196,8 @@ nova volume-detach $INSTANCE_NAME $VOLUME_ID
# The format of mapping is: # The format of mapping is:
# <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate> # <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
# Leaving the middle two fields blank appears to do-the-right-thing # Leaving the middle two fields blank appears to do-the-right-thing
VOL_VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block_device_mapping vda=$VOLUME_ID:::0 --security_groups=$SECGROUP --key_name $KEY_NAME $VOL_INSTANCE_NAME | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'` VOL_VM_UUID=`nova boot --flavor $INSTANCE_TYPE --image $IMAGE --block_device_mapping vda=$VOLUME_ID:::0 --security_groups=$SECGROUP --key_name $KEY_NAME $VOL_INSTANCE_NAME | grep ' id ' | get_field 2`
die_if_not_set VOL_VM_UUID "Failure launching $VOL_INSTANCE_NAME"
# 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 $VOL_VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VOL_VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
@ -201,7 +206,7 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VOL_VM_UUID | grep status
fi fi
# Add floating ip to our server # Add floating ip to our server
nova remove-floating-ip $VM_UUID $FLOATING_IP nova remove-floating-ip $VM_UUID $FLOATING_IP
# Gratuitous sleep, probably hiding a race condition :/ # Gratuitous sleep, probably hiding a race condition :/
sleep 1 sleep 1
@ -221,7 +226,8 @@ echo "success!"
EOF EOF
# Delete volume backed instance # Delete volume backed instance
nova delete $VOL_INSTANCE_NAME nova delete $VOL_INSTANCE_NAME || \
die "Failure deleting instance volume $VOL_INSTANCE_NAME"
# Wait till our volume is no longer in-use # Wait till our volume is no longer in-use
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
@ -230,10 +236,12 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME |
fi fi
# Delete the volume # Delete the volume
nova volume-delete $VOL_NAME nova volume-delete $VOL_NAME || \
die "Failure deleting volume $VOLUME_NAME"
# Delete instance # Delete instance
nova delete $INSTANCE_NAME nova delete $INSTANCE_NAME || \
die "Failure deleting instance $INSTANCE_NAME"
# Wait for termination # Wait for termination
if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1; done"; then
@ -242,12 +250,14 @@ if ! timeout $ACTIVE_TIMEOUT sh -c "while nova show $INSTANCE_NAME; do sleep 1;
fi fi
# De-allocate the floating ip # De-allocate the floating ip
nova floating-ip-delete $FLOATING_IP nova floating-ip-delete $FLOATING_IP || \
die "Failure deleting floating IP $FLOATING_IP"
# Delete secgroup # Delete a secgroup
nova secgroup-delete $SECGROUP nova secgroup-delete $SECGROUP || \
die "Failure deleting security group $SECGROUP"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -1,11 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# we will use the ``euca2ools`` cli tool that wraps the python boto # **bundle.sh**
# library to test ec2 compatibility
echo "**************************************************" # we will use the ``euca2ools`` cli tool that wraps the python boto
# library to test ec2 bundle upload compatibility
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -46,12 +48,9 @@ REGISTER_TIMEOUT=${REGISTER_TIMEOUT:-15}
BUCKET=testbucket BUCKET=testbucket
IMAGE=bundle.img IMAGE=bundle.img
truncate -s 5M /tmp/$IMAGE truncate -s 5M /tmp/$IMAGE
euca-bundle-image -i /tmp/$IMAGE euca-bundle-image -i /tmp/$IMAGE || die "Failure bundling image $IMAGE"
die_if_error "Failure bundling image $IMAGE"
euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml || die "Failure uploading bundle $IMAGE to $BUCKET"
euca-upload-bundle -b $BUCKET -m /tmp/$IMAGE.manifest.xml
die_if_error "Failure uploading bundle $IMAGE to $BUCKET"
AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2` AMI=`euca-register $BUCKET/$IMAGE.manifest.xml | cut -f2`
die_if_not_set AMI "Failure registering $BUCKET/$IMAGE" die_if_not_set AMI "Failure registering $BUCKET/$IMAGE"
@ -63,10 +62,9 @@ if ! timeout $REGISTER_TIMEOUT sh -c "while euca-describe-images | grep $AMI | g
fi fi
# Clean up # Clean up
euca-deregister $AMI euca-deregister $AMI || die "Failure deregistering $AMI"
die_if_error "Failure deregistering $AMI"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -2,9 +2,9 @@
# Test OpenStack client authentication aguemnts handling # Test OpenStack client authentication aguemnts handling
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# Settings # Settings
# ======== # ========
@ -135,8 +135,8 @@ report "Nova" $STATUS_NOVA
report "Glance" $STATUS_GLANCE report "Glance" $STATUS_GLANCE
report "Swift" $STATUS_SWIFT report "Swift" $STATUS_SWIFT
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
exit $RETURN exit $RETURN

View File

@ -2,9 +2,9 @@
# Test OpenStack client enviroment variable handling # Test OpenStack client enviroment variable handling
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# Verify client workage # Verify client workage
VERIFY=${1:-""} VERIFY=${1:-""}
@ -149,8 +149,8 @@ report "EC2" $STATUS_EC2
report "Glance" $STATUS_GLANCE report "Glance" $STATUS_GLANCE
report "Swift" $STATUS_SWIFT report "Swift" $STATUS_SWIFT
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
exit $RETURN exit $RETURN

View File

@ -1,11 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# **euca.sh**
# we will use the ``euca2ools`` cli tool that wraps the python boto # we will use the ``euca2ools`` cli tool that wraps the python boto
# library to test ec2 compatibility # library to test ec2 compatibility
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -15,6 +17,7 @@ set -o errexit
# an error. It is also useful for following allowing as the install occurs. # an error. It is also useful for following allowing as the install occurs.
set -o xtrace set -o xtrace
# Settings # Settings
# ======== # ========
@ -34,6 +37,10 @@ source $TOP_DIR/exerciserc
# Instance type to create # Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny} DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Launching a server
# ==================
# 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`
@ -64,12 +71,12 @@ FLOATING_IP=`euca-allocate-address | cut -f2`
die_if_not_set FLOATING_IP "Failure allocating floating IP" die_if_not_set FLOATING_IP "Failure allocating floating IP"
# Associate floating address # Associate floating address
euca-associate-address -i $INSTANCE $FLOATING_IP euca-associate-address -i $INSTANCE $FLOATING_IP || \
die_if_error "Failure associating address $FLOATING_IP to $INSTANCE" die "Failure associating address $FLOATING_IP to $INSTANCE"
# 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 || \
die_if_error "Failure authorizing rule in $SECGROUP" die "Failure authorizing rule in $SECGROUP"
# 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
@ -78,12 +85,12 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
fi fi
# Revoke pinging # Revoke pinging
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
die_if_error "Failure revoking rule in $SECGROUP" die "Failure revoking rule in $SECGROUP"
# Release floating address # Release floating address
euca-disassociate-address $FLOATING_IP euca-disassociate-address $FLOATING_IP || \
die_if_error "Failure disassociating address $FLOATING_IP" die "Failure disassociating address $FLOATING_IP"
# Wait just a tick for everything above to complete so release doesn't fail # 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 if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
@ -92,8 +99,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INS
fi fi
# Release floating address # Release floating address
euca-release-address $FLOATING_IP euca-release-address $FLOATING_IP || \
die_if_error "Failure releasing address $FLOATING_IP" die "Failure releasing address $FLOATING_IP"
# Wait just a tick for everything above to complete so terminate doesn't fail # Wait just a tick for everything above to complete so terminate doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
@ -102,8 +109,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $
fi fi
# Terminate instance # Terminate instance
euca-terminate-instances $INSTANCE euca-terminate-instances $INSTANCE || \
die_if_error "Failure terminating instance $INSTANCE" die "Failure terminating instance $INSTANCE"
# Assure it has terminated within a reasonable time # Assure it has terminated within a reasonable time
if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
@ -112,10 +119,10 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE |
fi fi
# Delete group # Delete group
euca-delete-group $SECGROUP euca-delete-group $SECGROUP || \
die_if_error "Failure deleting security group $SECGROUP" die "Failure deleting security group $SECGROUP"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -1,15 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# **exercise.sh** - using the cloud can be fun # **floating_ips.sh** - using the cloud can be fun
# we will use the ``nova`` cli tool provided by the ``python-novaclient`` # we will use the ``nova`` cli tool provided by the ``python-novaclient``
# package # package to work out the instance connectivity
#
echo "*********************************************************************"
echo "**************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -51,6 +49,7 @@ DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
# Additional floating IP pool and range # Additional floating IP pool and range
TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test} TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
# Launching a server # Launching a server
# ================== # ==================
@ -162,8 +161,8 @@ 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 $VM_UUID $FLOATING_IP nova add-floating-ip $VM_UUID $FLOATING_IP || \
die_if_error "Failure adding floating IP $FLOATING_IP to $NAME" die "Failure adding floating IP $FLOATING_IP to $NAME"
# 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
@ -182,8 +181,7 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! nova floating-ip-list | grep $TES
fi fi
# dis-allow icmp traffic (ping) # dis-allow icmp traffic (ping)
nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 nova secgroup-delete-rule $SECGROUP icmp -1 -1 0.0.0.0/0 || die "Failure deleting security group rule from $SECGROUP"
die_if_error "Failure deleting security group rule from $SECGROUP"
# FIXME (anthony): make xs support security groups # FIXME (anthony): make xs support security groups
if [ "$VIRT_DRIVER" != "xenserver" ]; then if [ "$VIRT_DRIVER" != "xenserver" ]; then
@ -196,16 +194,13 @@ if [ "$VIRT_DRIVER" != "xenserver" ]; then
fi fi
# de-allocate the floating ip # de-allocate the floating ip
nova floating-ip-delete $FLOATING_IP nova floating-ip-delete $FLOATING_IP || die "Failure deleting floating IP $FLOATING_IP"
die_if_error "Failure deleting floating IP $FLOATING_IP"
# Delete second floating IP # Delete second floating IP
nova floating-ip-delete $TEST_FLOATING_IP nova floating-ip-delete $TEST_FLOATING_IP || die "Failure deleting floating IP $TEST_FLOATING_IP"
die_if_error "Failure deleting floating IP $TEST_FLOATING_IP"
# shutdown the server # shutdown the server
nova delete $VM_UUID nova delete $VM_UUID || die "Failure deleting instance $NAME"
die_if_error "Failure deleting instance $NAME"
# make sure the VM shuts down within a reasonable time # make sure the VM shuts down within a reasonable time
if ! timeout $TERMINATE_TIMEOUT sh -c "while nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then if ! timeout $TERMINATE_TIMEOUT sh -c "while nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
@ -214,10 +209,9 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while nova show $VM_UUID | grep status |
fi fi
# Delete a secgroup # Delete a secgroup
nova secgroup-delete $SECGROUP nova secgroup-delete $SECGROUP || die "Failure deleting security group $SECGROUP"
die_if_error "Failure deleting security group $SECGROUP"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -1,10 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# **swift.sh**
# Test swift via the command line tools that ship with it. # Test swift via the command line tools that ship with it.
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -39,27 +41,22 @@ CONTAINER=ex-swift
# ============= # =============
# Check if we have to swift via keystone # Check if we have to swift via keystone
swift stat swift stat || die "Failure geting status"
die_if_error "Failure geting status"
# We start by creating a test container # We start by creating a test container
swift post $CONTAINER swift post $CONTAINER || die "Failure creating container $CONTAINER"
die_if_error "Failure creating container $CONTAINER"
# add some files into it. # add some files into it.
swift upload $CONTAINER /etc/issue swift upload $CONTAINER /etc/issue || die "Failure uploading file to container $CONTAINER"
die_if_error "Failure uploading file to container $CONTAINER"
# list them # list them
swift list $CONTAINER swift list $CONTAINER || die "Failure listing contents of container $CONTAINER"
die_if_error "Failure listing contents of container $CONTAINER"
# And we may want to delete them now that we have tested that # And we may want to delete them now that we have tested that
# everything works. # everything works.
swift delete $CONTAINER swift delete $CONTAINER || die "Failure deleting container $CONTAINER"
die_if_error "Failure deleting container $CONTAINER"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -1,10 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# **volumes.sh**
# Test nova volumes with the nova command from python-novaclient # Test nova volumes with the nova command from python-novaclient
echo "**************************************************" echo "*********************************************************************"
echo "Begin DevStack Exercise: $0" echo "Begin DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see # This script exits on an error so that errors don't compound and you see
# only the first error that occured. # only the first error that occured.
@ -37,6 +39,7 @@ DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Boot this image, use first AMi image if unset # Boot this image, use first AMi image if unset
DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami} DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
# Launching a server # Launching a server
# ================== # ==================
@ -136,8 +139,8 @@ die_if_not_set VOL_ID "Failure retrieving volume ID for $VOL_NAME"
# Attach to server # Attach to server
DEVICE=/dev/vdb DEVICE=/dev/vdb
nova volume-attach $VM_UUID $VOL_ID $DEVICE nova volume-attach $VM_UUID $VOL_ID $DEVICE || \
die_if_error "Failure attaching volume $VOL_NAME to $NAME" die "Failure attaching volume $VOL_NAME to $NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep in-use; do sleep 1; done"; then
echo "Volume $VOL_NAME not attached to $NAME" echo "Volume $VOL_NAME not attached to $NAME"
exit 1 exit 1
@ -151,26 +154,23 @@ if [[ "$VOL_ATTACH" != $VM_UUID ]]; then
fi fi
# Detach volume # Detach volume
nova volume-detach $VM_UUID $VOL_ID nova volume-detach $VM_UUID $VOL_ID || die "Failure detaching volume $VOL_NAME from $NAME"
die_if_error "Failure detaching volume $VOL_NAME from $NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME | grep available; do sleep 1; done"; then
echo "Volume $VOL_NAME not detached from $NAME" echo "Volume $VOL_NAME not detached from $NAME"
exit 1 exit 1
fi fi
# Delete volume # Delete volume
nova volume-delete $VOL_ID nova volume-delete $VOL_ID || die "Failure deleting volume $VOL_NAME"
die_if_error "Failure deleting volume $VOL_NAME"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME; do sleep 1; done"; then if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova volume-list | grep $VOL_NAME; do sleep 1; done"; then
echo "Volume $VOL_NAME not deleted" echo "Volume $VOL_NAME not deleted"
exit 1 exit 1
fi fi
# shutdown the server # shutdown the server
nova delete $NAME nova delete $NAME || die "Failure deleting instance $NAME"
die_if_error "Failure deleting instance $NAME"
set +o xtrace set +o xtrace
echo "**************************************************" echo "*********************************************************************"
echo "End DevStack Exercise: $0" echo "SUCCESS: End DevStack Exercise: $0"
echo "**************************************************" echo "*********************************************************************"

View File

@ -1,5 +1,9 @@
# functions - Common functions used by DevStack components # functions - Common functions used by DevStack components
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
# apt-get wrapper to set arguments correctly # apt-get wrapper to set arguments correctly
# apt_get package [package ...] # apt_get package [package ...]
@ -22,15 +26,13 @@ function cp_it {
} }
# Checks the exit code of the last command and prints "message" # Prints "message" and exits
# if it is non-zero and exits # die "message"
# die_if_error "message" function die() {
function die_if_error() {
local exitcode=$? local exitcode=$?
if [ $exitcode != 0 ]; then set +o xtrace
echo $@ echo $@
exit $exitcode exit $exitcode
fi
} }
@ -39,12 +41,16 @@ function die_if_error() {
# NOTE: env-var is the variable name without a '$' # NOTE: env-var is the variable name without a '$'
# die_if_not_set env-var "message" # die_if_not_set env-var "message"
function die_if_not_set() { function die_if_not_set() {
local exitcode=$? (
local evar=$1; shift local exitcode=$?
if ! is_set $evar || [ $exitcode != 0 ]; then set +o xtrace
echo $@ local evar=$1; shift
exit 99 if ! is_set $evar || [ $exitcode != 0 ]; then
fi set +o xtrace
echo $@
exit -1
fi
)
} }
@ -143,3 +149,6 @@ function trueorfalse() {
[[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; } [[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
echo "$default" echo "$default"
} }
# Restore xtrace
$XTRACE

View File

@ -133,8 +133,7 @@ if [[ $EUID -eq 0 ]]; then
exit 1 exit 1
else else
# We're not root, make sure sudo is available # We're not root, make sure sudo is available
dpkg -l sudo dpkg -l sudo || die "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo."
die_if_error "Sudo is required. Re-run stack.sh as root ONE TIME ONLY to set up sudo."
# UEC images /etc/sudoers does not have a '#includedir'. add one. # UEC images /etc/sudoers does not have a '#includedir'. add one.
sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers || sudo grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||

View File

@ -11,43 +11,28 @@ source $TOP/functions
source $TOP/openrc source $TOP/openrc
echo "Testing die_if_error()"
bash -c "source $TOP/functions; true; die_if_error 'not OK'"
if [[ $? != 0 ]]; then
echo "die_if_error [true] Failed"
fi
bash -c "source $TOP/functions; false; die_if_error 'OK'"
if [[ $? = 0 ]]; then
echo "die_if_error [false] Failed"
else
echo 'OK'
fi
echo "Testing die_if_not_set()" echo "Testing die_if_not_set()"
bash -c "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'" bash -cx "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
echo "die_if_not_set [X='Y' true] Failed" echo "die_if_not_set [X='Y' true] Failed"
else else
echo 'OK' echo 'OK'
fi fi
bash -c "source $TOP/functions; X=`true`; die_if_not_set X 'OK'" bash -cx "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
echo "die_if_not_set [X='' true] Failed" echo "die_if_not_set [X='' true] Failed"
fi fi
bash -c "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'" bash -cx "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
echo "die_if_not_set [X='Y' false] Failed" echo "die_if_not_set [X='Y' false] Failed"
else else
echo 'OK' echo 'OK'
fi fi
bash -c "source $TOP/functions; X=`false`; die_if_not_set X 'OK'" bash -cx "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
echo "die_if_not_set [X='' false] Failed" echo "die_if_not_set [X='' false] Failed"
fi fi