Browse Source

Add the 'external' message bus configuration option

This option is used to run devstack against a pre-provisioned
message bus, rather than having this plugin setup the bus.

Change-Id: I44f15889e6f1f14460bac34702407a8d30721616
Closes-Bug: #1683403
Closes-Bug: #1683397
Kenneth Giusti 2 years ago
parent
commit
59221dd8cc
1 changed files with 180 additions and 103 deletions
  1. 180
    103
      devstack/plugin.sh

+ 180
- 103
devstack/plugin.sh View File

@@ -23,33 +23,77 @@
23 23
 #
24 24
 # Environment Configuration
25 25
 #
26
-# AMQP1_SERVICE - identifies the messaging backend to use.  Should be
27
-#    one of 'qpid' for broker backend, 'qpid-dual' for hybrid router-broker, or
28
-#    'qpid-hybrid' for keeping Rabbit for notifcations.
29
-#    @TODO(kgiusti) add qpid-dispatch, etc
26
+# AMQP1_SERVICE - This plugin can deploy one of several different
27
+#   message bus configurations.  This variable identifies the message
28
+#   bus configuration that will be used. Should be one of:
29
+#     'qpid' - use the qpidd broker for both RPC and Notifications
30
+#     'qpid-dual' - use qpidd for Notifications, qdrouterd for RPC
31
+#     'qpid-hybrid' - use rabbitmq for Notifications, qdrouterd for RPC
32
+#     'external' - use a pre-provisioned message bus.  This prevents
33
+#       this plugin from creating the message bus.  Instead it assumes
34
+#       the bus has already been set up and simply connects to it.
35
+# AMQP1_RPC_TRANSPORT_URL - Transport URL to use for RPC service
36
+# AMQP1_NOTIFY_TRANSPORT_URL - Transport URL to use for Notification
37
+#    service.
38
+#
39
+# If the above AMQP1_*_TRANSPORT_URL env vars are not defined, this
40
+# plugin will construct these urls using the following env vars:
41
+#
30 42
 # AMQP1_HOST - the host used to connect to the messaging service.
31
-#    Defaults to 127.0.0.1
32
-# AMQP1_{DEFAULT_PORT, NOTIFY_PORT} - the port used to connect to the messaging
33
-#    service. Defaults to 5672 and 5671.
34
-# AMQP1_{USERNAME,PASSWORD} - for authentication with AMQP1_HOST
43
+#    Defaults to $SERVICE_HOST
44
+# AMQP1_{DEFAULT_PORT, NOTIFY_PORT} - the port used to connect to the
45
+#    messaging service. AMQP1_NOTIFY_PORT defaults to 5672.
46
+#    AMQP_DEFAULT_PORT also defaults to 5672 for the 'qpid'
47
+#    configuration, otherwise 45672 to avoid port# clashes with the
48
+#    Notification port.
49
+# AMQP1_{USERNAME,PASSWORD} - for authentication with AMQP1_HOST (optional)
50
+#
51
+# The RPC transport url will be defined as:
52
+# "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/"
53
+#
54
+# The notify transport url will be defined as:
55
+# "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/"
35 56
 #
36 57
 
