set errexit and xtrace in helper scripts

stack.sh invokes some helper scripts as separate processes, rather than
by source'ing them.  As with stack.sh itself, abort immediately on the
first error, so that errors don't compound and result in confusing error
messages.  If one of these helper scripts aborts, stack.sh itself will
also abort in the usual manner.

Due to the change in behaviour, tweak some mv invocations to ensure that
they don't trigger false failures.

As with stack.sh itself, also enable xtrace so we can see exactly what's
happening.  In particular this allows us to see the cause of any
premature termination due to a command failing whilst errexit is
enabled.

Change-Id: I7a55784c31e5395e29ab9bbe2bb112b83b9be693
This commit is contained in:
Adam Spiers
2013-10-01 00:35:16 +01:00
parent 1c1aef0eb7
commit c85ade7720
3 changed files with 26 additions and 6 deletions

View File

@@ -6,6 +6,9 @@
# Warning: This script just for development purposes # Warning: This script just for development purposes
set -o errexit
set -o xtrace
ACCOUNT_DIR=./accrc ACCOUNT_DIR=./accrc
display_help() display_help()
@@ -138,10 +141,14 @@ s3=`keystone endpoint-get --service s3 | awk '/\|[[:space:]]*s3.publicURL/ {prin
mkdir -p "$ACCOUNT_DIR" mkdir -p "$ACCOUNT_DIR"
ACCOUNT_DIR=`readlink -f "$ACCOUNT_DIR"` ACCOUNT_DIR=`readlink -f "$ACCOUNT_DIR"`
EUCALYPTUS_CERT=$ACCOUNT_DIR/cacert.pem EUCALYPTUS_CERT=$ACCOUNT_DIR/cacert.pem
mv "$EUCALYPTUS_CERT" "$EUCALYPTUS_CERT.old" &>/dev/null if [ -e "$EUCALYPTUS_CERT" ]; then
mv "$EUCALYPTUS_CERT" "$EUCALYPTUS_CERT.old"
fi
if ! nova x509-get-root-cert "$EUCALYPTUS_CERT"; then if ! nova x509-get-root-cert "$EUCALYPTUS_CERT"; then
echo "Failed to update the root certificate: $EUCALYPTUS_CERT" >&2 echo "Failed to update the root certificate: $EUCALYPTUS_CERT" >&2
mv "$EUCALYPTUS_CERT.old" "$EUCALYPTUS_CERT" &>/dev/null if [ -e "$EUCALYPTUS_CERT.old" ]; then
mv "$EUCALYPTUS_CERT.old" "$EUCALYPTUS_CERT"
fi
fi fi
@@ -168,12 +175,20 @@ function add_entry(){
local ec2_cert="$rcfile-cert.pem" local ec2_cert="$rcfile-cert.pem"
local ec2_private_key="$rcfile-pk.pem" local ec2_private_key="$rcfile-pk.pem"
# Try to preserve the original file on fail (best effort) # Try to preserve the original file on fail (best effort)
mv -f "$ec2_private_key" "$ec2_private_key.old" &>/dev/null if [ -e "$ec2_private_key" ]; then
mv -f "$ec2_cert" "$ec2_cert.old" &>/dev/null mv -f "$ec2_private_key" "$ec2_private_key.old"
fi
if [ -e "$ec2_cert" ]; then
mv -f "$ec2_cert" "$ec2_cert.old"
fi
# It will not create certs when the password is incorrect # It will not create certs when the password is incorrect
if ! nova --os-password "$user_passwd" --os-username "$user_name" --os-tenant-name "$tenant_name" x509-create-cert "$ec2_private_key" "$ec2_cert"; then if ! nova --os-password "$user_passwd" --os-username "$user_name" --os-tenant-name "$tenant_name" x509-create-cert "$ec2_private_key" "$ec2_cert"; then
mv -f "$ec2_private_key.old" "$ec2_private_key" &>/dev/null if [ -e "$ec2_private_key.old" ]; then
mv -f "$ec2_cert.old" "$ec2_cert" &>/dev/null mv -f "$ec2_private_key.old" "$ec2_private_key"
fi
if [ -e "$ec2_cert.old" ]; then
mv -f "$ec2_cert.old" "$ec2_cert"
fi
fi fi
cat >"$rcfile" <<EOF cat >"$rcfile" <<EOF
# you can source this file # you can source this file

View File

@@ -16,6 +16,8 @@
# - pre-install hgtools to work around a bug in RHEL6 distribute # - pre-install hgtools to work around a bug in RHEL6 distribute
# - install nose 1.1 from EPEL # - install nose 1.1 from EPEL
set -o errexit
set -o xtrace
# Keep track of the current directory # Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd) TOOLS_DIR=$(cd $(dirname "$0") && pwd)

View File

@@ -9,6 +9,9 @@
# Assumptions: # Assumptions:
# - update pip to $INSTALL_PIP_VERSION # - update pip to $INSTALL_PIP_VERSION
set -o errexit
set -o xtrace
# Keep track of the current directory # Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd) TOOLS_DIR=$(cd $(dirname "$0") && pwd)
TOP_DIR=`cd $TOOLS_DIR/..; pwd` TOP_DIR=`cd $TOOLS_DIR/..; pwd`