Browse code

Revert "Remove deprecated PostgreSQL database driver"

This reverts commit 168ca7f0a474f1207ee01dab0ca2e70f34783e9c.

Removing postgresql support from devstack was unnecessary
since it's not broken and not causing maintenance issues
as far as I know. The commit being reverted said that pg
support was deprecated in Pike but nothing in the docs or
commit message refer to official deprecation of postgres
support in devstack or openstack in general. Not to mention
that there are still postgres-based jobs that will no
longer work *and* the notification to the mailing list about
doing this happened *after* it was already done [1] leaving
stakeholders with no time to reply.

[1] http://lists.openstack.org/pipermail/openstack-discuss/2019-October/010196.html

Change-Id: Ie7036d37d79e6aba462b7c97f917e2e7aed108f9

Matt Riedemann authored on 2019/10/18 04:34:05
Showing 6 changed files
... ...
@@ -326,23 +326,29 @@ a file, keep service logs and disable color in the stored files.
326 326
 Database Backend
327 327
 ----------------
328 328
 
329
-Support for the MySQL database backend is included. Addition database backends
330
-may be available via external plugins. Enabling of disabling MySQL is handled
331
-via the usual service functions and ``ENABLED_SERVICES``. For example, to
332
-disable MySQL in ``local.conf``::
329
+Multiple database backends are available. The available databases are defined
330
+in the lib/databases directory.
331
+``mysql`` is the default database, choose a different one by putting the
332
+following in the ``localrc`` section::
333 333
 
334 334
   disable_service mysql
335
+  enable_service postgresql
336
+
337
+``mysql`` is the default database.
335 338
 
336 339
 RPC Backend
337 340
 -----------
338 341
 
339
-Support for a RabbitMQ RPC backend is included. Additional RPC backends may be
340
-available via external plugins.  Enabling or disabling RabbitMQ is handled via
341
-the usual service functions and ``ENABLED_SERVICES``. For example, to disable
342
-RabbitMQ in ``local.conf``::
342
+Support for a RabbitMQ RPC backend is included. Additional RPC
343
+backends may be available via external plugins.  Enabling or disabling
344
+RabbitMQ is handled via the usual service functions and
345
+``ENABLED_SERVICES``.
346
+
347
+Example disabling RabbitMQ in ``local.conf``::
343 348
 
344 349
   disable_service rabbit
345 350
 
351
+
346 352
 Apache Frontend
347 353
 ---------------
348 354
 
... ...
@@ -302,7 +302,10 @@ migrated at all.
302 302
      - This will probably be implemented on ironic side.
303 303
    * - DEVSTACK_GATE_POSTGRES
304 304
      - Legacy
305
-     - This has no effect in d-g.
305
+     - This flag exists in d-g but the only thing that it does is
306
+       capture postgres logs. This is already supported by the roles
307
+       in post, so the flag is useless in the new jobs. postgres
308
+       itself can be enabled via the devstack_service job variable.
306 309
    * - DEVSTACK_GATE_ZEROMQ
307 310
      - Legacy
308 311
      - This has no effect in d-g.
