Browse code

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

Dean Troyer authored on 2013/10/15 23:42:43
Showing 7 changed files
... ...
@@ -215,6 +215,10 @@ If tempest has been successfully configured, a basic set of smoke tests can be r
215 215
     $ cd /opt/stack/tempest
216 216
     $ nosetests tempest/scenario/test_network_basic_ops.py
217 217
 
218
+# Additional Projects
219
+
220
+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.
221
+
218 222
 # Multi-Node Setup
219 223
 
220 224
 A more interesting setup involves running multiple compute nodes, with Neutron networks connecting VMs on different compute nodes.
... ...
@@ -47,6 +47,15 @@ source $TOP_DIR/lib/neutron
47 47
 source $TOP_DIR/lib/baremetal
48 48
 source $TOP_DIR/lib/ldap
49 49
 
50
+# Extras Source
51
+# --------------
52
+
53
+# Phase: source
54
+if [[ -d $TOP_DIR/extras.d ]]; then
55
+    for i in $TOP_DIR/extras.d/*.sh; do
56
+        [[ -r $i ]] && source $i source
57
+    done
58
+fi
50 59
 
51 60
 # See if there is anything running...
52 61
 # need to adapt when run_service is merged
... ...
@@ -56,6 +65,16 @@ if [[ -n "$SESSION" ]]; then
56 56
     $TOP_DIR/unstack.sh --all
57 57
 fi
58 58
 
59
+# Run extras
60
+# ==========
61
+
62
+# Phase: clean
63
+if [[ -d $TOP_DIR/extras.d ]]; then
64
+    for i in $TOP_DIR/extras.d/*.sh; do
65
+        [[ -r $i ]] && source $i clean
66
+    done
67
+fi
68
+
59 69
 # Clean projects
60 70
 cleanup_oslo
61 71
 cleanup_cinder
... ...
@@ -1,21 +1,29 @@
1 1
 # tempest.sh - DevStack extras script
2 2
 
3
-source $TOP_DIR/lib/tempest
4
-
5
-if [[ "$1" == "stack" ]]; then
6
-    # Configure Tempest last to ensure that the runtime configuration of
7
-    # the various OpenStack services can be queried.
8
-    if is_service_enabled tempest; then
9
-        echo_summary "Configuring Tempest"
3
+if is_service_enabled tempest; then
4
+    if [[ "$1" == "source" ]]; then
5
+        # Initial source
6
+        source $TOP_DIR/lib/tempest
7
+    elif [[ "$1" == "stack" && "$2" == "install" ]]; then
8
+        echo_summary "Installing Tempest"
10 9
         install_tempest
10
+    elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
11
+        # Tempest config must come after layer 2 services are running
12
+        :
13
+    elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
14
+        echo_summary "Initializing Tempest"
11 15
         configure_tempest
12 16
         init_tempest
13 17
     fi
14
-fi
15 18
 
16
-if [[ "$1" == "unstack" ]]; then
17
-    # no-op
18
-    :
19
-fi
19
+    if [[ "$1" == "unstack" ]]; then
20
+        # no-op
21
+        :
22
+    fi
20 23
 
24
+    if [[ "$1" == "clean" ]]; then
25
+        # no-op
26
+        :
27
+    fi
28
+fi
21 29
 
22 30
deleted file mode 100644
... ...
@@ -1,14 +0,0 @@
1
-The extras.d directory contains project initialization scripts to be
2
-sourced by stack.sh at the end of its run.  This is expected to be
3
-used by external projects that want to be configured, started and
4
-stopped with DevStack.
5
-
6
-Order is controlled by prefixing the script names with the a two digit
7
-sequence number.  Script names must end with '.sh'.  This provides a
8
-convenient way to disable scripts by simoy renaming them.
9
-
10
-DevStack reserves the sequence numbers 00 through 09 and 90 through 99
11
-for its own use.
12
-
13
-The scripts are called with an argument of 'stack' by stack.sh and
14
-with an argument of 'unstack' by unstack.sh.
15 1
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+# Extras Hooks
1
+
2
+The `extras.d` directory contains project dispatch scripts that are called
3
+at specific times by `stack.sh`, `unstack.sh` and `clean.sh`.  These hooks are
4
+used to install, configure and start additional projects during a DevStack run
5
+without any modifications to the base DevStack scripts.
6
+
7
+When `stack.sh` reaches one of the hook points it sources the scripts in `extras.d`
8
+that end with `.sh`.  To control the order that the scripts are sourced their
9
+names start with a two digit sequence number.  DevStack reserves the sequence
10
+numbers 00 through 09 and 90 through 99 for its own use.
11
+
12
+The scripts are sourced at each hook point so they should not declare anything
13
+at the top level that would cause a problem, specifically, functions.  This does
14
+allow the entire `stack.sh` variable space to be available.  The scripts are
15
+sourced with one or more arguments, the first of which defines the hook phase:
16
+
17
+arg 1: source | stack | unstack | clean
18
+
19
+    source: always called first in any of the scripts, used to set the
20
+        initial defaults in a lib/* script or similar
21
+
22
+    stack: called by stack.sh.  There are three possible values for
23
+        the second arg to distinguish the phase stack.sh is in:
24
+
25
+        arg 2:  install | post-config | extra
26
+
27
+    unstack: called by unstack.sh
28
+
29
+    clean: called by clean.sh.  Remember, clean.sh also calls unstack.sh
30
+        so that work need not be repeated.
... ...
@@ -313,6 +313,16 @@ source $TOP_DIR/lib/ldap
313 313
 source $TOP_DIR/lib/ironic
314 314
 source $TOP_DIR/lib/trove
315 315
 
316
+# Extras Source
317
+# --------------
318
+
319
+# Phase: source
320
+if [[ -d $TOP_DIR/extras.d ]]; then
321
+    for i in $TOP_DIR/extras.d/*.sh; do
322
+        [[ -r $i ]] && source $i source
323
+    done
324
+fi
325
+
316 326
 # Set the destination directories for other OpenStack projects
317 327
 OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
318 328
 
... ...
@@ -725,6 +735,16 @@ if is_service_enabled ir-api ir-cond; then
725 725
     configure_ironic
726 726
 fi
727 727
 
728
+# Extras Install
729
+# --------------
730
+
731
+# Phase: install
732
+if [[ -d $TOP_DIR/extras.d ]]; then
733
+    for i in $TOP_DIR/extras.d/*.sh; do
734
+        [[ -r $i ]] && source $i stack install
735
+    done
736
+fi
737
+
728 738
 if [[ $TRACK_DEPENDS = True ]]; then
729 739
     $DEST/.venv/bin/pip freeze > $DEST/requires-post-pip
730 740
     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
1000 1000
 fi
1001 1001
 
1002 1002
 
1003
+# Extras Configuration
1004
+# ====================
1005
+
1006
+# Phase: post-config
1007
+if [[ -d $TOP_DIR/extras.d ]]; then
1008
+    for i in $TOP_DIR/extras.d/*.sh; do
1009
+        [[ -r $i ]] && source $i stack post-config
1010
+    done
1011
+fi
1012
+
1013
+
1003 1014
 # Local Configuration
1004 1015
 # ===================
1005 1016
 
... ...
@@ -1214,9 +1245,10 @@ merge_config_group $TOP_DIR/local.conf extra
1214 1214
 # Run extras
1215 1215
 # ==========
1216 1216
 
1217
+# Phase: extra
1217 1218
 if [[ -d $TOP_DIR/extras.d ]]; then
1218 1219
     for i in $TOP_DIR/extras.d/*.sh; do
1219
-        [[ -r $i ]] && source $i stack
1220
+        [[ -r $i ]] && source $i stack extra
1220 1221
     done
1221 1222
 fi
1222 1223
 
... ...
@@ -42,6 +42,16 @@ source $TOP_DIR/lib/neutron
42 42
 source $TOP_DIR/lib/ironic
43 43
 source $TOP_DIR/lib/trove
44 44
 
45
+# Extras Source
46
+# --------------
47
+
48
+# Phase: source
49
+if [[ -d $TOP_DIR/extras.d ]]; then
50
+    for i in $TOP_DIR/extras.d/*.sh; do
51
+        [[ -r $i ]] && source $i source
52
+    done
53
+fi
54
+
45 55
 # Determine what system we are running on.  This provides ``os_VENDOR``,
46 56
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
47 57
 GetOSVersion
... ...
@@ -53,6 +63,7 @@ fi
53 53
 # Run extras
54 54
 # ==========
55 55
 
56
+# Phase: unstack
56 57
 if [[ -d $TOP_DIR/extras.d ]]; then
57 58
     for i in $TOP_DIR/extras.d/*.sh; do
58 59
         [[ -r $i ]] && source $i unstack