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
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
# comma separated list of script basenames to skip
@ -21,9 +28,9 @@ for script in $basenames; do
if [[ "$SKIP_EXERCISES" =~ $script ]] ; then
skips="$skips $script"
else
echo =========================
echo "====================================================================="
echo Running $script
echo =========================
echo "====================================================================="
$EXERCISE_DIR/$script.sh
if [[ $? -ne 0 ]] ; then
failures="$failures $script"
@ -34,8 +41,7 @@ for script in $basenames; do
done
# output status of exercise run
echo =========================
echo =========================
echo "====================================================================="
for script in $skips; do
echo SKIP $script
done
@ -45,6 +51,7 @@ done
for script in $failures; do
echo FAILED $script
done
echo "====================================================================="
if [ -n "$failures" ] ; then
exit 1

View File

@ -8,9 +8,9 @@
# * Format and install an os onto the volume
# * Detach volume from builder, and then boot volume-backed instance
echo "**************************************************"
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "**************************************************"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# 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_POOL=${DEFAULT_FLOATING_POOL:-nova}
# Launching servers
# =================
# Grab the id of the image to launch
IMAGE=`glance -f index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
die_if_not_set IMAGE "Failure getting image"
# Instance and volume names
@ -88,7 +91,8 @@ nova keypair-add $KEY_NAME > $KEY_FILE
chmod 600 $KEY_FILE
# 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
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
# 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
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?
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
# Wait till volume is attached
@ -192,7 +196,8 @@ nova volume-detach $INSTANCE_NAME $VOLUME_ID
# The format of mapping is:
# <dev_name>=<id>:<type>:<size(GB)>:<delete_on_terminate>
# 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
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
# 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 :/
sleep 1
@ -221,7 +226,8 @@ echo "success!"
EOF
# 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
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
# Delete the volume
nova volume-delete $VOL_NAME
nova volume-delete $VOL_NAME || \
die "Failure deleting volume $VOLUME_NAME"
# Delete instance
nova delete $INSTANCE_NAME
nova delete $INSTANCE_NAME || \
die "Failure deleting instance $INSTANCE_NAME"
# Wait for termination
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
# 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
nova secgroup-delete $SECGROUP
# Delete a secgroup
nova secgroup-delete $SECGROUP || \
die "Failure deleting security group $SECGROUP"
set +o xtrace
echo "**************************************************"
echo "End DevStack Exercise: $0"
echo "**************************************************"
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

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

View File

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

View File

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

View File

@ -1,11 +1,13 @@
#!/usr/bin/env bash
# **euca.sh**
# we will use the ``euca2ools`` cli tool that wraps the python boto
# library to test ec2 compatibility
echo "**************************************************"
echo "*********************************************************************"
echo "Begin DevStack Exercise: $0"
echo "**************************************************"
echo "*********************************************************************"
# This script exits on an error so that errors don't compound and you see
# 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.
set -o xtrace
# Settings
# ========
@ -34,6 +37,10 @@ source $TOP_DIR/exerciserc
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
# Launching a server
# ==================
# Find a machine image to boot
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"
# Associate floating address
euca-associate-address -i $INSTANCE $FLOATING_IP
die_if_error "Failure associating address $FLOATING_IP to $INSTANCE"
euca-associate-address -i $INSTANCE $FLOATING_IP || \
die "Failure associating address $FLOATING_IP to $INSTANCE"
# Authorize pinging
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
die_if_error "Failure authorizing rule in $SECGROUP"
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
die "Failure authorizing rule in $SECGROUP"
# 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
@ -78,12 +85,12 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! ping -c1 -w1 $FLOATING_IP; do sle
fi
# Revoke pinging
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP
die_if_error "Failure revoking rule in $SECGROUP"
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
die "Failure revoking rule in $SECGROUP"
# Release floating address
euca-disassociate-address $FLOATING_IP
die_if_error "Failure disassociating address $FLOATING_IP"
euca-disassociate-address $FLOATING_IP || \
die "Failure disassociating 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
@ -92,8 +99,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INS
fi
# Release floating address
euca-release-address $FLOATING_IP
die_if_error "Failure releasing address $FLOATING_IP"
euca-release-address $FLOATING_IP || \
die "Failure releasing address $FLOATING_IP"
# 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
@ -102,8 +109,8 @@ if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $
fi
# Terminate instance
euca-terminate-instances $INSTANCE
die_if_error "Failure terminating instance $INSTANCE"
euca-terminate-instances $INSTANCE || \
die "Failure terminating instance $INSTANCE"
# 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
@ -112,10 +119,10 @@ if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE |
fi
# Delete group
euca-delete-group $SECGROUP
die_if_error "Failure deleting security group $SECGROUP"
euca-delete-group $SECGROUP || \
die "Failure deleting security group $SECGROUP"
set +o xtrace
echo "**************************************************"
echo "End DevStack Exercise: $0"
echo "**************************************************"
echo "*********************************************************************"
echo "SUCCESS: End DevStack Exercise: $0"
echo "*********************************************************************"

View File

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

View File

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

View File

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

View File

@ -1,5 +1,9 @@
# 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 package [package ...]
@ -22,15 +26,13 @@ function cp_it {
}
# Checks the exit code of the last command and prints "message"
# if it is non-zero and exits
# die_if_error "message"
function die_if_error() {
# Prints "message" and exits
# die "message"
function die() {
local exitcode=$?
if [ $exitcode != 0 ]; then
echo $@
exit $exitcode
fi
set +o xtrace
echo $@
exit $exitcode
}
@ -39,12 +41,16 @@ function die_if_error() {
# NOTE: env-var is the variable name without a '$'
# die_if_not_set env-var "message"
function die_if_not_set() {
local exitcode=$?
local evar=$1; shift
if ! is_set $evar || [ $exitcode != 0 ]; then
echo $@
exit 99
fi
(
local exitcode=$?
set +o xtrace
local evar=$1; shift
if ! is_set $evar || [ $exitcode != 0 ]; then
set +o xtrace
echo $@
exit -1
fi
)
}
@ -143,3 +149,6 @@ function trueorfalse() {
[[ "1 yes true True TRUE" =~ "$testval" ]] && { echo "True"; return; }
echo "$default"
}
# Restore xtrace
$XTRACE

View File

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

View File

@ -11,43 +11,28 @@ source $TOP/functions
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()"
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
echo "die_if_not_set [X='Y' true] Failed"
else
echo 'OK'
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
echo "die_if_not_set [X='' true] Failed"
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
echo "die_if_not_set [X='Y' false] Failed"
else
echo 'OK'
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
echo "die_if_not_set [X='' false] Failed"
fi