Browse Source

Initial checkin

Kenneth Giusti 3 years ago
parent
commit
36b49d83ed
2 changed files with 276 additions and 0 deletions
  1. 270
    0
      devstack/plugin.sh
  2. 6
    0
      devstack/settings

+ 270
- 0
devstack/plugin.sh View File

@@ -0,0 +1,270 @@
1
+#!/bin/bash
2
+#
3
+#    Licensed to the Apache Software Foundation (ASF) under one
4
+#    or more contributor license agreements.  See the NOTICE file
5
+#    distributed with this work for additional information
6
+#    regarding copyright ownership.
7
+#
8
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
9
+#    not use this file except in compliance with the License. You may obtain
10
+#    a copy of the License at
11
+#
12
+#         http://www.apache.org/licenses/LICENSE-2.0
13
+#
14
+#    Unless required by applicable law or agreed to in writing, software
15
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+#    License for the specific language governing permissions and limitations
18
+#    under the License.
19
+#
20
+
21
+# Sets up the messaging backend service needed by the AMQP 1.0
22
+# transport (amqp://)
23
+#
24
+# Environment Configuration
25
+#
26
+# AMQP1_SERVICE - identifies the messaging backend to use.  Should be
27
+#    one of 'qpid', ...
28
+#    @TODO(kgiusti) add qpid-dispatch, rabbitmq, etc
29
+# AMQP1_HOST - the host:port used to connect to the messaging service.
30
+#    Defaults to 127.0.0.1:5672
31
+# AMQP1_{USERNAME,PASSWORD} - for authentication with AMQP1_HOST
32
+#
33
+
34
+# Save trace setting
35
+XTRACE=$(set +o | grep xtrace)
36
+set +o xtrace
37
+
38
+# builds transport url string
39
+function _get_amqp1_transport_url {
40
+    echo "amqp://$AMQP1_USERNAME:$AMQP1_PASSWORD@$AMQP1_HOST:5672/"
41
+}
42
+
43
+
44
+# install packages necessary for support of the oslo.messaging AMQP
45
+# 1.0 driver
46
+function _install_pyngus {
47
+    # TODO(kgiusti) remove this once pyngus is upgraded to support
48
+    # auto-loading the proton bits:
49
+    if is_fedora; then
50
+        install_package qpid-proton-c-devel
51
+        install_package python-qpid-proton
52
+    else
53
+        exit_distro_not_supported "QPID AMQP 1.0 Proton libraries"
54
+    fi
55
+
56
+    # Install pyngus client API
57
+    # TODO(kgiusti) enforce minimal version of pyngus
58
+    pip_install_gr pyngus
59
+}
60
+
61
+
62
+# remove packages used by oslo.messaging AMQP 1.0 driver
63
+function _remove_pyngus {
64
+    # TODO(kgiusti) remove this once pyngus is upgraded to support
65
+    # auto-loading the proton bits:
66
+    if is_fedora; then
67
+        uninstall_package qpid-proton-c-devel
68
+        uninstall_package python-qpid-proton
69
+    fi
70
+    # TODO(kgiusti) ubuntu cleanup
71
+    # TODO(kgiusti) no way to pip uninstall?
72
+    # pip_install_gr pyngus
73
+}
74
+
75
+
76
+# Set up the various configuration files used by the qpidd broker
77
+function _configure_qpid {
78
+
79
+    # the location of the configuration files have changed since qpidd 0.14
80
+    local qpid_conf_file
81
+    if [ -e /etc/qpid/qpidd.conf ]; then
82
+        qpid_conf_file=/etc/qpid/qpidd.conf
83
+    elif [ -e /etc/qpidd.conf ]; then
84
+        qpid_conf_file=/etc/qpidd.conf
85
+    else
86
+        exit_distro_not_supported "qpidd.conf file not found!"
87
+    fi
88
+
89
+    # force the ACL file to a known location
90
+    local qpid_acl_file=/etc/qpid/qpidd.acl
91
+    if [ ! -e $qpid_acl_file ]; then
92
+        sudo mkdir -p -m 755 `dirname $qpid_acl_file`
93
+        sudo touch $qpid_acl_file
94
+        sudo chmod o+r $qpid_acl_file
95
+    fi
96
+    sudo sed -i.bak '/^acl-file=/d' $qpid_conf_file
97
+    echo "acl-file=$qpid_acl_file" | sudo tee --append $qpid_conf_file
98
+
99
+    sudo sed -i '/^auth=/d' $qpid_conf_file
100
+    if [ -z "$QPID_USERNAME" ]; then
101
+        # no QPID user configured, so disable authentication
102
+        # and access control
103
+        echo "auth=no" | sudo tee --append $qpid_conf_file
104
+        cat <<EOF | sudo tee $qpid_acl_file
105
+acl allow all all
106
+EOF
107
+    else
108
+        # Configure qpidd to use PLAIN authentication, and add
109
+        # QPID_USERNAME to the ACL:
110
+        echo "auth=yes" | sudo tee --append $qpid_conf_file
111
+        if [ -z "$QPID_PASSWORD" ]; then
112
+            read_password QPID_PASSWORD "ENTER A PASSWORD FOR QPID USER $QPID_USERNAME"
113
+        fi
114
+        # Create ACL to allow $QPID_USERNAME full access
115
+        cat <<EOF | sudo tee $qpid_acl_file
116
+group admin ${QPID_USERNAME}@QPID
117
+acl allow admin all
118
+acl deny all all
119
+EOF
120
+        # Add user to SASL database
121
+        local sasl_conf_file=/etc/sasl2/qpidd.conf
122
+        sudo sed -i.bak '/PLAIN/!s/mech_list: /mech_list: PLAIN /' $sasl_conf_file
123
+        local sasl_db=`sudo grep sasldb_path $sasl_conf_file | cut -f 2 -d ":" | tr -d [:blank:]`
124
+        if [ ! -e $sasl_db ]; then
125
+            sudo mkdir -p -m 755 `dirname $sasl_db`
126
+        fi
127
+        echo $QPID_PASSWORD | sudo saslpasswd2 -c -p -f $sasl_db -u QPID $QPID_USERNAME
128
+        sudo chmod o+r $sasl_db
129
+    fi
130
+
131
+    # Ensure that the version of the broker can support AMQP 1.0 and
132
+    # configure the queue and topic address patterns used by
133
+    # oslo.messaging.
134
+    QPIDD=$(type -p qpidd)
135
+    if ! $QPIDD --help | grep -q "queue-patterns"; then
136
+        exit_distro_not_supported "qpidd with AMQP 1.0 support"
137
+    fi
138
+    if ! grep -q "queue-patterns=exclusive" $qpid_conf_file; then
139
+        cat <<EOF | sudo tee --append $qpid_conf_file
140
+queue-patterns=exclusive
141
+queue-patterns=unicast
142
+topic-patterns=broadcast
143
+EOF
144
+    fi
145
+}
146
+
147
+
148
+# install and configure the qpidd broker
149
+function _install_qpid_backend {
150
+    _install_pyngus
151
+
152
+    if is_fedora; then
153
+        install_package cyrus_sasl_lib
154
+        install_package cyrus_sasl_plain
155
+        install_package qpid-cpp-server
156
+    elif is_ubuntu; then
157
+        install_package sasl2-bin
158
+        install_package qpidd
159
+    else
160
+        exit_distro_not_supported "qpidd installation"
161
+    fi
162
+
163
+    _configure_qpid
164
+}
165
+
166
+
167
+function _start_qpid_backend {
168
+    echo_summary "Starting qpidd broker"
169
+    start_service qpidd
170
+}
171
+
172
+
173
+function _cleanup_qpid_backend {
174
+    if is_fedora; then
175
+        uninstall_package qpid-cpp-server
176
+        # install_package cyrus_sasl_lib
177
+        # install_package cyrus_sasl_plain
178
+    elif is_ubuntu; then
179
+        uninstall_package qpidd
180
+        # install_package sasl2-bin
181
+    else
182
+        exit_distro_not_supported "qpid installation"
183
+    fi
184
+
185
+    _uninstall_pyngus
186
+}
187
+
188
+
189
+# iniset configuration for qpid
190
+function _iniset_qpid_backend {
191
+    local package=$1
192
+    local file=$2
193
+    local section=${3:-DEFAULT}
194
+
195
+    iniset $file $section rpc_backend "amqp"
196
+    # @TODO(kgiusti) why is "qpid_" part of the setting's name?  Why isn't this generic??
197
+    iniset $file $section qpid_hostname ${AMQP1_HOST}
198
+    if [ -n "$AMQP1_USERNAME" ]; then
199
+	iniset $file $section qpid_username $AMQP1_USERNAME
200
+	iniset $file $section qpid_password $AMQP1_PASSWORD
201
+    fi
202
+}
203
+
204
+
205
+if is_service_enabled amqp1; then
206
+    # @TODO(kgiusti) hardcode qpid for now, add other service
207
+    # types as support is provided
208
+    if [ "$AMQP1_SERVICE" != "qpid" ];
209
+        die $LINENO "AMQP 1.0 requires qpid - $AMQP1_SERVICE not supported"
210
+    fi
211
+
212
+    # Note: this is the only tricky part about out of tree rpc plugins,
213
+    # you must overwrite the iniset_rpc_backend function so that when
214
+    # that's passed around the correct settings files are made.
215
+    function iniset_rpc_backend {
216
+        _iniset_${AMQP1_SERVICE}_backend $@
217
+    }
218
+    function get_transport_url {
219
+        _get_amqp1_transport_url $@
220
+    }
221
+    export -f iniset_rpc_backend
222
+    export -f get_transport_url
223
+fi
224
+
225
+
226
+# check for amqp1 service
227
+if is_service_enabled amqp1; then
228
+    if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
229
+        # nothing needed here
230
+        :
231
+
232
+    elif [[ "$1" == "stack" && "$2" == "install" ]]; then
233
+        # Installs and configures the messaging service
234
+        echo_summary "Installing AMQP service $AMQP1_SERVICE"
235
+        _install_${AMQP1_SERVICE}_backend
236
+
237
+    elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
238
+        # Start the messaging service process, this happens before any
239
+        # services start
240
+        _start_${AMQP1_SERVICE}_backend
241
+
242
+    elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
243
+        :
244
+    fi
245
+
246
+    if [[ "$1" == "unstack" ]]; then
247
+        :
248
+    fi
249
+
250
+    if [[ "$1" == "clean" ]]; then
251
+        # Remove state and transient data
252
+        # Remember clean.sh first calls unstack.sh
253
+        _uninstall_${AMQP1_SERVICE}_backend
254
+    fi
255
+fi
256
+
257
+
258
+# Restore xtrace
259
+$XTRACE
260
+
261
+
262
+# Tell emacs to use shell-script-mode
263
+## Local variables:
264
+## mode: shell-script
265
+## End:
266
+
267
+
268
+
269
+
270
+

+ 6
- 0
devstack/settings View File

@@ -0,0 +1,6 @@
1
+enable_service amqp1
2
+disable_service rabbit
3
+AMQP1_SERVICE=${AMQP1_SERVICE:-qpid}
4
+AMQP1_HOST=${AMQP1_HOST:-`hostname`}
5
+
6
+

Loading…
Cancel
Save