From cdf3d766478d04e62a860754298e7d86f89b33a9 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 15 Oct 2013 09:42:43 -0500 Subject: [PATCH] Add stack phases to extras.d handling Add hooks to stack.sh, unstack.sh and clean.sh to call the extras.d scripts at multiple points in stack.sh. This allows these scripts to perform installation and startup tasks at similar times as they would if integrated into stack.sh. extras.d/70-tempest.sh is present as an example of the structure of these scripts. See extras.d/README.md for more information. Change-Id: Ic1fe522559b94d204d6c0319a2e3d23684c8d028 --- README.md | 4 ++++ clean.sh | 19 +++++++++++++++++++ extras.d/80-tempest.sh | 34 +++++++++++++++++++++------------- extras.d/README | 14 -------------- extras.d/README.md | 31 +++++++++++++++++++++++++++++++ stack.sh | 34 +++++++++++++++++++++++++++++++++- unstack.sh | 11 +++++++++++ 7 files changed, 119 insertions(+), 28 deletions(-) delete mode 100644 extras.d/README create mode 100644 extras.d/README.md diff --git a/README.md b/README.md index 66e36b22a8..514786c60f 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,10 @@ If tempest has been successfully configured, a basic set of smoke tests can be r $ cd /opt/stack/tempest $ nosetests tempest/scenario/test_network_basic_ops.py +# Additional Projects + +DevStack has a hook mechanism to call out to a dispatch script at specific points in the execution if `stack.sh`, `unstack.sh` and `clean.sh`. This allows higher-level projects, especially those that the lower level projects have no dependency on, to be added to DevStack without modifying the scripts. Tempest is built this way as an example of how to structure the dispatch script, see `extras.d/80-tempest.sh`. See `extras.d/README.md` for more information. + # Multi-Node Setup A more interesting setup involves running multiple compute nodes, with Neutron networks connecting VMs on different compute nodes. diff --git a/clean.sh b/clean.sh index 6ceb5a4933..395941ae21 100755 --- a/clean.sh +++ b/clean.sh @@ -47,6 +47,15 @@ source $TOP_DIR/lib/neutron source $TOP_DIR/lib/baremetal source $TOP_DIR/lib/ldap +# Extras Source +# -------------- + +# Phase: source +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i source + done +fi # See if there is anything running... # need to adapt when run_service is merged @@ -56,6 +65,16 @@ if [[ -n "$SESSION" ]]; then $TOP_DIR/unstack.sh --all fi +# Run extras +# ========== + +# Phase: clean +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i clean + done +fi + # Clean projects cleanup_oslo cleanup_cinder diff --git a/extras.d/80-tempest.sh b/extras.d/80-tempest.sh index f159955726..75b702c700 100644 --- a/extras.d/80-tempest.sh +++ b/extras.d/80-tempest.sh @@ -1,21 +1,29 @@ # tempest.sh - DevStack extras script -source $TOP_DIR/lib/tempest - -if [[ "$1" == "stack" ]]; then - # Configure Tempest last to ensure that the runtime configuration of - # the various OpenStack services can be queried. - if is_service_enabled tempest; then - echo_summary "Configuring Tempest" +if is_service_enabled tempest; then + if [[ "$1" == "source" ]]; then + # Initial source + source $TOP_DIR/lib/tempest + elif [[ "$1" == "stack" && "$2" == "install" ]]; then + echo_summary "Installing Tempest" install_tempest + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + # Tempest config must come after layer 2 services are running + : + elif [[ "$1" == "stack" && "$2" == "extra" ]]; then + echo_summary "Initializing Tempest" configure_tempest init_tempest fi + + if [[ "$1" == "unstack" ]]; then + # no-op + : + fi + + if [[ "$1" == "clean" ]]; then + # no-op + : + fi fi -if [[ "$1" == "unstack" ]]; then - # no-op - : -fi - - diff --git a/extras.d/README b/extras.d/README deleted file mode 100644 index ffc6793abd..0000000000 --- a/extras.d/README +++ /dev/null @@ -1,14 +0,0 @@ -The extras.d directory contains project initialization scripts to be -sourced by stack.sh at the end of its run. This is expected to be -used by external projects that want to be configured, started and -stopped with DevStack. - -Order is controlled by prefixing the script names with the a two digit -sequence number. Script names must end with '.sh'. This provides a -convenient way to disable scripts by simoy renaming them. - -DevStack reserves the sequence numbers 00 through 09 and 90 through 99 -for its own use. - -The scripts are called with an argument of 'stack' by stack.sh and -with an argument of 'unstack' by unstack.sh. diff --git a/extras.d/README.md b/extras.d/README.md new file mode 100644 index 0000000000..591e438b02 --- /dev/null +++ b/extras.d/README.md @@ -0,0 +1,31 @@ +# Extras Hooks + +The `extras.d` directory contains project dispatch scripts that are called +at specific times by `stack.sh`, `unstack.sh` and `clean.sh`. These hooks are +used to install, configure and start additional projects during a DevStack run +without any modifications to the base DevStack scripts. + +When `stack.sh` reaches one of the hook points it sources the scripts in `extras.d` +that end with `.sh`. To control the order that the scripts are sourced their +names start with a two digit sequence number. DevStack reserves the sequence +numbers 00 through 09 and 90 through 99 for its own use. + +The scripts are sourced at each hook point so they should not declare anything +at the top level that would cause a problem, specifically, functions. This does +allow the entire `stack.sh` variable space to be available. The scripts are +sourced with one or more arguments, the first of which defines the hook phase: + +arg 1: source | stack | unstack | clean + + source: always called first in any of the scripts, used to set the + initial defaults in a lib/* script or similar + + stack: called by stack.sh. There are three possible values for + the second arg to distinguish the phase stack.sh is in: + + arg 2: install | post-config | extra + + unstack: called by unstack.sh + + clean: called by clean.sh. Remember, clean.sh also calls unstack.sh + so that work need not be repeated. diff --git a/stack.sh b/stack.sh index 14ec023a51..aa0efea487 100755 --- a/stack.sh +++ b/stack.sh @@ -313,6 +313,16 @@ source $TOP_DIR/lib/ldap source $TOP_DIR/lib/ironic source $TOP_DIR/lib/trove +# Extras Source +# -------------- + +# Phase: source +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i source + done +fi + # Set the destination directories for other OpenStack projects OPENSTACKCLIENT_DIR=$DEST/python-openstackclient @@ -725,6 +735,16 @@ if is_service_enabled ir-api ir-cond; then configure_ironic fi +# Extras Install +# -------------- + +# Phase: install +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i stack install + done +fi + if [[ $TRACK_DEPENDS = True ]]; then $DEST/.venv/bin/pip freeze > $DEST/requires-post-pip if ! diff -Nru $DEST/requires-pre-pip $DEST/requires-post-pip > $DEST/requires.diff; then @@ -1000,6 +1020,17 @@ if is_service_enabled nova && is_baremetal; then fi +# Extras Configuration +# ==================== + +# Phase: post-config +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i stack post-config + done +fi + + # Local Configuration # =================== @@ -1214,9 +1245,10 @@ merge_config_group $TOP_DIR/local.conf extra # Run extras # ========== +# Phase: extra if [[ -d $TOP_DIR/extras.d ]]; then for i in $TOP_DIR/extras.d/*.sh; do - [[ -r $i ]] && source $i stack + [[ -r $i ]] && source $i stack extra done fi diff --git a/unstack.sh b/unstack.sh index c944ccc0fb..67c8b7c7b1 100755 --- a/unstack.sh +++ b/unstack.sh @@ -42,6 +42,16 @@ source $TOP_DIR/lib/neutron source $TOP_DIR/lib/ironic source $TOP_DIR/lib/trove +# Extras Source +# -------------- + +# Phase: source +if [[ -d $TOP_DIR/extras.d ]]; then + for i in $TOP_DIR/extras.d/*.sh; do + [[ -r $i ]] && source $i source + done +fi + # Determine what system we are running on. This provides ``os_VENDOR``, # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` GetOSVersion @@ -53,6 +63,7 @@ fi # Run extras # ========== +# Phase: unstack if [[ -d $TOP_DIR/extras.d ]]; then for i in $TOP_DIR/extras.d/*.sh; do [[ -r $i ]] && source $i unstack