Create exerciserc to configure exercises
* Move timeouts from openrc to (new) exerciserc
* Update all exercise scripts
* Update HACKING.rst
Fixes bug 951315
Change-Id: Icc4ff03a7dcf0cc711e204046176fb5186990c17
diff --git a/HACKING.rst b/HACKING.rst
index d91d496..a105a66 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -43,15 +43,14 @@
also rc files (``stackrc`` and ``openrc``) that are often included to set the primary
configuration of the user environment::
- # Use openrc + stackrc + localrc for settings
- pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
+ # Keep track of the current devstack directory.
+ TOP_DIR=$(cd $(dirname "$0") && pwd)
# Import common functions
- source ./functions
+ source $TOP_DIR/functions
# Import configuration
- source ./openrc
- popd >/dev/null
+ source $TOP_DIR/openrc
``stack.sh`` is a rather large monolithic script that flows through from beginning
to end. There is a proposal to segment it to put the OpenStack projects
@@ -119,6 +118,12 @@
# an error. It is also useful for following allowing as the install occurs.
set -o xtrace
+* Settings and configuration are stored in ``exerciserc``, which must be
+ sourced after ``openrc`` or ``stackrc``::
+
+ # Import exercise configuration
+ source $TOP_DIR/exerciserc
+
* There are a couple of helper functions in the common ``functions`` sub-script
that will check for non-zero exit codes and unset environment variables and
print a message and exit the script. These should be called after most client
diff --git a/exerciserc b/exerciserc
new file mode 100644
index 0000000..b41714d
--- /dev/null
+++ b/exerciserc
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+#
+# source exerciserc
+#
+# Configure the DevStack exercise scripts
+# For best results, source this _after_ stackrc/localrc as it will set
+# values only if they are not already set.
+
+# Max time to wait while vm goes from build to active state
+export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
+
+# Max time to wait for proper IP association and dis-association.
+export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
+
+# Max time till the vm is bootable
+export BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
+
+# Max time from run instance command until it is running
+export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
+
+# Max time to wait for a vm to terminate
+export TERMINATE_TIMEOUT=${TERMINATE_TIMEOUT:-30}
diff --git a/exercises/bundle.sh b/exercises/bundle.sh
index 47bacac..0f128af 100755
--- a/exercises/bundle.sh
+++ b/exercises/bundle.sh
@@ -28,6 +28,9 @@
# Import EC2 configuration
source $TOP_DIR/eucarc
+# Import exercise configuration
+source $TOP_DIR/exerciserc
+
# Remove old certificates
rm -f $TOP_DIR/cacert.pem
rm -f $TOP_DIR/cert.pem
diff --git a/exercises/client-env.sh b/exercises/client-env.sh
index d4ba702..0f17275 100755
--- a/exercises/client-env.sh
+++ b/exercises/client-env.sh
@@ -22,6 +22,9 @@
# Import configuration
source $TOP_DIR/openrc
+# Import exercise configuration
+source $TOP_DIR/exerciserc
+
# Unset all of the known NOVA_ vars
unset NOVA_API_KEY
unset NOVA_ENDPOINT_NAME
diff --git a/exercises/euca.sh b/exercises/euca.sh
index 2be2f62..703c7aa 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -28,14 +28,8 @@
# Import EC2 configuration
source $TOP_DIR/eucarc
-# 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}
+# Import exercise configuration
+source $TOP_DIR/exerciserc
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
diff --git a/exercises/floating_ips.sh b/exercises/floating_ips.sh
index a47f1ff..f2b9d03 100755
--- a/exercises/floating_ips.sh
+++ b/exercises/floating_ips.sh
@@ -23,24 +23,18 @@
# Settings
# ========
-# Use openrc + stackrc + localrc for settings
-pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
+# Keep track of the current directory
+EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
+TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
-source ./functions
+source $TOP_DIR/functions
# Import configuration
-source ./openrc
-popd >/dev/null
+source $TOP_DIR/openrc
-# 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}
+# Import exercise configuration
+source $TOP_DIR/exerciserc
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
diff --git a/exercises/swift.sh b/exercises/swift.sh
index 7609637..b70b85f 100755
--- a/exercises/swift.sh
+++ b/exercises/swift.sh
@@ -18,15 +18,18 @@
# Settings
# ========
-# Use openrc + stackrc + localrc for settings
-pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
+# Keep track of the current directory
+EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
+TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
-source ./functions
+source $TOP_DIR/functions
# Import configuration
-source ./openrc
-popd >/dev/null
+source $TOP_DIR/openrc
+
+# Import exercise configuration
+source $TOP_DIR/exerciserc
# Container name
CONTAINER=ex-swift
diff --git a/exercises/volumes.sh b/exercises/volumes.sh
index a812401..77c3498 100755
--- a/exercises/volumes.sh
+++ b/exercises/volumes.sh
@@ -18,24 +18,18 @@
# Settings
# ========
-# Use openrc + stackrc + localrc for settings
-pushd $(cd $(dirname "$0")/.. && pwd) >/dev/null
+# Keep track of the current directory
+EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
+TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
# Import common functions
-source ./functions
+source $TOP_DIR/functions
# Import configuration
-source ./openrc
-popd >/dev/null
+source $TOP_DIR/openrc
-# 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}
+# Import exercise configuration
+source $TOP_DIR/exerciserc
# Instance type to create
DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
diff --git a/openrc b/openrc
index 188ffc5..7aefb0f 100644
--- a/openrc
+++ b/openrc
@@ -65,18 +65,3 @@
# set log level to DEBUG (helps debug issues)
# export KEYSTONECLIENT_DEBUG=1
# export NOVACLIENT_DEBUG=1
-
-# Max time till the vm is bootable
-export BOOT_TIMEOUT=${BOOT_TIMEOUT:-30}
-
-# Max time to wait while vm goes from build to active state
-export ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
-
-# Max time from run instance command until it is running
-export RUNNING_TIMEOUT=${RUNNING_TIMEOUT:-$(($BOOT_TIMEOUT + $ACTIVE_TIMEOUT))}
-
-# Max time to wait for proper IP association and dis-association.
-export ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
-
-# Max time to wait for a vm to terminate
-export TERMINATE_TIMEOUT=${TERMINATE_TIMEOUT:-30}