37
-# builds default transport url string
38
-function _get_amqp1_default_transport_url {
39
-    if [ -z "$AMQP1_USERNAME" ]; then
40
-        echo "amqp://$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/"
58
+# parse URL, extracting host, port, username, password
59
+function _parse_transport_url {
60
+    local uphp    # user+password+host+port
61
+    local user    # username
62
+    local passwd  # password
63
+    local hostport  # host+port
64
+    local host    # hostname
65
+    local port    # port #
66
+
67
+    # extract [user:pass@]host:port
68
+    uphp=$(echo $1 | sed -e "s#^[^:]*://\([^/]*\).*#\1#")
69
+    # parse out username + password if present:
70
+    user=""
71
+    passwd=""
72
+    if [[ "$uphp" =~ .+@.+ ]]; then
73
+        local passhostport
74
+        user=$(echo $uphp | sed -e "s#^\([^:]*\).*#\1#")
75
+        passhostport=$(echo $uphp | sed -e "s#$user:##")
76
+        passwd=$(echo $passhostport | sed -e "s#^\([^@]*\).*#\1#")
77
+        hostport=$(echo $passhostport | sed -e "s#$passwd@##")
41 78
     else
42
-        echo "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_DEFAULT_PORT}/"
79
+        hostport=$uphp
43 80
     fi
81
+    host=$(echo $hostport | cut -d: -f1)
82
+    port=$(echo $hostport | cut -d: -f2)
83
+
84
+    # field 1   2     3     4
85
+    echo "$host $port $user $passwd"
44 86
 }
45 87
 
46
-# builds notify transport url string
88
+
89
+# default transport url string
90
+function _get_amqp1_default_transport_url {
91
+    echo "$AMQP1_RPC_TRANSPORT_URL"
92
+}
93
+
94
+# notify transport url string
47 95
 function _get_amqp1_notify_transport_url {
48
-    if [ -z "$AMQP1_USERNAME" ]; then
49
-        echo "amqp://$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/"
50
-    else
51
-        echo "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:${AMQP1_NOTIFY_PORT}/"
52
-    fi
96
+    echo "$AMQP1_NOTIFY_TRANSPORT_URL"
53 97
 }
54 98
 
55 99
 # install packages necessary for support of the oslo.messaging AMQP
@@ -81,6 +125,9 @@ function _remove_pyngus {
81 125
 # Set up the various configuration files used by the qpidd broker
82 126
 function _configure_qpid {
83 127
 
128
+    local url
129
+    url=$(_parse_transport_url $1)
130
+
84 131
     # the location of the configuration files have changed since qpidd 0.14
85 132
     local qpid_conf_file
86 133
     if [ -e /etc/qpid/qpidd.conf ]; then
@@ -95,7 +142,8 @@ function _configure_qpid {
95 142
     sudo chmod o+r $qpid_conf_file
96 143
 
97 144
     # force the ACL file to a known location
98
-    local qpid_acl_file=/etc/qpid/qpidd.acl
145
+    local qpid_acl_file
146
+    qpid_acl_file=/etc/qpid/qpidd.acl
99 147
     if [ ! -e $qpid_acl_file ]; then
100 148
         sudo mkdir -p -m 755 `dirname $qpid_acl_file`
101 149
         sudo touch $qpid_acl_file
@@ -103,12 +151,9 @@ function _configure_qpid {
103 151
     fi
104 152
     echo "acl-file=$qpid_acl_file" | sudo tee $qpid_conf_file
105 153
 
106
-    # map broker port for dual backend config
107
-    if [ "$AMQP1_SERVICE" == "qpid-dual" ]; then
108
-        echo "port=${AMQP1_NOTIFY_PORT}" | sudo tee --append $qpid_conf_file
109
-    fi
110
-
111
-    if [ -z "$AMQP1_USERNAME" ]; then
154
+    local username
155
+    username=$(echo "$url" | cut -d' ' -f3)
156
+    if [ -z "$username" ]; then
112 157
         # no QPID user configured, so disable authentication
113 158
         # and access control
114 159
         echo "auth=no" | sudo tee --append $qpid_conf_file
@@ -117,19 +162,22 @@ acl allow all all
117 162
 EOF
118 163
     else
119 164
         # Configure qpidd to use PLAIN authentication, and add
120
-        # AMQP1_USERNAME to the ACL:
165
+        # $username to the ACL:
121 166
         echo "auth=yes" | sudo tee --append $qpid_conf_file
122
-        if [ -z "$AMQP1_PASSWORD" ]; then
123
-            read_password AMQP1_PASSWORD "ENTER A PASSWORD FOR QPID USER $AMQP1_USERNAME"
167
+        local passwd
168
+        passwd=$(echo "$url" | cut -d' ' -f4)
169
+        if [ -z "$passwd" ]; then
170
+            read_password password "ENTER A PASSWORD FOR QPID USER $username"
124 171
         fi
125
-        # Create ACL to allow $AMQP1_USERNAME full access
172
+        # Create ACL to allow $username full access
126 173
         cat <<EOF | sudo tee $qpid_acl_file
127
-group admin ${AMQP1_USERNAME}@QPID
174
+group admin ${username}@QPID
128 175
 acl allow admin all
129 176
 acl deny all all
130 177
 EOF
131 178
         # Add user to SASL database
132
-        local sasl_conf_file=/etc/sasl2/qpidd.conf
179
+        local sasl_conf_file
180
+        sasl_conf_file=/etc/sasl2/qpidd.conf
133 181
         cat <<EOF | sudo tee $sasl_conf_file
134 182
 pwcheck_method: auxprop
135 183
 auxprop_plugin: sasldb
@@ -143,7 +191,7 @@ EOF
143 191
         if [ ! -e $sasl_db ]; then
144 192
             sudo mkdir -p -m 755 `dirname $sasl_db`
145 193
         fi
146
-        echo $AMQP1_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db -u QPID $AMQP1_USERNAME
194
+        echo $passwd | sudo saslpasswd2 -c -p -f $sasl_db -u QPID $username
147 195
         sudo chmod o+r $sasl_db
148 196
     fi
149 197
 
@@ -154,7 +202,8 @@ EOF
154 202
     if ! $QPIDD --help | grep -q "queue-patterns"; then
155 203
         exit_distro_not_supported "qpidd with AMQP 1.0 support"
156 204
     fi
157
-    local log_file=$LOGDIR/qpidd.log
205
+    local log_file
206
+    log_file=$LOGDIR/qpidd.log
158 207
     cat <<EOF | sudo tee --append $qpid_conf_file
159 208
 queue-patterns=exclusive
160 209
 queue-patterns=unicast
@@ -180,6 +229,9 @@ EOF
180 229
 # Set up the various configuration files used by the qpid-dispatch-router (qdr)
181 230
 function _configure_qdr {
182 231
 
232
+    local url
233
+    url=$(_parse_transport_url $1)
234
+
183 235
     # the location of the configuration is /etc/qpid-dispatch
184 236
     local qdr_conf_file
185 237
     if [ -e /etc/qpid-dispatch/qdrouterd.conf ]; then
@@ -207,13 +259,17 @@ router {
207 259
 EOF
208 260
 
209 261
     # Create a listener for incoming connect to the router
262
+    local port
263
+    port=$(echo "$url" | cut -d' ' -f2)
210 264
     cat <<EOF | sudo tee --append $qdr_conf_file
211 265
 listener {
212 266
     addr: 0.0.0.0
213
-    port: ${AMQP1_DEFAULT_PORT}
267
+    port: ${port}
214 268
     role: normal
215 269
 EOF
216
-    if [ -z "$AMQP1_USERNAME" ]; then
270
+    local username
271
+    username=$(echo "$url" | cut -d' ' -f3)
272
+    if [ -z "$username" ]; then
217 273
         #no user configured, so disable authentication
218 274
         cat <<EOF | sudo tee --append $qdr_conf_file
219 275
     authenticatePeer: no
@@ -222,8 +278,10 @@ EOF
222 278
 EOF
223 279
     else
224 280
         # configure to use PLAIN authentication
225
-        if [ -z "$AMQP1_PASSWORD" ]; then
226
-            read_password AMQP1_PASSWORD "ENTER A PASSWORD FOR QPID DISPATCH USER $AMQP1_USERNAME"
281
+        local passwd
282
+        passwd=$(echo "$url" | cut -d' ' -f4)
283
+        if [ -z "$passwd" ]; then
284
+            read_password passwd "ENTER A PASSWORD FOR QPID DISPATCH USER $username"
227 285
         fi
228 286
         cat <<EOF | sudo tee --append $qdr_conf_file
229 287
     authenticatePeer: yes
@@ -231,7 +289,8 @@ EOF
231 289
 
232 290
 EOF
233 291
         # Add user to SASL database
234
-        local sasl_conf_file=/etc/sasl2/qdrouterd.conf
292
+        local sasl_conf_file
293
+        sasl_conf_file=/etc/sasl2/qdrouterd.conf
235 294
         cat <<EOF | sudo tee $sasl_conf_file
236 295
 pwcheck_method: auxprop
237 296
 auxprop_plugin: sasldb
@@ -244,7 +303,7 @@ EOF
244 303
         if [ ! -e $sasl_db ]; then
245 304
             sudo mkdir -p -m 755 `dirname $sasl_db`
246 305
         fi
247
-        echo $AMQP1_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db $AMQP1_USERNAME
306
+        echo $passwd | sudo saslpasswd2 -c -p -f $sasl_db $username
248 307
         sudo chmod o+r $sasl_db
249 308
     fi
250 309
 
@@ -297,8 +356,8 @@ address {
297 356
 
298 357
 EOF
299 358
 
300
-    local log_file=$LOGDIR/qdrouterd.log
301
-
359
+    local log_file
360
+    log_file=$LOGDIR/qdrouterd.log
302 361
     sudo touch $log_file
303 362
     sudo chmod a+rw $log_file  # qdrouterd user can write to it
304 363
 
@@ -319,39 +378,35 @@ EOF
319 378
 # (qpidd broker and optionally dispatch-router for hybrid)
320 379
 function _install_amqp1_backend {
321 380
 
381
+    local qdrouterd_package
382
+    local qpidd_package
322 383
     if is_fedora; then
323 384
         # expects epel is already added to the yum repos
324 385
         install_package cyrus-sasl-lib
325 386
         install_package cyrus-sasl-plain
326
-        if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
327
-            install_package qpid-cpp-server
328
-        fi
329
-        if [ "$AMQP1_SERVICE" != "qpid" ]; then
330
-            install_package qpid-dispatch-router
331
-        fi
387
+        qdrouterd_package="qpid-dispatch-router"
388
+        qpidd_package="qpid-cpp-server"
332 389
     elif is_ubuntu; then
333 390
         install_package sasl2-bin
334 391
         # newer qpidd and proton only available via the qpid PPA
335 392
         sudo add-apt-repository -y ppa:qpid/released
336
-        #sudo apt-get update
337 393
         REPOS_UPDATED=False
338 394
         update_package_repo
339
-        if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
340
-            install_package qpidd
341
-        fi
342
-        if [ "$AMQP1_SERVICE" != "qpid" ]; then
343
-            install_package qdrouterd
344
-        fi
395
+        qdrouterd_package="qdrouterd"
396
+        qpidd_package="qpidd"
345 397
     else
346 398
         exit_distro_not_supported "amqp1 qpid installation"
347 399
     fi
348 400
 
349 401
     _install_pyngus
350
-    if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
351
-        _configure_qpid
402
+
403
+    if [ "$AMQP1_RPC" == "qdrouterd" ]; then
404
+        install_package $qdrouterd_package
405
+        _configure_qdr $AMQP1_RPC_TRANSPORT_URL
352 406
     fi
353
-    if [ "$AMQP1_SERVICE" != "qpid" ]; then
354
-        _configure_qdr
407
+    if [ "$AMQP1_NOTIFY" == "qpidd" ]; then
408
+        install_package $qpidd_package
409
+        _configure_qpid $AMQP1_NOTIFY_TRANSPORT_URL
355 410
     fi
356 411
 }
357 412
 
@@ -359,36 +414,30 @@ function _install_amqp1_backend {
359 414
 function _start_amqp1_backend {
360 415
     echo_summary "Starting amqp1 backends"
361 416
     # restart, since qpid* may already be running
362
-    if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
363
-        restart_service qpidd
364
-    fi
365
-    if [ "$AMQP1_SERVICE" != "qpid" ]; then
417
+    if [ "$AMQP1_RPC" == "qdrouterd" ]; then
366 418
         restart_service qdrouterd
367 419
     fi
420
+    if [ "$AMQP1_NOTIFY" == "qpidd" ]; then
421
+        restart_service qpidd
422
+    fi
368 423
 }
369 424
 
370 425
 
371 426
 function _cleanup_amqp1_backend {
372 427
     if is_fedora; then
373
-        if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
374
-            uninstall_package qpid-cpp-server
375
-        fi
376
-        if [ "$AMQP1_SERVICE" != "qpid" ]; then
428
+        if [ "$AMQP1_RPC" == "qdrouterd" ]; then
377 429
             uninstall_package qpid-dispatch-router
378 430
         fi
379
-        # TODO(kgiusti) can we pull these, or will that break other
380
-        # packages that depend on them?
381
-
382
-        # install_package cyrus_sasl_lib
383
-        # install_package cyrus_sasl_plain
384
-    elif is_ubuntu; then
385
-        if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
386
-            uninstall_package qpidd
431
+        if [ "$AMQP1_NOTIFY" == "qpidd" ]; then
432
+            uninstall_package qpid-cpp-server
387 433
         fi
388
-        if [ "$AMQP1_SERVICE" != "qpid" ]; then
434
+    elif is_ubuntu; then
435
+        if [ "$AMQP1_RPC" == "qdrouterd" ]; then
389 436
             uninstall_package qdrouterd
390 437
         fi
391
-        # install_package sasl2-bin
438
+        if [ "$AMQP1_NOTIFY" == "qpidd" ]; then
439
+            uninstall_package qpidd
440
+        fi
392 441
     else
393 442
         exit_distro_not_supported "amqp1 qpid installation"
394 443
     fi
@@ -399,28 +448,70 @@ function _cleanup_amqp1_backend {
399 448
 
400 449
 # iniset configuration for amqp rpc_backend
401 450
 function _iniset_amqp1_backend {
402
-    local package=$1
403
-    local file=$2
404
-    local section=${3:-DEFAULT}
451
+    local package
452
+    local file
453
+    local section
405 454
 
406
-    if [ "$AMQP1_SERVICE" == "qpid-dual" ]; then
407
-        iniset $file $section transport_url $(get_transport_url)
408
-        iniset $file oslo_messaging_notifications transport_url $(_get_amqp1_notify_transport_url)
409
-    elif [ "$AMQP1_SERVICE" == "qpid-hybrid" ]; then
410
-        iniset $file $section transport_url $(get_transport_url)
455
+    package=$1
456
+    file=$2
457
+    section=${3:-DEFAULT}
458
+
459
+    iniset $file $section transport_url $(get_transport_url)
460
+    if [ "$AMQP1_NOTIFY" == "rabbit" ]; then
411 461
         iniset $file oslo_messaging_notifications transport_url $(_get_rabbit_transport_url)
412 462
     else
413
-        iniset $file $section transport_url $(get_transport_url)
463
+        iniset $file oslo_messaging_notifications transport_url $(_get_amqp1_notify_transport_url)
414 464
     fi
415 465
 }
416 466
 
417 467
 
418 468
 if is_service_enabled amqp1; then
419
-    # @TODO (ansmith) check is for qdr or qpid for now
420
-    if [[ "$AMQP1_SERVICE" != "qpid" && "$AMQP1_SERVICE" != "qpid-dual" && "$AMQP1_SERVICE" != "qpid-hybrid" ]]; then
421
-        die $LINENO "AMQP 1.0 requires qpid, qpid-dual or qpid-hybrid - $AMQP1_SERVICE not supported"
469
+
470
+    # for backward compatibility - generate the transport urls from the old env vars if not set
471
+    if [[ -z "$AMQP1_RPC_TRANSPORT_URL" ]]; then
472
+        AMQP1_DEFAULT_PORT=${AMQP1_DEFAULT_PORT:=$([[ "$AMQP1_SERVICE" == "qpid" ]] && echo 5672 || echo 45672)}
473
+        if [ -n "$AMQP1_USERNAME" ]; then
474
+            AMQP1_RPC_TRANSPORT_URL="amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:$AMQP1_DEFAULT_PORT"
475
+        else
476
+            AMQP1_RPC_TRANSPORT_URL="amqp://$AMQP1_HOST:$AMQP1_DEFAULT_PORT"
477
+        fi
478
+    fi
479
+
480
+    if [[ -z "$AMQP1_NOTIFY_TRANSPORT_URL" ]]; then
481
+        AMQP1_NOTIFY_PORT=${AMQP1_NOTIFY_PORT:=5672}
482
+        if [ -n "$AMQP1_USERNAME" ]; then
483
+            AMQP1_NOTIFY_TRANSPORT_URL="amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:$AMQP1_NOTIFY_PORT"
484
+        else
485
+            AMQP1_NOTIFY_TRANSPORT_URL="amqp://$AMQP1_HOST:$AMQP1_NOTIFY_PORT"
486
+        fi
422 487
     fi
423 488
 
489
+    case $AMQP1_SERVICE in
490
+        "qpid")
491
+            # Use qpidd for both notifications and RPC messages
492
+            AMQP1_RPC="qpidd"
493
+            AMQP1_NOTIFY="qpidd"
494
+            ;;
495
+        "qpid-dual")
496
+            # Use qpidd for notifications and qdrouterd for RPC messages
497
+            AMQP1_RPC="qdrouterd"
498
+            AMQP1_NOTIFY="qpidd"
499
+            ;;
500
+        "qpid-hybrid")
501
+            # Use rabbitmq for notifications and qdrouterd for RPC messages
502
+            AMQP1_RPC="qdrouterd"
503
+            AMQP1_NOTIFY="rabbit"
504
+            ;;
505
+        "external")
506
+            # Use a pre-provisioned message bus @ AMQP1_NOTIFY/RPC_TRANSPORT_URLs
507
+            AMQP1_RPC="external"
508
+            AMQP1_NOTIFY="external"
509
+            ;;
510
+        *)
511
+            die $LINENO "Set AMQP1_SERVICE to one of: qpid, qpid-dual, qpid-hybrid or external - $AMQP1_SERVICE not supported"
512
+            ;;
513
+    esac
514
+
424 515
     # Save rabbit get_transport_url for notifications if necessary
425 516
     if [ ! $(type -t _get_rabbit_transport_url) ]; then
426 517
         get_transport_url_definition=$(declare -f get_transport_url)
@@ -439,20 +530,6 @@ if is_service_enabled amqp1; then
439 530
     }
440 531
     export -f iniset_rpc_backend
441 532
     export -f get_transport_url
442
-fi
443
-
444
-
445
-# check for amqp1 service
446
-if is_service_enabled amqp1; then
447
-
448
-    if [ "$AMQP1_SERVICE" != "qpid-hybrid" ]; then
449
-        available_port=5672
450
-    else
451
-        available_port=15672
452
-    fi
453
-
454
-    AMQP1_DEFAULT_PORT=${AMQP1_DEFAULT_PORT:=$available_port}
455
-    AMQP1_NOTIFY_PORT=${AMQP1_NOTIFY_PORT:=5671}
456 533
 
457 534
     if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
458 535
         # nothing needed here

Loading…
Cancel
Save