Browse code

Begin is_service_enabled() cleanup

This converts the special cases in the is_service_enabled() function to call
individual functions declared by the projects. This allows projects that
are not in the DevStack repo and called via the extras.d plugin to handle
an equivalent service alias.

* Ceilometer
* Cinder
* Glance
* Neutron
* Nova
* Swift

TODO: remove the tests from is_service_enabled() after a transition period

Patch Set 2: Rebased

Change-Id: Ic78be433f93a9dd5f46be548bdbd4c984e0da6e7

Dean Troyer authored on 2014/01/16 06:04:49
Showing 16 changed files
... ...
@@ -97,7 +97,7 @@ if is_service_enabled ldap; then
97 97
 fi
98 98
 
99 99
 # Do the hypervisor cleanup until this can be moved back into lib/nova
100
-if [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
100
+if is_service_enabled nova && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
101 101
     cleanup_nova_hypervisor
102 102
 fi
103 103
 
... ...
@@ -30,14 +30,12 @@ TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
30 30
 # Import common functions
31 31
 source $TOP_DIR/functions
32 32
 
33
+# Import project functions
34
+source $TOP_DIR/lib/cinder
35
+
33 36
 # Import configuration
34 37
 source $TOP_DIR/openrc
35 38
 
36
-# Import neutron functions if needed
37
-if is_service_enabled neutron; then
38
-    source $TOP_DIR/lib/neutron
39
-fi
40
-
41 39
 # Import exercise configuration
42 40
 source $TOP_DIR/exerciserc
43 41
 
... ...
@@ -33,11 +33,6 @@ source $TOP_DIR/functions
33 33
 # Import EC2 configuration
34 34
 source $TOP_DIR/eucarc
35 35
 
36
-# Import neutron functions if needed
37
-if is_service_enabled neutron; then
38
-    source $TOP_DIR/lib/neutron
39
-fi
40
-
41 36
 # Import exercise configuration
42 37
 source $TOP_DIR/exerciserc
43 38
 
... ...
@@ -27,14 +27,12 @@ TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
27 27
 # Import common functions
28 28
 source $TOP_DIR/functions
29 29
 
30
+# Import project functions
31
+source $TOP_DIR/lib/neutron
32
+
30 33
 # Import configuration
31 34
 source $TOP_DIR/openrc
32 35
 
33
-# Import neutron functions if needed
34
-if is_service_enabled neutron; then
35
-    source $TOP_DIR/lib/neutron
36
-fi
37
-
38 36
 # Import exercise configuration
39 37
 source $TOP_DIR/exerciserc
40 38
 
... ...
@@ -27,14 +27,12 @@ TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
27 27
 # Import common functions
28 28
 source $TOP_DIR/functions
29 29
 
30
+# Import project functions
31
+source $TOP_DIR/lib/cinder
32
+
30 33
 # Import configuration
31 34
 source $TOP_DIR/openrc
32 35
 
33
-# Import neutron functions if needed
34
-if is_service_enabled neutron; then
35
-    source $TOP_DIR/lib/neutron
36
-fi
37
-
38 36
 # Import exercise configuration
39 37
 source $TOP_DIR/exerciserc
40 38
 
... ...
@@ -840,6 +840,16 @@ function is_service_enabled() {
840 840
     services=$@
841 841
     for service in ${services}; do
842 842
         [[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
843
+
844
+        # Look for top-level 'enabled' function for this service
845
+        if type is_${service}_enabled >/dev/null 2>&1; then
846
+            # A function exists for this service, use it
847
+            is_${service}_enabled
848
+            return $?
849
+        fi
850
+
851
+        # TODO(dtroyer): Remove these legacy special-cases after the is_XXX_enabled()
852
+        #                are implemented
843 853
         [[ ${service} == n-cell-* && ${ENABLED_SERVICES} =~ "n-cell" ]] && return 0
844 854
         [[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
845 855
         [[ ${service} == "cinder" && ${ENABLED_SERVICES} =~ "c-" ]] && return 0
... ...
@@ -59,7 +59,14 @@ TEMPEST_SERVICES+=,ceilometer
59 59
 
60 60
 # Functions
61 61
 # ---------
62
-#
62
+
63
+# Test if any Ceilometer services are enabled
64
+# is_ceilometer_enabled
65
+function is_ceilometer_enabled {
66
+    [[ ,${ENABLED_SERVICES} =~ ,"ceilometer-" ]] && return 0
67
+    return 1
68
+}
69
+
63 70
 # create_ceilometer_accounts() - Set up common required ceilometer accounts
64 71
 
65 72
 create_ceilometer_accounts() {
... ...
@@ -85,6 +85,14 @@ TEMPEST_SERVICES+=,cinder
85 85
 
86 86
 # Functions
87 87
 # ---------
88
+
89
+# Test if any Cinder services are enabled
90
+# is_cinder_enabled
91
+function is_cinder_enabled {
92
+    [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
93
+    return 1
94
+}
95
+
88 96
 # _clean_lvm_lv removes all cinder LVM volumes
89 97
 #
90 98
 # Usage: _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX
... ...
@@ -59,6 +59,13 @@ TEMPEST_SERVICES+=,glance
59 59
 # Functions
60 60
 # ---------
61 61
 
62
+# Test if any Glance services are enabled
63
+# is_glance_enabled
64
+function is_glance_enabled {
65
+    [[ ,${ENABLED_SERVICES} =~ ,"g-" ]] && return 0
66
+    return 1
67
+}
68
+
62 69
 # cleanup_glance() - Remove residual data files, anything left over from previous
63 70
 # runs that a clean run would need to clean up
64 71
 function cleanup_glance() {
... ...
@@ -244,6 +244,13 @@ TEMPEST_SERVICES+=,neutron
244 244
 # Functions
245 245
 # ---------
246 246
 
247
+# Test if any Neutron services are enabled
248
+# is_neutron_enabled
249
+function is_neutron_enabled {
250
+    [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
251
+    return 1
252
+}
253
+
247 254
 # configure_neutron()
248 255
 # Set common config for all neutron server and agents.
249 256
 function configure_neutron() {
... ...
@@ -129,6 +129,20 @@ TEMPEST_SERVICES+=,nova
129 129
 # Functions
130 130
 # ---------
131 131
 
132
+# Test if any Nova services are enabled
133
+# is_nova_enabled
134
+function is_nova_enabled {
135
+    [[ ,${ENABLED_SERVICES} =~ ,"n-" ]] && return 0
136
+    return 1
137
+}
138
+
139
+# Test if any Nova Cell services are enabled
140
+# is_nova_enabled
141
+function is_n-cell_enabled {
142
+    [[ ,${ENABLED_SERVICES} =~ ,"n-cell-" ]] && return 0
143
+    return 1
144
+}
145
+
132 146
 # Helper to clean iptables rules
133 147
 function clean_iptables() {
134 148
     # Delete rules
... ...
@@ -118,6 +118,13 @@ TEMPEST_SERVICES+=,swift
118 118
 # Functions
119 119
 # ---------
120 120
 
121
+# Test if any Swift services are enabled
122
+# is_swift_enabled
123
+function is_swift_enabled {
124
+    [[ ,${ENABLED_SERVICES} =~ ,"s-" ]] && return 0
125
+    return 1
126
+}
127
+
121 128
 # cleanup_swift() - Remove residual data files
122 129
 function cleanup_swift() {
123 130
     rm -f ${SWIFT_CONF_DIR}{*.builder,*.ring.gz,backups/*.builder,backups/*.ring.gz}
... ...
@@ -10,6 +10,7 @@
10 10
 
11 11
 # ``stack.sh`` calls the entry points in this order:
12 12
 #
13
+# - is_XXXX_enabled
13 14
 # - install_XXXX
14 15
 # - configure_XXXX
15 16
 # - init_XXXX
... ...
@@ -35,6 +36,13 @@ XXX_CONF_DIR=/etc/XXXX
35 35
 # Entry Points
36 36
 # ------------
37 37
 
38
+# Test if any XXXX services are enabled
39
+# is_XXXX_enabled
40
+function is_XXXX_enabled {
41
+    [[ ,${ENABLED_SERVICES} =~ ,"XX-" ]] && return 0
42
+    return 1
43
+}
44
+
38 45
 # cleanup_XXXX() - Remove residual data files, anything left over from previous
39 46
 # runs that a clean run would need to clean up
40 47
 function cleanup_XXXX() {
... ...
@@ -1096,7 +1096,7 @@ if is_service_enabled s-proxy; then
1096 1096
 fi
1097 1097
 
1098 1098
 # Launch the Glance services
1099
-if is_service_enabled g-api g-reg; then
1099
+if is_service_enabled glance; then
1100 1100
     echo_summary "Starting Glance"
1101 1101
     start_glance
1102 1102
 fi
... ...
@@ -35,7 +35,7 @@ fi
35 35
 #  enable_service neutron
36 36
 #  # Optional, to enable tempest configuration as part of devstack
37 37
 #  enable_service tempest
38
-ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,n-cond,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,tempest,mysql
38
+ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,n-cond,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,tempest,mysql
39 39
 
40 40
 # Tell Tempest which services are available.  The default is set here as
41 41
 # Tempest falls late in the configuration sequence.  This differs from
... ...
@@ -104,7 +104,7 @@ if is_service_enabled nova; then
104 104
     stop_nova
105 105
 fi
106 106
 
107
-if is_service_enabled g-api g-reg; then
107
+if is_service_enabled glance; then
108 108
     stop_glance
109 109
 fi
110 110