Select a database by adding it to ENABLED_SERVICE like the other
services. This greatly simplifies using the lib/* functions in
places other than stack.sh
Backward-compatibility is maintained or now (into havana at least).
Change-Id: I967e44603b4d69d5d70e1a75a9938172ca434025
| ... | ... |
@@ -60,11 +60,12 @@ You can override environment variables used in `stack.sh` by creating file name |
| 60 | 60 |
# Database Backend |
| 61 | 61 |
|
| 62 | 62 |
Multiple database backends are available. The available databases are defined in the lib/databases directory. |
| 63 |
-To choose a database backend, add a line to your `localrc` like: |
|
| 63 |
+`mysql` is the default database, choose a different one by putting the following in `localrc`: |
|
| 64 | 64 |
|
| 65 |
- use_database postgresql |
|
| 65 |
+ disable_service mysql |
|
| 66 |
+ enable_service postgresql |
|
| 66 | 67 |
|
| 67 |
-By default, the mysql database backend is used. |
|
| 68 |
+`mysql` is the default database. |
|
| 68 | 69 |
|
| 69 | 70 |
# RPC Backend |
| 70 | 71 |
|
| ... | ... |
@@ -975,9 +975,11 @@ function upload_image() {
|
| 975 | 975 |
# $1 The name of the database backend to use (mysql, postgresql, ...) |
| 976 | 976 |
function use_database {
|
| 977 | 977 |
if [[ -z "$DATABASE_BACKENDS" ]]; then |
| 978 |
- # The backends haven't initialized yet, just save the selection for now |
|
| 978 |
+ # No backends registered means this is likely called from ``localrc`` |
|
| 979 |
+ # This is now deprecated usage |
|
| 979 | 980 |
DATABASE_TYPE=$1 |
| 980 | 981 |
else |
| 982 |
+ # This should no longer get called...here for posterity |
|
| 981 | 983 |
use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1 |
| 982 | 984 |
fi |
| 983 | 985 |
} |
| ... | ... |
@@ -2,9 +2,12 @@ |
| 2 | 2 |
# Interface for interacting with different database backends |
| 3 | 3 |
|
| 4 | 4 |
# Dependencies: |
| 5 |
-# DATABASE_BACKENDS variable must contain a list of available database backends |
|
| 6 |
-# DATABASE_TYPE variable must be set |
|
| 5 |
+# ``ENABLED_SERVICES`` must be defined |
|
| 7 | 6 |
|
| 7 |
+# ``DATABASE_BACKENDS`` will contain a list of available database backends |
|
| 8 |
+# after sourcing this file. |
|
| 9 |
+ |
|
| 10 |
+# This is a wrapper for the specific database backends available. |
|
| 8 | 11 |
# Each database must implement four functions: |
| 9 | 12 |
# recreate_database_$DATABASE_TYPE |
| 10 | 13 |
# install_database_$DATABASE_TYPE |
| ... | ... |
@@ -23,8 +26,36 @@ function register_database {
|
| 23 | 23 |
[ -z "$DATABASE_BACKENDS" ] && DATABASE_BACKENDS=$1 || DATABASE_BACKENDS+=" $1" |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
+# Sourcing the database libs sets DATABASE_BACKENDS with the available list |
|
| 26 | 27 |
for f in $TOP_DIR/lib/databases/*; do source $f; done |
| 27 | 28 |
|
| 29 |
+# If ``DATABASE_TYPE`` is defined here it's because the user has it in ``localrc`` |
|
| 30 |
+# or has called ``use_database``. Both are deprecated so let's fix it up for now. |
|
| 31 |
+if [[ -n $DATABASE_TYPE ]]; then |
|
| 32 |
+ # This is now deprecated usage, set up a warning and try to be |
|
| 33 |
+ # somewhat backward compatible for now. |
|
| 34 |
+ DEPRECATED_TEXT="$DEPRECATED_TEXT\nThe database backend needs to be properly set in ENABLED_SERVICES; DATABASE_TYPE or use_database is deprecated localrc\n" |
|
| 35 |
+ if [[ ! $ENABLED_SERVICES =~ $DATABASE_TYPE ]]; then |
|
| 36 |
+ # It's not in enabled services but user has attempted to select a |
|
| 37 |
+ # database, so just add it now |
|
| 38 |
+ ENABLED_SERVICES+=,$DATABASE_TYPE |
|
| 39 |
+ unset DATABASE_TYPE |
|
| 40 |
+ fi |
|
| 41 |
+fi |
|
| 42 |
+ |
|
| 43 |
+# ``DATABASE_BACKENDS`` now contains a list of the supported databases |
|
| 44 |
+# Look in ``ENABLED_SERVICES`` to see if one has been selected |
|
| 45 |
+for db in $DATABASE_BACKENDS; do |
|
| 46 |
+ # Set the type for the rest of the backend to use |
|
| 47 |
+ if is_service_enabled $db; then |
|
| 48 |
+ # Set this now for the rest of the database funtions |
|
| 49 |
+ DATABASE_TYPE=$db |
|
| 50 |
+ fi |
|
| 51 |
+done |
|
| 52 |
+# If ``DATABASE_TYPE`` is unset here no database was selected |
|
| 53 |
+# This is not an error as multi-node installs will do this on the compute nodes |
|
| 54 |
+ |
|
| 55 |
+ |
|
| 28 | 56 |
# Set the database type based on the configuration |
| 29 | 57 |
function initialize_database_backends {
|
| 30 | 58 |
for backend in $DATABASE_BACKENDS; do |
| ... | ... |
@@ -99,11 +99,6 @@ fi |
| 99 | 99 |
source $TOP_DIR/lib/database |
| 100 | 100 |
source $TOP_DIR/lib/rpc_backend |
| 101 | 101 |
|
| 102 |
-# Validate database selection |
|
| 103 |
-# Since DATABASE_BACKENDS is now set, this also gets ENABLED_SERVICES |
|
| 104 |
-# properly configured for the database selection. |
|
| 105 |
-use_database $DATABASE_TYPE || echo "Invalid database '$DATABASE_TYPE'" |
|
| 106 |
- |
|
| 107 | 102 |
# Remove services which were negated in ENABLED_SERVICES |
| 108 | 103 |
# using the "-" prefix (e.g., "-rabbit") instead of |
| 109 | 104 |
# calling disable_service(). |
| ... | ... |
@@ -430,13 +425,13 @@ FLAT_INTERFACE=${FLAT_INTERFACE-$GUEST_INTERFACE_DEFAULT}
|
| 430 | 430 |
# Database Configuration |
| 431 | 431 |
# ---------------------- |
| 432 | 432 |
|
| 433 |
-# To select between database backends, add a line to localrc like: |
|
| 433 |
+# To select between database backends, add the following to ``localrc``: |
|
| 434 | 434 |
# |
| 435 |
-# use_database postgresql |
|
| 435 |
+# disable_service mysql |
|
| 436 |
+# enable_service postgresql |
|
| 436 | 437 |
# |
| 437 |
-# The available database backends are defined in the ``DATABASE_BACKENDS`` |
|
| 438 |
-# variable defined in stackrc. By default, MySQL is enabled as the database |
|
| 439 |
-# backend. |
|
| 438 |
+# The available database backends are listed in ``DATABASE_BACKENDS`` after |
|
| 439 |
+# ``lib/database`` is sourced. ``mysql`` is the default. |
|
| 440 | 440 |
|
| 441 | 441 |
initialize_database_backends && echo "Using $DATABASE_TYPE database backend" || echo "No database enabled" |
| 442 | 442 |
|
| ... | ... |
@@ -520,11 +515,11 @@ function echo_summary() {
|
| 520 | 520 |
if [ ! -z "$LAST_SPINNER_PID" ]; then |
| 521 | 521 |
printf "\b\b\bdone\n" >&3 |
| 522 | 522 |
fi |
| 523 |
- echo -n $@ >&6 |
|
| 523 |
+ echo -n -e $@ >&6 |
|
| 524 | 524 |
spinner & |
| 525 | 525 |
LAST_SPINNER_PID=$! |
| 526 | 526 |
else |
| 527 |
- echo $@ >&6 |
|
| 527 |
+ echo -e $@ >&6 |
|
| 528 | 528 |
fi |
| 529 | 529 |
} |
| 530 | 530 |
|
| ... | ... |
@@ -1382,9 +1377,9 @@ fi |
| 1382 | 1382 |
# Echo ``HOST_IP`` - useful for ``build_uec.sh``, which uses dhcp to give the instance an address |
| 1383 | 1383 |
echo "This is your host ip: $HOST_IP" |
| 1384 | 1384 |
|
| 1385 |
-# Warn that ``EXTRA_FLAGS`` needs to be converted to ``EXTRA_OPTS`` |
|
| 1386 |
-if [[ -n "$EXTRA_FLAGS" ]]; then |
|
| 1387 |
- echo_summary "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS" |
|
| 1385 |
+# Warn that a deprecated feature was used |
|
| 1386 |
+if [[ -n "$DEPRECATED_TEXT" ]]; then |
|
| 1387 |
+ echo_summary "WARNING: $DEPRECATED_TEXT" |
|
| 1388 | 1388 |
fi |
| 1389 | 1389 |
|
| 1390 | 1390 |
# Indicate how long this took to run (bash maintained variable ``SECONDS``) |
| ... | ... |
@@ -9,9 +9,6 @@ DEST=/opt/stack |
| 9 | 9 |
# Destination for working data |
| 10 | 10 |
DATA_DIR=${DEST}/data
|
| 11 | 11 |
|
| 12 |
-# Select the default database |
|
| 13 |
-DATABASE_TYPE=mysql |
|
| 14 |
- |
|
| 15 | 12 |
# Determine stack user |
| 16 | 13 |
if [[ $EUID -eq 0 ]]; then |
| 17 | 14 |
STACK_USER=stack |
| ... | ... |
@@ -24,7 +21,7 @@ fi |
| 24 | 24 |
# ``disable_service`` functions in ``localrc``. |
| 25 | 25 |
# For example, to enable Swift add this to ``localrc``: |
| 26 | 26 |
# enable_service swift |
| 27 |
-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,$DATABASE_TYPE |
|
| 27 |
+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 |
|
| 28 | 28 |
|
| 29 | 29 |
# Set the default Nova APIs to enable |
| 30 | 30 |
NOVA_ENABLED_APIS=ec2,osapi_compute,metadata |