From afc29fe5f210a8e78bafaafe7e8b3b5de733971c Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 7 Feb 2013 15:56:24 -0600 Subject: [PATCH] Deprecate DATABASE_TYPE and use_database 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 --- README.md | 7 ++++--- functions | 4 +++- lib/database | 35 +++++++++++++++++++++++++++++++++-- stack.sh | 25 ++++++++++--------------- stackrc | 5 +---- 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 931075887a..483d1b0bc3 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,12 @@ You can override environment variables used in `stack.sh` by creating file name # Database Backend Multiple database backends are available. The available databases are defined in the lib/databases directory. -To choose a database backend, add a line to your `localrc` like: +`mysql` is the default database, choose a different one by putting the following in `localrc`: - use_database postgresql + disable_service mysql + enable_service postgresql -By default, the mysql database backend is used. +`mysql` is the default database. # RPC Backend diff --git a/functions b/functions index 68aec5d2f5..3a037ca3ec 100644 --- a/functions +++ b/functions @@ -975,9 +975,11 @@ function upload_image() { # $1 The name of the database backend to use (mysql, postgresql, ...) function use_database { if [[ -z "$DATABASE_BACKENDS" ]]; then - # The backends haven't initialized yet, just save the selection for now + # No backends registered means this is likely called from ``localrc`` + # This is now deprecated usage DATABASE_TYPE=$1 else + # This should no longer get called...here for posterity use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1 fi } diff --git a/lib/database b/lib/database index 07e37aef72..4fba7c2140 100644 --- a/lib/database +++ b/lib/database @@ -2,9 +2,12 @@ # Interface for interacting with different database backends # Dependencies: -# DATABASE_BACKENDS variable must contain a list of available database backends -# DATABASE_TYPE variable must be set +# ``ENABLED_SERVICES`` must be defined +# ``DATABASE_BACKENDS`` will contain a list of available database backends +# after sourcing this file. + +# This is a wrapper for the specific database backends available. # Each database must implement four functions: # recreate_database_$DATABASE_TYPE # install_database_$DATABASE_TYPE @@ -23,8 +26,36 @@ function register_database { [ -z "$DATABASE_BACKENDS" ] && DATABASE_BACKENDS=$1 || DATABASE_BACKENDS+=" $1" } +# Sourcing the database libs sets DATABASE_BACKENDS with the available list for f in $TOP_DIR/lib/databases/*; do source $f; done +# If ``DATABASE_TYPE`` is defined here it's because the user has it in ``localrc`` +# or has called ``use_database``. Both are deprecated so let's fix it up for now. +if [[ -n $DATABASE_TYPE ]]; then + # This is now deprecated usage, set up a warning and try to be + # somewhat backward compatible for now. + DEPRECATED_TEXT="$DEPRECATED_TEXT\nThe database backend needs to be properly set in ENABLED_SERVICES; DATABASE_TYPE or use_database is deprecated localrc\n" + if [[ ! $ENABLED_SERVICES =~ $DATABASE_TYPE ]]; then + # It's not in enabled services but user has attempted to select a + # database, so just add it now + ENABLED_SERVICES+=,$DATABASE_TYPE + unset DATABASE_TYPE + fi +fi + +# ``DATABASE_BACKENDS`` now contains a list of the supported databases +# Look in ``ENABLED_SERVICES`` to see if one has been selected +for db in $DATABASE_BACKENDS; do + # Set the type for the rest of the backend to use + if is_service_enabled $db; then + # Set this now for the rest of the database funtions + DATABASE_TYPE=$db + fi +done +# If ``DATABASE_TYPE`` is unset here no database was selected +# This is not an error as multi-node installs will do this on the compute nodes + + # Set the database type based on the configuration function initialize_database_backends { for backend in $DATABASE_BACKENDS; do diff --git a/stack.sh b/stack.sh index 0521ced3b7..2cfbfa510c 100755 --- a/stack.sh +++ b/stack.sh @@ -99,11 +99,6 @@ fi source $TOP_DIR/lib/database source $TOP_DIR/lib/rpc_backend -# Validate database selection -# Since DATABASE_BACKENDS is now set, this also gets ENABLED_SERVICES -# properly configured for the database selection. -use_database $DATABASE_TYPE || echo "Invalid database '$DATABASE_TYPE'" - # Remove services which were negated in ENABLED_SERVICES # using the "-" prefix (e.g., "-rabbit") instead of # calling disable_service(). @@ -430,13 +425,13 @@ FLAT_INTERFACE=${FLAT_INTERFACE-$GUEST_INTERFACE_DEFAULT} # Database Configuration # ---------------------- -# To select between database backends, add a line to localrc like: +# To select between database backends, add the following to ``localrc``: # -# use_database postgresql +# disable_service mysql +# enable_service postgresql # -# The available database backends are defined in the ``DATABASE_BACKENDS`` -# variable defined in stackrc. By default, MySQL is enabled as the database -# backend. +# The available database backends are listed in ``DATABASE_BACKENDS`` after +# ``lib/database`` is sourced. ``mysql`` is the default. initialize_database_backends && echo "Using $DATABASE_TYPE database backend" || echo "No database enabled" @@ -520,11 +515,11 @@ function echo_summary() { if [ ! -z "$LAST_SPINNER_PID" ]; then printf "\b\b\bdone\n" >&3 fi - echo -n $@ >&6 + echo -n -e $@ >&6 spinner & LAST_SPINNER_PID=$! else - echo $@ >&6 + echo -e $@ >&6 fi } @@ -1382,9 +1377,9 @@ fi # Echo ``HOST_IP`` - useful for ``build_uec.sh``, which uses dhcp to give the instance an address echo "This is your host ip: $HOST_IP" -# Warn that ``EXTRA_FLAGS`` needs to be converted to ``EXTRA_OPTS`` -if [[ -n "$EXTRA_FLAGS" ]]; then - echo_summary "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS" +# Warn that a deprecated feature was used +if [[ -n "$DEPRECATED_TEXT" ]]; then + echo_summary "WARNING: $DEPRECATED_TEXT" fi # Indicate how long this took to run (bash maintained variable ``SECONDS``) diff --git a/stackrc b/stackrc index 789fc82d76..f53aeec052 100644 --- a/stackrc +++ b/stackrc @@ -9,9 +9,6 @@ DEST=/opt/stack # Destination for working data DATA_DIR=${DEST}/data -# Select the default database -DATABASE_TYPE=mysql - # Determine stack user if [[ $EUID -eq 0 ]]; then STACK_USER=stack @@ -24,7 +21,7 @@ fi # ``disable_service`` functions in ``localrc``. # For example, to enable Swift add this to ``localrc``: # enable_service swift -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 +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 # Set the default Nova APIs to enable NOVA_ENABLED_APIS=ec2,osapi_compute,metadata