Editing ENABLED_SERVICES directly can get tricky when
the user wants to disable something. This patch includes
two new functions for adding or removing services
safely, and a third (for completeness) to clear the
settings entirely before adding a minimal set of
services.
It also moves the logic for dealing with "negated"
services into a function so it can be tested and
applied by the new functions for manipulating
ENABLED_SERVICES.
Change-Id: I88f205f3666b86e6f0b6a94e0ec32a26c4bc6873
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
| ... | ... |
@@ -8,6 +8,7 @@ Chmouel Boudjnah <chmouel@chmouel.com> |
| 8 | 8 |
Dan Prince <dprince@redhat.com> |
| 9 | 9 |
Dean Troyer <dtroyer@gmail.com> |
| 10 | 10 |
Devin Carlen <devin.carlen@gmail.com> |
| 11 |
+Doug hellmann <doug.hellmann@dreamhost.com> |
|
| 11 | 12 |
Eddie Hebert <edhebert@gmail.com> |
| 12 | 13 |
Eoghan Glynn <eglynn@redhat.com> |
| 13 | 14 |
Gabriel Hurley <gabriel@strikeawe.com> |
| ... | ... |
@@ -61,11 +61,12 @@ You can override environment variables used in `stack.sh` by creating file name |
| 61 | 61 |
|
| 62 | 62 |
Swift is not installed by default, you can enable easily by adding this to your `localrc`: |
| 63 | 63 |
|
| 64 |
- ENABLED_SERVICE="$ENABLED_SERVICES,swift" |
|
| 64 |
+ enable_service swift |
|
| 65 | 65 |
|
| 66 | 66 |
If you want a minimal Swift install with only Swift and Keystone you can have this instead in your `localrc`: |
| 67 | 67 |
|
| 68 |
- ENABLED_SERVICES="key,mysql,swift" |
|
| 68 |
+ disable_all_services |
|
| 69 |
+ enable_service key mysql swift |
|
| 69 | 70 |
|
| 70 | 71 |
If you use Swift with Keystone, Swift will authenticate against it. You will need to make sure to use the Keystone URL to auth against. |
| 71 | 72 |
|
| ... | ... |
@@ -1,3 +1,4 @@ |
| 1 |
+# -*- mode: Shell-script -*- |
|
| 1 | 2 |
# functions - Common functions used by DevStack components |
| 2 | 3 |
# |
| 3 | 4 |
# ENABLED_SERVICES is used by is_service_enabled() |
| ... | ... |
@@ -349,6 +350,76 @@ function is_service_enabled() {
|
| 349 | 349 |
return 1 |
| 350 | 350 |
} |
| 351 | 351 |
|
| 352 |
+# remove extra commas from the input string (ENABLED_SERVICES) |
|
| 353 |
+function _cleanup_service_list () {
|
|
| 354 |
+ echo "$1" | sed -e ' |
|
| 355 |
+ s/,,/,/g; |
|
| 356 |
+ s/^,//; |
|
| 357 |
+ s/,$// |
|
| 358 |
+ ' |
|
| 359 |
+} |
|
| 360 |
+ |
|
| 361 |
+# enable_service() adds the services passed as argument to the |
|
| 362 |
+# **ENABLED_SERVICES** list, if they are not already present. |
|
| 363 |
+# |
|
| 364 |
+# For example: |
|
| 365 |
+# |
|
| 366 |
+# enable_service n-vol |
|
| 367 |
+# |
|
| 368 |
+# This function does not know about the special cases |
|
| 369 |
+# for nova, glance, and quantum built into is_service_enabled(). |
|
| 370 |
+function enable_service() {
|
|
| 371 |
+ local tmpsvcs="${ENABLED_SERVICES}"
|
|
| 372 |
+ for service in $@; do |
|
| 373 |
+ if ! is_service_enabled $service; then |
|
| 374 |
+ tmpsvcs+=",$service" |
|
| 375 |
+ fi |
|
| 376 |
+ done |
|
| 377 |
+ ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") |
|
| 378 |
+ disable_negated_services |
|
| 379 |
+} |
|
| 380 |
+ |
|
| 381 |
+# disable_service() removes the services passed as argument to the |
|
| 382 |
+# **ENABLED_SERVICES** list, if they are present. |
|
| 383 |
+# |
|
| 384 |
+# For example: |
|
| 385 |
+# |
|
| 386 |
+# disable_service n-vol |
|
| 387 |
+# |
|
| 388 |
+# This function does not know about the special cases |
|
| 389 |
+# for nova, glance, and quantum built into is_service_enabled(). |
|
| 390 |
+function disable_service() {
|
|
| 391 |
+ local tmpsvcs=",${ENABLED_SERVICES},"
|
|
| 392 |
+ local service |
|
| 393 |
+ for service in $@; do |
|
| 394 |
+ if is_service_enabled $service; then |
|
| 395 |
+ tmpsvcs=${tmpsvcs//,$service,/,}
|
|
| 396 |
+ fi |
|
| 397 |
+ done |
|
| 398 |
+ ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") |
|
| 399 |
+} |
|
| 400 |
+ |
|
| 401 |
+# disable_all_services() removes all current services |
|
| 402 |
+# from **ENABLED_SERVICES** to reset the configuration |
|
| 403 |
+# before a minimal installation |
|
| 404 |
+function disable_all_services() {
|
|
| 405 |
+ ENABLED_SERVICES="" |
|
| 406 |
+} |
|
| 407 |
+ |
|
| 408 |
+# We are looking for services with a - at the beginning to force |
|
| 409 |
+# excluding those services. For example if you want to install all the default |
|
| 410 |
+# services but not nova-volume (n-vol) you can have this set in your localrc : |
|
| 411 |
+# ENABLED_SERVICES+=",-n-vol" |
|
| 412 |
+function disable_negated_services() {
|
|
| 413 |
+ local tmpsvcs="${ENABLED_SERVICES}"
|
|
| 414 |
+ local service |
|
| 415 |
+ for service in ${tmpsvcs//,/ }; do
|
|
| 416 |
+ if [[ ${service} == -* ]]; then
|
|
| 417 |
+ tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
|
|
| 418 |
+ fi |
|
| 419 |
+ done |
|
| 420 |
+ ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") |
|
| 421 |
+} |
|
| 352 | 422 |
|
| 353 | 423 |
# Distro-agnostic package installer |
| 354 | 424 |
# install_package package [package ...] |
| ... | ... |
@@ -89,15 +89,10 @@ DEST=${DEST:-/opt/stack}
|
| 89 | 89 |
# Sanity Check |
| 90 | 90 |
# ============ |
| 91 | 91 |
|
| 92 |
-# We are looking for services with a - at the beginning to force |
|
| 93 |
-# excluding those services. For example if you want to install all the default |
|
| 94 |
-# services but not nova-volume (n-vol) you can have this set in your localrc : |
|
| 95 |
-# ENABLED_SERVICES+=",-n-vol" |
|
| 96 |
-for service in ${ENABLED_SERVICES//,/ }; do
|
|
| 97 |
- if [[ ${service} == -* ]]; then
|
|
| 98 |
- ENABLED_SERVICES=$(echo ${ENABLED_SERVICES}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
|
|
| 99 |
- fi |
|
| 100 |
-done |
|
| 92 |
+# Remove services which were negated in ENABLED_SERVICES |
|
| 93 |
+# using the "-" prefix (e.g., "-n-vol") instead of |
|
| 94 |
+# calling disable_service(). |
|
| 95 |
+disable_negated_services |
|
| 101 | 96 |
|
| 102 | 97 |
# Warn users who aren't on an explicitly supported distro, but allow them to |
| 103 | 98 |
# override check and attempt installation with ``FORCE=yes ./stack`` |
| ... | ... |
@@ -143,3 +143,99 @@ else |
| 143 | 143 |
fi |
| 144 | 144 |
|
| 145 | 145 |
rm test.ini |
| 146 |
+ |
|
| 147 |
+# Enabling/disabling services |
|
| 148 |
+ |
|
| 149 |
+echo "Testing enable_service()" |
|
| 150 |
+ |
|
| 151 |
+function test_enable_service() {
|
|
| 152 |
+ local start="$1" |
|
| 153 |
+ local add="$2" |
|
| 154 |
+ local finish="$3" |
|
| 155 |
+ |
|
| 156 |
+ ENABLED_SERVICES="$start" |
|
| 157 |
+ enable_service $add |
|
| 158 |
+ if [ "$ENABLED_SERVICES" = "$finish" ] |
|
| 159 |
+ then |
|
| 160 |
+ echo "OK: $start + $add -> $ENABLED_SERVICES" |
|
| 161 |
+ else |
|
| 162 |
+ echo "changing $start to $finish with $add failed: $ENABLED_SERVICES" |
|
| 163 |
+ fi |
|
| 164 |
+} |
|
| 165 |
+ |
|
| 166 |
+test_enable_service '' a 'a' |
|
| 167 |
+test_enable_service 'a' b 'a,b' |
|
| 168 |
+test_enable_service 'a,b' c 'a,b,c' |
|
| 169 |
+test_enable_service 'a,b' c 'a,b,c' |
|
| 170 |
+test_enable_service 'a,b,' c 'a,b,c' |
|
| 171 |
+test_enable_service 'a,b' c,d 'a,b,c,d' |
|
| 172 |
+test_enable_service 'a,b' "c d" 'a,b,c,d' |
|
| 173 |
+test_enable_service 'a,b,c' c 'a,b,c' |
|
| 174 |
+ |
|
| 175 |
+test_enable_service 'a,b,-c' c 'a,b' |
|
| 176 |
+test_enable_service 'a,b,c' -c 'a,b' |
|
| 177 |
+ |
|
| 178 |
+function test_disable_service() {
|
|
| 179 |
+ local start="$1" |
|
| 180 |
+ local del="$2" |
|
| 181 |
+ local finish="$3" |
|
| 182 |
+ |
|
| 183 |
+ ENABLED_SERVICES="$start" |
|
| 184 |
+ disable_service "$del" |
|
| 185 |
+ if [ "$ENABLED_SERVICES" = "$finish" ] |
|
| 186 |
+ then |
|
| 187 |
+ echo "OK: $start - $del -> $ENABLED_SERVICES" |
|
| 188 |
+ else |
|
| 189 |
+ echo "changing $start to $finish with $del failed: $ENABLED_SERVICES" |
|
| 190 |
+ fi |
|
| 191 |
+} |
|
| 192 |
+ |
|
| 193 |
+echo "Testing disable_service()" |
|
| 194 |
+test_disable_service 'a,b,c' a 'b,c' |
|
| 195 |
+test_disable_service 'a,b,c' b 'a,c' |
|
| 196 |
+test_disable_service 'a,b,c' c 'a,b' |
|
| 197 |
+ |
|
| 198 |
+test_disable_service 'a,b,c' a 'b,c' |
|
| 199 |
+test_disable_service 'b,c' b 'c' |
|
| 200 |
+test_disable_service 'c' c '' |
|
| 201 |
+test_disable_service '' d '' |
|
| 202 |
+ |
|
| 203 |
+test_disable_service 'a,b,c,' c 'a,b' |
|
| 204 |
+test_disable_service 'a,b' c 'a,b' |
|
| 205 |
+ |
|
| 206 |
+ |
|
| 207 |
+echo "Testing disable_all_services()" |
|
| 208 |
+ENABLED_SERVICES=a,b,c |
|
| 209 |
+disable_all_services |
|
| 210 |
+ |
|
| 211 |
+if [[ -z "$ENABLED_SERVICES" ]] |
|
| 212 |
+then |
|
| 213 |
+ echo "OK" |
|
| 214 |
+else |
|
| 215 |
+ echo "disabling all services FAILED: $ENABLED_SERVICES" |
|
| 216 |
+fi |
|
| 217 |
+ |
|
| 218 |
+echo "Testing disable_negated_services()" |
|
| 219 |
+ |
|
| 220 |
+ |
|
| 221 |
+function test_disable_negated_services() {
|
|
| 222 |
+ local start="$1" |
|
| 223 |
+ local finish="$2" |
|
| 224 |
+ |
|
| 225 |
+ ENABLED_SERVICES="$start" |
|
| 226 |
+ disable_negated_services |
|
| 227 |
+ if [ "$ENABLED_SERVICES" = "$finish" ] |
|
| 228 |
+ then |
|
| 229 |
+ echo "OK: $start + $add -> $ENABLED_SERVICES" |
|
| 230 |
+ else |
|
| 231 |
+ echo "changing $start to $finish failed: $ENABLED_SERVICES" |
|
| 232 |
+ fi |
|
| 233 |
+} |
|
| 234 |
+ |
|
| 235 |
+test_disable_negated_services '-a' '' |
|
| 236 |
+test_disable_negated_services '-a,a' '' |
|
| 237 |
+test_disable_negated_services '-a,-a' '' |
|
| 238 |
+test_disable_negated_services 'a,-a' '' |
|
| 239 |
+test_disable_negated_services 'b,a,-a' 'b' |
|
| 240 |
+test_disable_negated_services 'a,b,-a' 'b' |
|
| 241 |
+test_disable_negated_services 'a,-a,b' 'b' |