Browse code

Merge "Deprecate DATABASE_TYPE and use_database"

Jenkins authored on 2013/02/22 21:26:03
Showing 5 changed files
... ...
@@ -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
 
... ...
@@ -1003,9 +1003,11 @@ function upload_image() {
1003 1003
 #  $1 The name of the database backend to use (mysql, postgresql, ...)
1004 1004
 function use_database {
1005 1005
     if [[ -z "$DATABASE_BACKENDS" ]]; then
1006
-        # The backends haven't initialized yet, just save the selection for now
1006
+        # No backends registered means this is likely called from ``localrc``
1007
+        # This is now deprecated usage
1007 1008
         DATABASE_TYPE=$1
1008 1009
     else
1010
+        # This should no longer get called...here for posterity
1009 1011
         use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1
1010 1012
     fi
1011 1013
 }
... ...
@@ -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
... ...
@@ -83,11 +83,6 @@ fi
83 83
 source $TOP_DIR/lib/database
84 84
 source $TOP_DIR/lib/rpc_backend
85 85
 
86
-# Validate database selection
87
-# Since DATABASE_BACKENDS is now set, this also gets ENABLED_SERVICES
88
-# properly configured for the database selection.
89
-use_database $DATABASE_TYPE || echo "Invalid database '$DATABASE_TYPE'"
90
-
91 86
 # Remove services which were negated in ENABLED_SERVICES
92 87
 # using the "-" prefix (e.g., "-rabbit") instead of
93 88
 # calling disable_service().
... ...
@@ -419,13 +414,13 @@ FLAT_INTERFACE=${FLAT_INTERFACE-$GUEST_INTERFACE_DEFAULT}
419 419
 # Database Configuration
420 420
 # ----------------------
421 421
 
422
-# To select between database backends, add a line to localrc like:
422
+# To select between database backends, add the following to ``localrc``:
423 423
 #
424
-#  use_database postgresql
424
+#    disable_service mysql
425
+#    enable_service postgresql
425 426
 #
426
-# The available database backends are defined in the ``DATABASE_BACKENDS``
427
-# variable defined in stackrc. By default, MySQL is enabled as the database
428
-# backend.
427
+# The available database backends are listed in ``DATABASE_BACKENDS`` after
428
+# ``lib/database`` is sourced. ``mysql`` is the default.
429 429
 
430 430
 initialize_database_backends && echo "Using $DATABASE_TYPE database backend" || echo "No database enabled"
431 431
 
... ...
@@ -509,11 +504,11 @@ function echo_summary() {
509 509
         if [ ! -z "$LAST_SPINNER_PID" ]; then
510 510
             printf "\b\b\bdone\n" >&3
511 511
         fi
512
-        echo -n $@ >&6
512
+        echo -n -e $@ >&6
513 513
         spinner &
514 514
         LAST_SPINNER_PID=$!
515 515
     else
516
-        echo $@ >&6
516
+        echo -e $@ >&6
517 517
     fi
518 518
 }
519 519
 
... ...
@@ -1364,9 +1359,9 @@ fi
1364 1364
 # Echo ``HOST_IP`` - useful for ``build_uec.sh``, which uses dhcp to give the instance an address
1365 1365
 echo "This is your host ip: $HOST_IP"
1366 1366
 
1367
-# Warn that ``EXTRA_FLAGS`` needs to be converted to ``EXTRA_OPTS``
1368
-if [[ -n "$EXTRA_FLAGS" ]]; then
1369
-    echo_summary "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS"
1367
+# Warn that a deprecated feature was used
1368
+if [[ -n "$DEPRECATED_TEXT" ]]; then
1369
+    echo_summary "WARNING: $DEPRECATED_TEXT"
1370 1370
 fi
1371 1371
 
1372 1372
 # 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