From b0f1c38bdcb02068e2e3d0daf2d65695d9d58478 Mon Sep 17 00:00:00 2001 From: Akihiro MOTOKI Date: Sun, 13 Jan 2013 17:58:12 +0900 Subject: [PATCH] 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 in https://review.openstack.org/#/c/19074/. Change-Id: I45e21b1fb85e539213f5243764132a37906d7455 --- functions | 12 ----- lib/cinder | 9 +--- lib/heat | 32 ++----------- lib/quantum | 15 +----- lib/rpc_backend | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ stack.sh | 78 ++++-------------------------- 6 files changed, 137 insertions(+), 132 deletions(-) create mode 100644 lib/rpc_backend diff --git a/functions b/functions index 80e1796991..4795042025 100644 --- a/functions +++ b/functions @@ -1133,18 +1133,6 @@ function get_pip_command() { fi } -# Check if qpid can be used on the current distro. -# qpid_is_supported -function qpid_is_supported() { - if [[ -z "$DISTRO" ]]; then - GetDistro - fi - - # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is - # not in openSUSE either right now. - ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) ) -} - # Restore xtrace $XTRACE diff --git a/lib/cinder b/lib/cinder index d9f8d63fa9..8b1ccd7194 100644 --- a/lib/cinder +++ b/lib/cinder @@ -184,14 +184,7 @@ function configure_cinder() { iniset $CINDER_CONF DEFAULT use_syslog True fi - if is_service_enabled qpid ; then - iniset $CINDER_CONF DEFAULT rpc_backend cinder.openstack.common.rpc.impl_qpid - elif is_service_enabled zeromq; then - iniset $CINDER_CONF DEFAULT rpc_backend nova.openstack.common.rpc.impl_zmq - elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then - iniset $CINDER_CONF DEFAULT rabbit_host $RABBIT_HOST - iniset $CINDER_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - fi + iniset_rpc_backend cinder $CINDER_CONF DEFAULT if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then iniset $CINDER_CONF DEFAULT secure_delete False diff --git a/lib/heat b/lib/heat index 89bd44f0bf..5b8b360ae7 100644 --- a/lib/heat +++ b/lib/heat @@ -69,13 +69,7 @@ function configure_heat() { iniset $HEAT_API_CFN_CONF DEFAULT bind_host $HEAT_API_CFN_HOST iniset $HEAT_API_CFN_CONF DEFAULT bind_port $HEAT_API_CFN_PORT - if is_service_enabled rabbit; then - iniset $HEAT_API_CFN_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu - iniset $HEAT_API_CFN_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - iniset $HEAT_API_CFN_CONF DEFAULT rabbit_host $RABBIT_HOST - elif is_service_enabled qpid; then - iniset $HEAT_API_CFN_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid - fi + iniset_rpc_backend heat $HEAT_API_CFN_CONF DEFAULT HEAT_API_CFN_PASTE_INI=$HEAT_CONF_DIR/heat-api-cfn-paste.ini cp $HEAT_DIR/etc/heat/heat-api-cfn-paste.ini $HEAT_API_CFN_PASTE_INI @@ -98,13 +92,7 @@ function configure_heat() { iniset $HEAT_API_CONF DEFAULT bind_host $HEAT_API_HOST iniset $HEAT_API_CONF DEFAULT bind_port $HEAT_API_PORT - if is_service_enabled rabbit; then - iniset $HEAT_API_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu - iniset $HEAT_API_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - iniset $HEAT_API_CONF DEFAULT rabbit_host $RABBIT_HOST - elif is_service_enabled qpid; then - iniset $HEAT_API_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid - fi + iniset_rpc_backend heat $HEAT_API_CONF DEFAULT HEAT_API_PASTE_INI=$HEAT_CONF_DIR/heat-api-paste.ini cp $HEAT_DIR/etc/heat/heat-api-paste.ini $HEAT_API_PASTE_INI @@ -134,13 +122,7 @@ function configure_heat() { iniset $HEAT_ENGINE_CONF DEFAULT sql_connection $dburl iniset $HEAT_ENGINE_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random` - if is_service_enabled rabbit; then - iniset $HEAT_ENGINE_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu - iniset $HEAT_ENGINE_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - iniset $HEAT_ENGINE_CONF DEFAULT rabbit_host $RABBIT_HOST - elif is_service_enabled qpid; then - iniset $HEAT_ENGINE_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid - fi + iniset_rpc_backend heat $HEAT_ENGINE_CONF DEFAULT # Cloudwatch API HEAT_API_CW_CONF=$HEAT_CONF_DIR/heat-api-cloudwatch.conf @@ -151,13 +133,7 @@ function configure_heat() { iniset $HEAT_API_CW_CONF DEFAULT bind_host $HEAT_API_CW_HOST iniset $HEAT_API_CW_CONF DEFAULT bind_port $HEAT_API_CW_PORT - if is_service_enabled rabbit; then - iniset $HEAT_API_CW_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_kombu - iniset $HEAT_API_CW_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - iniset $HEAT_API_CW_CONF DEFAULT rabbit_host $RABBIT_HOST - elif is_service_enabled qpid; then - iniset $HEAT_API_CW_CONF DEFAULT rpc_backend heat.openstack.common.rpc.impl_qpid - fi + iniset_rpc_backend heat $HEAT_API_CW_CONF DEFAULT HEAT_API_CW_PASTE_INI=$HEAT_CONF_DIR/heat-api-cloudwatch-paste.ini cp $HEAT_DIR/etc/heat/heat-api-cloudwatch-paste.ini $HEAT_API_CW_PASTE_INI diff --git a/lib/quantum b/lib/quantum index 343e5a9b0c..19df49904b 100644 --- a/lib/quantum +++ b/lib/quantum @@ -176,7 +176,7 @@ fi # Set common config for all quantum server and agents. function configure_quantum() { _configure_quantum_common - _configure_quantum_rpc + iniset_rpc_backend quantum $QUANTUM_CONF DEFAULT if is_service_enabled q-svc; then _configure_quantum_service @@ -596,19 +596,6 @@ function _configure_quantum_plugin_agent_ryu() { AGENT_BINARY="$QUANTUM_DIR/quantum/plugins/ryu/agent/ryu_quantum_agent.py" } -# Quantum RPC support - must be updated prior to starting any of the services -function _configure_quantum_rpc() { - iniset $QUANTUM_CONF DEFAULT control_exchange quantum - if is_service_enabled qpid ; then - iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_qpid - elif is_service_enabled zeromq; then - iniset $QUANTUM_CONF DEFAULT rpc_backend quantum.openstack.common.rpc.impl_zmq - elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then - iniset $QUANTUM_CONF DEFAULT rabbit_host $RABBIT_HOST - iniset $QUANTUM_CONF DEFAULT rabbit_password $RABBIT_PASSWORD - fi -} - # _configure_quantum_service() - Set config files for quantum service # It is called when q-svc is enabled. function _configure_quantum_service() { diff --git a/lib/rpc_backend b/lib/rpc_backend new file mode 100644 index 0000000000..4d7f8d2f1d --- /dev/null +++ b/lib/rpc_backend @@ -0,0 +1,123 @@ +# lib/rpc_backend +# Interface for interactig with different rpc backend +# rpc backend settings + +# Dependencies: +# ``functions`` file +# ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used + +# ``stack.sh`` calls the entry points in this order: +# +# check_rpc_backend +# install_rpc_backend +# restart_rpc_backend +# iniset_rpc_backend + +# Save trace setting +XTRACE=$(set +o | grep xtrace) +set +o xtrace + +# Entry Points +# ------------ + +# Make sure we only have one rpc backend enabled. +# Also check the specified rpc backend is available on your platform. +function check_rpc_backend() { + local rpc_backend_cnt=0 + for svc in qpid zeromq rabbit; do + is_service_enabled $svc && + ((rpc_backend_cnt++)) + done + if [ "$rpc_backend_cnt" -gt 1 ]; then + echo "ERROR: only one rpc backend may be enabled," + echo " set only one of 'rabbit', 'qpid', 'zeromq'" + echo " via ENABLED_SERVICES." + elif [ "$rpc_backend_cnt" == 0 ]; then + echo "ERROR: at least one rpc backend must be enabled," + echo " set one of 'rabbit', 'qpid', 'zeromq'" + echo " via ENABLED_SERVICES." + fi + + if is_service_enabled qpid && ! qpid_is_supported; then + echo "Qpid support is not available for this version of your distribution." + exit 1 + fi +} + +# install rpc backend +function install_rpc_backend() { + if is_service_enabled rabbit; then + # Install rabbitmq-server + # the temp file is necessary due to LP: #878600 + tfile=$(mktemp) + install_package rabbitmq-server > "$tfile" 2>&1 + cat "$tfile" + rm -f "$tfile" + elif is_service_enabled qpid; then + if is_fedora; then + install_package qpid-cpp-server-daemon + elif is_ubuntu; then + install_package qpidd + else + exit_distro_not_supported "qpid installation" + fi + elif is_service_enabled zeromq; then + if is_fedora; then + install_package zeromq python-zmq + elif is_ubuntu; then + install_package libzmq1 python-zmq + elif is_suse; then + install_package libzmq1 python-pyzmq + else + exit_distro_not_supported "zeromq installation" + fi + fi +} + +# restart the rpc backend +function restart_rpc_backend() { + if is_service_enabled rabbit; then + # Start rabbitmq-server + echo_summary "Starting RabbitMQ" + if is_fedora || is_suse; then + # service is not started by default + restart_service rabbitmq-server + fi + # change the rabbit password since the default is "guest" + sudo rabbitmqctl change_password guest $RABBIT_PASSWORD + elif is_service_enabled qpid; then + echo_summary "Starting qpid" + restart_service qpidd + fi +} + +# iniset cofiguration +function iniset_rpc_backend() { + local package=$1 + local file=$2 + local section=$3 + if is_service_enabled zeromq; then + iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq + elif is_service_enabled qpid; then + iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid + elif is_service_enabled rabbit; then + iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu + iniset $file $section rabbit_host $RABBIT_HOST + iniset $file $section rabbit_password $RABBIT_PASSWORD + fi +} + +# Check if qpid can be used on the current distro. +# qpid_is_supported +function qpid_is_supported() { + if [[ -z "$DISTRO" ]]; then + GetDistro + fi + + # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is + # not in openSUSE either right now. + ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) ) +} + +# Restore xtrace +$XTRACE diff --git a/stack.sh b/stack.sh index 5c071fcf75..bf473ca7d3 100755 --- a/stack.sh +++ b/stack.sh @@ -95,8 +95,9 @@ if [[ -r $TOP_DIR/.stackenv ]]; then rm $TOP_DIR/.stackenv fi -# Import database configuration +# Import common services (database, message queue) configuration source $TOP_DIR/lib/database +source $TOP_DIR/lib/rpc_backend # Validate database selection # 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) fi fi -if is_service_enabled qpid && ! qpid_is_supported; then - echo "Qpid support is not available for this version of your distribution." - exit 1 -fi +# Make sure we only have one rpc backend enabled, +# and the specified rpc backend is available on your platform. +check_rpc_backend # ``stack.sh`` keeps function libraries here # 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 exit 1 fi -# Make sure we only have one rpc backend enabled. -rpc_backend_cnt=0 -for svc in qpid zeromq rabbit; do - is_service_enabled $svc && - ((rpc_backend_cnt++)) -done -if [ "$rpc_backend_cnt" -gt 1 ]; then - echo "ERROR: only one rpc backend may be enabled," - echo " set only one of 'rabbit', 'qpid', 'zeromq'" - echo " via ENABLED_SERVICES." -elif [ "$rpc_backend_cnt" == 0 ]; then - echo "ERROR: at least one rpc backend must be enabled," - echo " set one of 'rabbit', 'qpid', 'zeromq'" - echo " via ENABLED_SERVICES." -fi -unset rpc_backend_cnt - # Set up logging level VERBOSE=$(trueorfalse True $VERBOSE) @@ -670,32 +653,7 @@ if [[ $SYSLOG != "False" ]]; then fi fi -if is_service_enabled rabbit; then - # Install rabbitmq-server - # the temp file is necessary due to LP: #878600 - tfile=$(mktemp) - install_package rabbitmq-server > "$tfile" 2>&1 - cat "$tfile" - rm -f "$tfile" -elif is_service_enabled qpid; then - if is_fedora; then - install_package qpid-cpp-server-daemon - elif is_ubuntu; then - install_package qpidd - else - exit_distro_not_supported "qpid installation" - fi -elif is_service_enabled zeromq; then - if is_fedora; then - install_package zeromq python-zmq - elif is_ubuntu; then - install_package libzmq1 python-zmq - elif is_suse; then - install_package libzmq1 python-pyzmq - else - exit_distro_not_supported "zeromq installation" - fi -fi +install_rpc_backend if is_service_enabled $DATABASE_BACKENDS; then install_database @@ -868,20 +826,7 @@ fi # Finalize queue installation # ---------------------------- - -if is_service_enabled rabbit; then - # Start rabbitmq-server - echo_summary "Starting RabbitMQ" - if is_fedora || is_suse; then - # service is not started by default - restart_service rabbitmq-server - fi - # change the rabbit password since the default is "guest" - sudo rabbitmqctl change_password guest $RABBIT_PASSWORD -elif is_service_enabled qpid; then - echo_summary "Starting qpid" - restart_service qpidd -fi +restart_rpc_backend # Configure database @@ -1075,14 +1020,7 @@ if is_service_enabled nova; then iniset $NOVA_CONF DEFAULT vncserver_listen "$VNCSERVER_LISTEN" iniset $NOVA_CONF DEFAULT vncserver_proxyclient_address "$VNCSERVER_PROXYCLIENT_ADDRESS" iniset $NOVA_CONF DEFAULT ec2_dmz_host "$EC2_DMZ_HOST" - if is_service_enabled zeromq; then - iniset $NOVA_CONF DEFAULT rpc_backend "nova.openstack.common.rpc.impl_zmq" - elif is_service_enabled qpid; then - iniset $NOVA_CONF DEFAULT rpc_backend "nova.rpc.impl_qpid" - elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then - iniset $NOVA_CONF DEFAULT rabbit_host "$RABBIT_HOST" - iniset $NOVA_CONF DEFAULT rabbit_password "$RABBIT_PASSWORD" - fi + iniset_rpc_backend nova $NOVA_CONF DEFAULT iniset $NOVA_CONF DEFAULT glance_api_servers "$GLANCE_HOSTPORT"