Browse Source

Override rpc_backend_add_vhost for AMQP 1.0 support

Change-Id: Ibb2003bba1371ccd8144f7a03d82fcf78f8b7065
Closes-bug: #1707298
Partial-bug: #1706987
Kenneth Giusti 1 year ago
parent
commit
fac766525d
1 changed files with 62 additions and 19 deletions
  1. 62
    19
      devstack/plugin.sh

+ 62
- 19
devstack/plugin.sh View File

@@ -32,9 +32,10 @@
32 32
 #     'external' - use a pre-provisioned message bus.  This prevents
33 33
 #       this plugin from creating the message bus.  Instead it assumes
34 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
35
+# AMQP1_RPC_TRANSPORT_URL - Transport URL to use for RPC service.
36
+#    A virtual host may be added at run time.
36 37
 # AMQP1_NOTIFY_TRANSPORT_URL - Transport URL to use for Notification
37
-#    service.
38
+#    service. A virtual host may be added at run time.
38 39
 #
39 40
 # If the above AMQP1_*_TRANSPORT_URL env vars are not defined, this
40 41
 # plugin will construct these urls using the following env vars:
@@ -88,12 +89,33 @@ function _parse_transport_url {
88 89
 
89 90
 # default transport url string
90 91
 function _get_amqp1_default_transport_url {
91
-    echo "$AMQP1_RPC_TRANSPORT_URL"
92
+    local virtual_host
93
+    virtual_host=$1
94
+    echo "$AMQP1_RPC_TRANSPORT_URL/$virtual_host"
92 95
 }
93 96
 
94 97
 # notify transport url string
95 98
 function _get_amqp1_notify_transport_url {
96
-    echo "$AMQP1_NOTIFY_TRANSPORT_URL"
99
+    local virtual_host
100
+    virtual_host=$1
101
+
102
+    if [ "$AMQP1_NOTIFY" == "rabbit" ]; then
103
+        echo $(_get_rabbit_notification_url $virtual_host)
104
+    else
105
+        echo "$AMQP1_NOTIFY_TRANSPORT_URL/$virtual_host"
106
+    fi
107
+}
108
+
109
+# override the default in devstack as it forces all non-rabbit
110
+# backends to fail...
111
+function _amqp1_add_vhost {
112
+
113
+    if [ "$AMQP1_NOTIFY" == "rabbit" ]; then
114
+        _rabbit_rpc_backend_add_vhost $@
115
+    fi
116
+
117
+    # no configuration necessary for AMQP 1.0 backend
118
+    return 0
97 119
 }
98 120
 
99 121
 # install packages necessary for support of the oslo.messaging AMQP
@@ -451,17 +473,15 @@ function _iniset_amqp1_backend {
451 473
     local package
452 474
     local file
453 475
     local section
476
+    local virtual_host
454 477
 
455 478
     package=$1
456 479
     file=$2
457 480
     section=${3:-DEFAULT}
481
+    virtual_host=$4
458 482
 
459
-    iniset $file $section transport_url $(get_transport_url)
460
-    if [ "$AMQP1_NOTIFY" == "rabbit" ]; then
461
-        iniset $file oslo_messaging_notifications transport_url $(_get_rabbit_transport_url)
462
-    else
463
-        iniset $file oslo_messaging_notifications transport_url $(_get_amqp1_notify_transport_url)
464
-    fi
483
+    iniset $file $section transport_url $(get_transport_url "$virtual_host")
484
+    iniset $file oslo_messaging_notifications transport_url $(get_notification_url "$virtual_host")
465 485
 }
466 486
 
467 487
 
@@ -512,25 +532,48 @@ if is_service_enabled amqp1; then
512 532
             ;;
513 533
     esac
514 534
 
515
-    # Save rabbit get_transport_url for notifications if necessary
516
-    if [ ! $(type -t _get_rabbit_transport_url) ]; then
517
-        get_transport_url_definition=$(declare -f get_transport_url)
518
-        eval "_get_rabbit_transport_url() ${get_transport_url_definition#*\()}"
519
-        export -f _get_rabbit_transport_url
535
+    #
536
+    # Override all rpc_backend functions that are rabbit-specific:
537
+    #
538
+
539
+    # this plugin can be configured to use rabbit for notifications
540
+    # (qpid-hybrid), so save a copy of the original
541
+    if [ ! $(type -t _get_rabbit_notification_url) ]; then
542
+        get_notification_url_definition=$(declare -f get_notification_url)
543
+        eval "_get_rabbit_notification_url() ${get_notification_url_definition#*\()}"
544
+        export -f _get_rabbit_notification_url
545
+    fi
546
+
547
+    # rpc_backend's version of rpc_backend_add_vhost assumes vhosting
548
+    # is a rabbit-only feature!  Will need original if using rabbit
549
+    # for notifications
550
+    if [ ! $(type -t _rabbit_rpc_backend_add_vhost) ]; then
551
+        rpc_backend_add_vhost_definition=$(declare -f rpc_backend_add_vhost)
552
+        eval "_rabbit_rpc_backend_add_vhost() ${rpc_backend_add_vhost_definition#*\()}"
553
+        export -f _rabbit_rpc_backend_add_vhost
520 554
     fi
521 555
 
522
-    # Note: this is the only tricky part about out of tree rpc plugins,
523
-    # you must overwrite the iniset_rpc_backend function so that when
524
-    # that's passed around the correct settings files are made.
556
+    # export the overridden functions
525 557
     function iniset_rpc_backend {
526 558
         _iniset_amqp1_backend $@
527 559
     }
560
+    export -f iniset_rpc_backend
561
+
528 562
     function get_transport_url {
529 563
         _get_amqp1_default_transport_url $@
530 564
     }
531
-    export -f iniset_rpc_backend
532 565
     export -f get_transport_url
533 566
 
567
+    function get_notification_url {
568
+        _get_amqp1_notify_transport_url $@
569
+    }
570
+    export -f get_notification_url
571
+
572
+    function rpc_backend_add_vhost {
573
+        _amqp1_add_vhost $@
574
+    }
575
+    export -f rpc_backend_add_vhost
576
+
534 577
     if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
535 578
         # nothing needed here
536 579
         :

Loading…
Cancel
Save