... ...
@@ -400,8 +400,7 @@ function upload_image {
400 400
 # initialized yet, just save the configuration selection and call back later
401 401
 # to validate it.
402 402
 #
403
-# ``$1`` - the name of the database backend to use (only mysql is currently
404
-# supported)
403
+# ``$1`` - the name of the database backend to use (mysql, postgresql, ...)
405 404
 function use_database {
406 405
     if [[ -z "$DATABASE_BACKENDS" ]]; then
407 406
         # No backends registered means this is likely called from ``localrc``
408 407
new file mode 100644
... ...
@@ -0,0 +1,137 @@
0
+#!/bin/bash
1
+#
2
+# lib/databases/postgresql
3
+# Functions to control the configuration and operation of the **PostgreSQL** database backend
4
+
5
+# Dependencies:
6
+#
7
+# - DATABASE_{HOST,USER,PASSWORD} must be defined
8
+
9
+# Save trace setting
10
+_XTRACE_PG=$(set +o | grep xtrace)
11
+set +o xtrace
12
+
13
+
14
+MAX_DB_CONNECTIONS=${MAX_DB_CONNECTIONS:-200}
15
+
16
+
17
+register_database postgresql
18
+
19
+
20
+# Functions
21
+# ---------
22
+
23
+function get_database_type_postgresql {
24
+    echo postgresql
25
+}
26
+
27
+# Get rid of everything enough to cleanly change database backends
28
+function cleanup_database_postgresql {
29
+    stop_service postgresql
30
+    if is_ubuntu; then
31
+        # Get ruthless with mysql
32
+        apt_get purge -y postgresql*
33
+        return
34
+    elif is_fedora || is_suse; then
35
+        uninstall_package postgresql-server
36
+    else
37
+        return
38
+    fi
39
+}
40
+
41
+function recreate_database_postgresql {
42
+    local db=$1
43
+    # Avoid unsightly error when calling dropdb when the database doesn't exist
44
+    psql -h$DATABASE_HOST -U$DATABASE_USER -dtemplate1 -c "DROP DATABASE IF EXISTS $db"
45
+    createdb -h $DATABASE_HOST -U$DATABASE_USER -l C -T template0 -E utf8 $db
46
+}
47
+
48
+function configure_database_postgresql {
49
+    local pg_conf pg_dir pg_hba check_role version
50
+    echo_summary "Configuring and starting PostgreSQL"
51
+    if is_fedora; then
52
+        pg_hba=/var/lib/pgsql/data/pg_hba.conf
53
+        pg_conf=/var/lib/pgsql/data/postgresql.conf
54
+        if ! sudo [ -e $pg_hba ]; then
55
+            sudo postgresql-setup initdb
56
+        fi
57
+    elif is_ubuntu; then
58
+        version=`psql --version | cut -d ' ' -f3 | cut -d. -f1-2`
59
+        if vercmp $version '>=' 9.3; then
60
+            if [ -z "`pg_lsclusters -h`" ]; then
61
+                echo 'No PostgreSQL clusters exist; will create one'
62
+                sudo pg_createcluster $version main --start
63
+            fi
64
+        fi
65
+        pg_dir=`find /etc/postgresql -name pg_hba.conf|xargs dirname`
66
+        pg_hba=$pg_dir/pg_hba.conf
67
+        pg_conf=$pg_dir/postgresql.conf
68
+    elif is_suse; then
69
+        pg_hba=/var/lib/pgsql/data/pg_hba.conf
70
+        pg_conf=/var/lib/pgsql/data/postgresql.conf
71
+        # initdb is called when postgresql is first started
72
+        sudo [ -e $pg_hba ] || start_service postgresql
73
+    else
74
+        exit_distro_not_supported "postgresql configuration"
75
+    fi
76
+    # Listen on all addresses
77
+    sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $pg_conf
78
+    # Set max_connections
79
+    sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $pg_conf
80
+    # Do password auth from all IPv4 clients
81
+    sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $pg_hba
82
+    # Do password auth for all IPv6 clients
83
+    sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $pg_hba
84
+    restart_service postgresql
85
+
86
+    # Create the role if it's not here or else alter it.
87
+    check_role=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='$DATABASE_USER'")
88
+    if [[ ${check_role} == *HERE ]];then
89
+        sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
90
+    else
91
+        sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
92
+    fi
93
+}
94
+
95
+function install_database_postgresql {
96
+    echo_summary "Installing postgresql"
97
+    deprecated "Use of postgresql in devstack is deprecated, and will be removed during the Pike cycle"
98
+    local pgpass=$HOME/.pgpass
99
+    if [[ ! -e $pgpass ]]; then
100
+        cat <<EOF > $pgpass
101
+*:*:*:$DATABASE_USER:$DATABASE_PASSWORD
102
+EOF
103
+        chmod 0600 $pgpass
104
+    else
105
+        sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $pgpass
106
+    fi
107
+    if is_ubuntu; then
108
+        install_package postgresql
109
+    elif is_fedora || is_suse; then
110
+        install_package postgresql-server
111
+        if is_fedora; then
112
+            sudo systemctl enable postgresql
113
+        fi
114
+    else
115
+        exit_distro_not_supported "postgresql installation"
116
+    fi
117
+}
118
+
119
+function install_database_python_postgresql {
120
+    # Install Python client module
121
+    pip_install_gr psycopg2
122
+    ADDITIONAL_VENV_PACKAGES+=",psycopg2"
123
+}
124
+
125
+function database_connection_url_postgresql {
126
+    local db=$1
127
+    echo "$BASE_SQL_CONN/$db?client_encoding=utf8"
128
+}
129
+
130
+
131
+# Restore xtrace
132
+$_XTRACE_PG
133
+
134
+# Local variables:
135
+# mode: shell-script
136
+# End:
... ...
@@ -695,11 +695,14 @@ function read_password {
695 695
 # Database Configuration
696 696
 # ----------------------
697 697
 
698
-# DevStack provides a MySQL database backend. Additional backends may be
699
-# provided by external plugins and can be enabled using the usual service
700
-# functions and ``ENABLED_SERVICES``. For example, to disable MySQL:
698
+# To select between database backends, add the following to ``local.conf``:
701 699
 #
702 700
 #    disable_service mysql
701
+#    enable_service postgresql
702
+#
703
+# The available database backends are listed in ``DATABASE_BACKENDS`` after
704
+# ``lib/database`` is sourced. ``mysql`` is the default.
705
+
703 706
 if initialize_database_backends; then
704 707
     echo "Using $DATABASE_TYPE database backend"
705 708
     # Last chance for the database password. This must be handled here
... ...
@@ -147,6 +147,10 @@ if [[ -n "$UNSTACK_ALL" ]]; then
147 147
         stop_service mysql
148 148
     fi
149 149
 
150
+    if is_service_enabled postgresql; then
151
+        stop_service postgresql
152
+    fi
153
+
150 154
     # Stop rabbitmq-server
151 155
     if is_service_enabled rabbit; then
152 156
         stop_service rabbitmq-server