Browse code

Refactor rpc backend configuration logic

This commit also changes the following:
- Fixes Nova QPID module path
- Fixes a bug Cinder ZeroMQ RPC points to nova module
- Adds ZeroMQ setting for Heat RPC

qpid_is_supported is moved from functions to lib/rpc_backend.

This work is based on the work by Isaku Yamahata <yamahata@valinux.co.jp>
in https://review.openstack.org/#/c/19074/.

Change-Id: I45e21b1fb85e539213f5243764132a37906d7455

Akihiro MOTOKI authored on 2013/01/13 17:58:12
Showing 6 changed files
... ...
@@ -1133,18 +1133,6 @@ function get_pip_command() {
1133 1133
     fi
1134 1134
 }
1135 1135
 
1136
-# Check if qpid can be used on the current distro.
1137
-# qpid_is_supported
1138
-function qpid_is_supported() {
1139
-    if [[ -z "$DISTRO" ]]; then
1140
-        GetDistro
1141
-    fi
1142
-
1143
-    # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
1144
-    # not in openSUSE either right now.
1145
-    ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
1146
-}
1147
-
1148 1136
 # Restore xtrace
1149 1137
 $XTRACE
1150 1138
 
... ...
@@ -184,14 +184,7 @@ function configure_cinder() {
184 184
         iniset $CINDER_CONF DEFAULT use_syslog True
185 185
     fi
186 186
 
187
-    if is_service_enabled qpid ; then
188
-        iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid
189
-    elif is_service_enabled zeromq; then
190
-        iniset $CINDER_CONF DEFAULT rpc_backend nova.openstack.common.rpc.impl_zmq
191
-    elif [ -n "$RABBIT_HOST" ] &&  [ -n "$RABBIT_PASSWORD" ]; then
192
-        iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST
193
-        iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
194
-    fi
187
+    iniset_rpc_backend cinder $CINDER_CONF DEFAULT
195 188
 
196 189
     if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then
197 190
         iniset $CINDER_CONF DEFAULT secure_delete False
... ...
@@ -69,13 +69,7 @@ function configure_heat() {
69 69
     iniset $HEAT_API_CFN_CONF DEFAULT bind_host $HEAT_API_CFN_HOST
70 70
     iniset $HEAT_API_CFN_CONF DEFAULT bind_port $HEAT_API_CFN_PORT
71 71
 
72
-    if is_service_enabled rabbit; then
73
-        iniset $HEAT_API_CFN_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu
74
-        iniset $HEAT_API_CFN_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
75
-        iniset $HEAT_API_CFN_CONF DEFAULT rabbit_host $RABBIT_HOST
76
-    elif is_service_enabled qpid; then
77
-        iniset $HEAT_API_CFN_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid
78
-    fi
72
+    iniset_rpc_backend heat $HEAT_API_CFN_CONF DEFAULT
79 73
 
80 74
     HEAT_API_CFN_PASTE_INI=$HEAT_CONF_DIR/heat-api-cfn-paste.ini
81 75
     cp $HEAT_DIR/etc/heat/heat-api-cfn-paste.ini $HEAT_API_CFN_PASTE_INI
... ...
@@ -98,13 +92,7 @@ function configure_heat() {
98 98
     iniset $HEAT_API_CONF DEFAULT bind_host $HEAT_API_HOST
99 99
     iniset $HEAT_API_CONF DEFAULT bind_port $HEAT_API_PORT
100 100
 
101
-    if is_service_enabled rabbit; then
102
-        iniset $HEAT_API_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu
103
-        iniset $HEAT_API_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
104
-        iniset $HEAT_API_CONF DEFAULT rabbit_host $RABBIT_HOST
105
-    elif is_service_enabled qpid; then
106
-        iniset $HEAT_API_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid
107
-    fi
101
+    iniset_rpc_backend heat $HEAT_API_CONF DEFAULT
108 102
 
109 103
     HEAT_API_PASTE_INI=$HEAT_CONF_DIR/heat-api-paste.ini
110 104
     cp $HEAT_DIR/etc/heat/heat-api-paste.ini $HEAT_API_PASTE_INI
... ...
@@ -134,13 +122,7 @@ function configure_heat() {
134 134
     iniset $HEAT_ENGINE_CONF DEFAULT sql_connection $dburl
135 135
     iniset $HEAT_ENGINE_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
136 136
 
137
-    if is_service_enabled rabbit; then
138
-        iniset $HEAT_ENGINE_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu
139
-        iniset $HEAT_ENGINE_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
140
-        iniset $HEAT_ENGINE_CONF DEFAULT rabbit_host $RABBIT_HOST
141
-    elif is_service_enabled qpid; then
142
-        iniset $HEAT_ENGINE_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid
143
-    fi
137
+    iniset_rpc_backend heat $HEAT_ENGINE_CONF DEFAULT
144 138
 
145 139
     # Cloudwatch API
146 140
     HEAT_API_CW_CONF=$HEAT_CONF_DIR/heat-api-cloudwatch.conf
... ...
@@ -151,13 +133,7 @@ function configure_heat() {
151 151
     iniset $HEAT_API_CW_CONF DEFAULT bind_host $HEAT_API_CW_HOST
152 152
     iniset $HEAT_API_CW_CONF DEFAULT bind_port $HEAT_API_CW_PORT
153 153
 
154
-    if is_service_enabled rabbit; then
155
-        iniset $HEAT_API_CW_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu
156
-        iniset $HEAT_API_CW_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
157
-        iniset $HEAT_API_CW_CONF DEFAULT rabbit_host $RABBIT_HOST
158
-    elif is_service_enabled qpid; then
159
-        iniset $HEAT_API_CW_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid
160
-    fi
154
+    iniset_rpc_backend heat $HEAT_API_CW_CONF DEFAULT
161 155
 
162 156
     HEAT_API_CW_PASTE_INI=$HEAT_CONF_DIR/heat-api-cloudwatch-paste.ini
163 157
     cp $HEAT_DIR/etc/heat/heat-api-cloudwatch-paste.ini $HEAT_API_CW_PASTE_INI
... ...
@@ -176,7 +176,7 @@ fi
176 176
 # Set common config for all quantum server and agents.
177 177
 function configure_quantum() {
178 178
     _configure_quantum_common
179
-    _configure_quantum_rpc
179
+    iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT
180 180
 
181 181
     if is_service_enabled q-svc; then
182 182
         _configure_quantum_service
... ...
@@ -596,19 +596,6 @@ function _configure_quantum_plugin_agent_ryu() {
596 596
     AGENT_BINARY="$QUANTUM_DIR/quantum/plugins/ryu/agent/ryu_quantum_agent.py"
597 597
 }
598 598
 
599
-# Quantum RPC support - must be updated prior to starting any of the services
600
-function _configure_quantum_rpc() {
601
-    iniset $QUANTUM_CONF DEFAULT control_exchange quantum
602
-    if is_service_enabled qpid ; then
603
-        iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_qpid
604
-    elif is_service_enabled zeromq; then
605
-        iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_zmq
606
-    elif [ -n "$RABBIT_HOST" ] &&  [ -n "$RABBIT_PASSWORD" ]; then
607
-        iniset $QUANTUM_CONF DEFAULT rabbit_host $RABBIT_HOST
608
-        iniset $QUANTUM_CONF DEFAULT rabbit_password $RABBIT_PASSWORD
609
-    fi
610
-}
611
-
612 599
 # _configure_quantum_service() - Set config files for quantum service
613 600
 # It is called when q-svc is enabled.
614 601
 function _configure_quantum_service() {
615 602
new file mode 100644
... ...
@@ -0,0 +1,123 @@
0
+# lib/rpc_backend
1
+# Interface for interactig with different rpc backend
2
+# rpc backend settings
3
+
4
+# Dependencies:
5
+# ``functions`` file
6
+# ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used
7
+
8
+# ``stack.sh`` calls the entry points in this order:
9
+#
10
+# check_rpc_backend
11
+# install_rpc_backend
12
+# restart_rpc_backend
13
+# iniset_rpc_backend
14
+
15
+# Save trace setting
16
+XTRACE=$(set +o | grep xtrace)
17
+set +o xtrace
18
+
19
+# Entry Points
20
+# ------------
21
+
22
+# Make sure we only have one rpc backend enabled.
23
+# Also check the specified rpc backend is available on your platform.
24
+function check_rpc_backend() {
25
+    local rpc_backend_cnt=0
26
+    for svc in qpid zeromq rabbit; do
27
+        is_service_enabled $svc &&
28
+        ((rpc_backend_cnt++))
29
+    done
30
+    if [ "$rpc_backend_cnt" -gt 1 ]; then
31
+        echo "ERROR: only one rpc backend may be enabled,"
32
+        echo "       set only one of 'rabbit', 'qpid', 'zeromq'"
33
+        echo "       via ENABLED_SERVICES."
34
+    elif [ "$rpc_backend_cnt" == 0 ]; then
35
+        echo "ERROR: at least one rpc backend must be enabled,"
36
+        echo "       set one of 'rabbit', 'qpid', 'zeromq'"
37
+        echo "       via ENABLED_SERVICES."
38
+    fi
39
+
40
+    if is_service_enabled qpid && ! qpid_is_supported; then
41
+        echo "Qpid support is not available for this version of your distribution."
42
+        exit 1
43
+    fi
44
+}
45
+
46
+# install rpc backend
47
+function install_rpc_backend() {
48
+    if is_service_enabled rabbit; then
49
+        # Install rabbitmq-server
50
+        # the temp file is necessary due to LP: #878600
51
+        tfile=$(mktemp)
52
+        install_package rabbitmq-server > "$tfile" 2>&1
53
+        cat "$tfile"
54
+        rm -f "$tfile"
55
+    elif is_service_enabled qpid; then
56
+        if is_fedora; then
57
+            install_package qpid-cpp-server-daemon
58
+        elif is_ubuntu; then
59
+            install_package qpidd
60
+        else
61
+            exit_distro_not_supported "qpid installation"
62
+        fi
63
+    elif is_service_enabled zeromq; then
64
+        if is_fedora; then
65
+            install_package zeromq python-zmq
66
+        elif is_ubuntu; then
67
+            install_package libzmq1 python-zmq
68
+        elif is_suse; then
69
+            install_package libzmq1 python-pyzmq
70
+        else
71
+            exit_distro_not_supported "zeromq installation"
72
+        fi
73
+    fi
74
+}
75
+
76
+# restart the rpc backend
77
+function restart_rpc_backend() {
78
+    if is_service_enabled rabbit; then
79
+        # Start rabbitmq-server
80
+        echo_summary "Starting RabbitMQ"
81
+        if is_fedora || is_suse; then
82
+            # service is not started by default
83
+            restart_service rabbitmq-server
84
+        fi
85
+        # change the rabbit password since the default is "guest"
86
+        sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
87
+    elif is_service_enabled qpid; then
88
+        echo_summary "Starting qpid"
89
+        restart_service qpidd
90
+    fi
91
+}
92
+
93
+# iniset cofiguration
94
+function iniset_rpc_backend() {
95
+    local package=$1
96
+    local file=$2
97
+    local section=$3
98
+    if is_service_enabled zeromq; then
99
+        iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
100
+    elif is_service_enabled qpid; then
101
+        iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
102
+    elif is_service_enabled rabbit; then
103
+        iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
104
+        iniset $file $section rabbit_host $RABBIT_HOST
105
+        iniset $file $section rabbit_password $RABBIT_PASSWORD
106
+    fi
107
+}
108
+
109
+# Check if qpid can be used on the current distro.
110
+# qpid_is_supported
111
+function qpid_is_supported() {
112
+    if [[ -z "$DISTRO" ]]; then
113
+        GetDistro
114
+    fi
115
+
116
+    # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
117
+    # not in openSUSE either right now.
118
+    ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
119
+}
120
+
121
+# Restore xtrace
122
+$XTRACE
... ...
@@ -95,8 +95,9 @@ if [[ -r $TOP_DIR/.stackenv ]]; then
95 95
     rm $TOP_DIR/.stackenv
96 96
 fi
97 97
 
98
-# Import database configuration
98
+# Import common services (database, message queue) configuration
99 99
 source $TOP_DIR/lib/database
100
+source $TOP_DIR/lib/rpc_backend
100 101
 
101 102
 # Validate database selection
102 103
 # Since DATABASE_BACKENDS is now set, this also gets ENABLED_SERVICES
... ...
@@ -118,10 +119,9 @@ if [[ ! ${DISTRO} =~ (oneiric|precise|quantal|raring|f16|f17|f18|opensuse-12.2)
118 118
     fi
119 119
 fi
120 120
 
121
-if is_service_enabled qpid && ! qpid_is_supported; then
122
-    echo "Qpid support is not available for this version of your distribution."
123
-    exit 1
124
-fi
121
+# Make sure we only have one rpc backend enabled,
122
+# and the specified rpc backend is available on your platform.
123
+check_rpc_backend
125 124
 
126 125
 # ``stack.sh`` keeps function libraries here
127 126
 # Make sure ``$TOP_DIR/lib`` directory is present
... ...
@@ -147,23 +147,6 @@ if type -p screen >/dev/null && screen -ls | egrep -q "[0-9].$SCREEN_NAME"; then
147 147
     exit 1
148 148
 fi
149 149
 
150
-# Make sure we only have one rpc backend enabled.
151
-rpc_backend_cnt=0
152
-for svc in qpid zeromq rabbit; do
153
-    is_service_enabled $svc &&
154
-        ((rpc_backend_cnt++))
155
-done
156
-if [ "$rpc_backend_cnt" -gt 1 ]; then
157
-    echo "ERROR: only one rpc backend may be enabled,"
158
-    echo "       set only one of 'rabbit', 'qpid', 'zeromq'"
159
-    echo "       via ENABLED_SERVICES."
160
-elif [ "$rpc_backend_cnt" == 0 ]; then
161
-    echo "ERROR: at least one rpc backend must be enabled,"
162
-    echo "       set one of 'rabbit', 'qpid', 'zeromq'"
163
-    echo "       via ENABLED_SERVICES."
164
-fi
165
-unset rpc_backend_cnt
166
-
167 150
 # Set up logging level
168 151
 VERBOSE=$(trueorfalse True $VERBOSE)
169 152
 
... ...
@@ -670,32 +653,7 @@ if [[ $SYSLOG != "False" ]]; then
670 670
     fi
671 671
 fi
672 672
 
673
-if is_service_enabled rabbit; then
674
-    # Install rabbitmq-server
675
-    # the temp file is necessary due to LP: #878600
676
-    tfile=$(mktemp)
677
-    install_package rabbitmq-server > "$tfile" 2>&1
678
-    cat "$tfile"
679
-    rm -f "$tfile"
680
-elif is_service_enabled qpid; then
681
-    if is_fedora; then
682
-        install_package qpid-cpp-server-daemon
683
-    elif is_ubuntu; then
684
-        install_package qpidd
685
-    else
686
-        exit_distro_not_supported "qpid installation"
687
-    fi
688
-elif is_service_enabled zeromq; then
689
-    if is_fedora; then
690
-        install_package zeromq python-zmq
691
-    elif is_ubuntu; then
692
-        install_package libzmq1 python-zmq
693
-    elif is_suse; then
694
-        install_package libzmq1 python-pyzmq
695
-    else
696
-        exit_distro_not_supported "zeromq installation"
697
-    fi
698
-fi
673
+install_rpc_backend
699 674
 
700 675
 if is_service_enabled $DATABASE_BACKENDS; then
701 676
     install_database
... ...
@@ -868,20 +826,7 @@ fi
868 868
 
869 869
 # Finalize queue installation
870 870
 # ----------------------------
871
-
872
-if is_service_enabled rabbit; then
873
-    # Start rabbitmq-server
874
-    echo_summary "Starting RabbitMQ"
875
-    if is_fedora || is_suse; then
876
-        # service is not started by default
877
-        restart_service rabbitmq-server
878
-    fi
879
-    # change the rabbit password since the default is "guest"
880
-    sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
881
-elif is_service_enabled qpid; then
882
-    echo_summary "Starting qpid"
883
-    restart_service qpidd
884
-fi
871
+restart_rpc_backend
885 872
 
886 873
 
887 874
 # Configure database
... ...
@@ -1075,14 +1020,7 @@ if is_service_enabled nova; then
1075 1075
     iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN"
1076 1076
     iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS"
1077 1077
     iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST"
1078
-    if is_service_enabled zeromq; then
1079
-        iniset $NOVA_CONF DEFAULT rpc_backend "nova.openstack.common.rpc.impl_zmq"
1080
-    elif is_service_enabled qpid; then
1081
-        iniset $NOVA_CONF DEFAULT rpc_backend "nova.rpc.impl_qpid"
1082
-    elif [ -n "$RABBIT_HOST" ] &&  [ -n "$RABBIT_PASSWORD" ]; then
1083
-        iniset $NOVA_CONF DEFAULT rabbit_host "$RABBIT_HOST"
1084
-        iniset $NOVA_CONF DEFAULT rabbit_password "$RABBIT_PASSWORD"
1085
-    fi
1078
+    iniset_rpc_backend nova $NOVA_CONF DEFAULT
1086 1079
     iniset $NOVA_CONF DEFAULT glance_api_servers "$GLANCE_HOSTPORT"
1087 1080
 
1088 1081