From 2443294da20b9f59ce5001b957a4bffe0798b340 Mon Sep 17 00:00:00 2001 From: Xingchao Yu Date: Wed, 19 Aug 2015 10:10:45 +0800 Subject: [PATCH] Add rabbit_ha_queues option There are two methods for setting up RabbitMQ HA: 1. Configure rabbit_hosts to multi rabbit hosts. 2. Setting up a loadbalancer in front of RabbitMQ cluster, provide a unique address in rabbit_host In current, rabbit_ha_queues option is controled by rabbit_hosts IF conditional statement. But when users want to use the second method: changing rabbit_ha_queues to true, but they don't use rabbit_hosts option, this logic will not work. This patch adds an rabbit_ha_queues option, set it to undef by default for forward compatbility. Close-Bug: #1485287 Change-Id: Ib8fe16182188729100ef4704466c4d42d31ff510 --- manifests/api.pp | 12 ++++++++++-- manifests/conductor.pp | 12 ++++++++++-- manifests/guestagent.pp | 12 ++++++++++-- manifests/init.pp | 7 ++++++- manifests/taskmanager.pp | 12 ++++++++++-- spec/classes/trove_api_spec.rb | 15 +++++++++++++++ spec/classes/trove_conductor_spec.rb | 15 +++++++++++++++ spec/classes/trove_guestagent_spec.rb | 15 +++++++++++++++ spec/classes/trove_taskmanager_spec.rb | 15 +++++++++++++++ 9 files changed, 106 insertions(+), 9 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index fe4b27e2..7cccac7d 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -279,12 +279,20 @@ class trove::api( } if $::trove::rabbit_hosts { trove_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($::trove::rabbit_hosts, ',') } - trove_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { trove_config { 'oslo_messaging_rabbit/rabbit_host': value => $::trove::rabbit_host } trove_config { 'oslo_messaging_rabbit/rabbit_port': value => $::trove::rabbit_port } trove_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${::trove::rabbit_host}:${::trove::rabbit_port}" } - trove_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + + if $::trove::rabbit_ha_queues == undef { + if size($::trove::rabbit_hosts) > 1 { + trove_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + } else { + trove_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + } else { + trove_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $::trove::rabbit_ha_queues } } trove_config { diff --git a/manifests/conductor.pp b/manifests/conductor.pp index 268c78fa..090d1164 100644 --- a/manifests/conductor.pp +++ b/manifests/conductor.pp @@ -104,12 +104,20 @@ class trove::conductor( } if $::trove::rabbit_hosts { trove_conductor_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($::trove::rabbit_hosts, ',') } - trove_conductor_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { trove_conductor_config { 'oslo_messaging_rabbit/rabbit_host': value => $::trove::rabbit_host } trove_conductor_config { 'oslo_messaging_rabbit/rabbit_port': value => $::trove::rabbit_port } trove_conductor_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${::trove::rabbit_host}:${::trove::rabbit_port}" } - trove_conductor_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + + if $::trove::rabbit_ha_queues == undef { + if size($::trove::rabbit_hosts) > 1 { + trove_conductor_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + } else { + trove_conductor_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + } else { + trove_conductor_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $::trove::rabbit_ha_queues } } trove_conductor_config { diff --git a/manifests/guestagent.pp b/manifests/guestagent.pp index 703d58ad..ac506a2d 100644 --- a/manifests/guestagent.pp +++ b/manifests/guestagent.pp @@ -101,12 +101,20 @@ class trove::guestagent( } if $::trove::rabbit_hosts { trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($::trove::rabbit_hosts, ',') } - trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_host': value => $::trove::rabbit_host } trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_port': value => $::trove::rabbit_port } trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${::trove::rabbit_host}:${::trove::rabbit_port}" } - trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + + if $::trove::rabbit_ha_queues == undef { + if size($::trove::rabbit_hosts) > 1 { + trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + } else { + trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + } else { + trove_guestagent_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $::trove::rabbit_ha_queues } } trove_guestagent_config { diff --git a/manifests/init.pp b/manifests/init.pp index b70bc352..2fd4ccb6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -77,6 +77,10 @@ # available on some distributions. # Defaults to 'TLSv1' # +# [*rabbit_ha_queues*] +# (optional) Use HA queues in RabbitMQ (x-ha-policy: all). +# Defaults to undef +# # [*amqp_durable_queues*] # (optional) Define queues as "durable" to rabbitmq. # Defaults to false @@ -223,12 +227,13 @@ class trove( $nova_proxy_admin_pass, $rabbit_host = 'localhost', - $rabbit_hosts = false, + $rabbit_hosts = undef, $rabbit_password = 'guest', $rabbit_port = '5672', $rabbit_userid = 'guest', $rabbit_virtual_host = '/', $rabbit_use_ssl = false, + $rabbit_ha_queues = undef, $rabbit_notification_topic = 'notifications', $kombu_ssl_ca_certs = undef, $kombu_ssl_certfile = undef, diff --git a/manifests/taskmanager.pp b/manifests/taskmanager.pp index 59711d98..c102d9e3 100644 --- a/manifests/taskmanager.pp +++ b/manifests/taskmanager.pp @@ -162,12 +162,20 @@ class trove::taskmanager( } if $::trove::rabbit_hosts { trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join($::trove::rabbit_hosts, ',') } - trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } } else { trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_host': value => $::trove::rabbit_host } trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_port': value => $::trove::rabbit_port } trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${::trove::rabbit_host}:${::trove::rabbit_port}" } - trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + + if $::trove::rabbit_ha_queues == undef { + if size($::trove::rabbit_hosts) > 1 { + trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } + } else { + trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } + } + } else { + trove_taskmanager_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $::trove::rabbit_ha_queues } } trove_taskmanager_config { diff --git a/spec/classes/trove_api_spec.rb b/spec/classes/trove_api_spec.rb index 6d6b0c84..9d8d66bb 100644 --- a/spec/classes/trove_api_spec.rb +++ b/spec/classes/trove_api_spec.rb @@ -118,6 +118,20 @@ describe 'trove::api' do end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') + end + end + + context 'when using a single RabbitMQ server with enable rabbbit_ha_queues' do + let :pre_condition do + "class { 'trove': + nova_proxy_admin_pass => 'verysecrete', + rabbit_ha_queues => 'true', + rabbit_host => '10.0.0.1'}" + end + it 'configures trove-api with RabbitMQ' do + is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end @@ -129,6 +143,7 @@ describe 'trove::api' do end it 'configures trove-api with RabbitMQ' do is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) + is_expected.to contain_trove_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end diff --git a/spec/classes/trove_conductor_spec.rb b/spec/classes/trove_conductor_spec.rb index c64ce9b7..82ef118e 100644 --- a/spec/classes/trove_conductor_spec.rb +++ b/spec/classes/trove_conductor_spec.rb @@ -41,6 +41,20 @@ describe 'trove::conductor' do end it 'configures trove-conductor with RabbitMQ' do is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') + end + end + + context 'when using a single RabbitMQ server with enable rabbbit_ha_queues' do + let :pre_condition do + "class { 'trove': + nova_proxy_admin_pass => 'verysecrete', + rabbit_ha_queues => 'true', + rabbit_host => '10.0.0.1'}" + end + it 'configures trove-api with RabbitMQ' do + is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end @@ -52,6 +66,7 @@ describe 'trove::conductor' do end it 'configures trove-conductor with RabbitMQ' do is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) + is_expected.to contain_trove_conductor_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end diff --git a/spec/classes/trove_guestagent_spec.rb b/spec/classes/trove_guestagent_spec.rb index a04875d7..80dde495 100644 --- a/spec/classes/trove_guestagent_spec.rb +++ b/spec/classes/trove_guestagent_spec.rb @@ -43,6 +43,20 @@ describe 'trove::guestagent' do end it 'configures trove-guestagent with RabbitMQ' do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') + end + end + + context 'when using a single RabbitMQ server with enable rabbbit_ha_queues' do + let :pre_condition do + "class { 'trove': + nova_proxy_admin_pass => 'verysecrete', + rabbit_ha_queues => 'true', + rabbit_host => '10.0.0.1'}" + end + it 'configures trove-api with RabbitMQ' do + is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end @@ -54,6 +68,7 @@ describe 'trove::guestagent' do end it 'configures trove-guestagent with RabbitMQ' do is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) + is_expected.to contain_trove_guestagent_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end diff --git a/spec/classes/trove_taskmanager_spec.rb b/spec/classes/trove_taskmanager_spec.rb index 5b426808..37f78ef4 100644 --- a/spec/classes/trove_taskmanager_spec.rb +++ b/spec/classes/trove_taskmanager_spec.rb @@ -91,6 +91,20 @@ describe 'trove::taskmanager' do end it 'configures trove-taskmanager with RabbitMQ' do is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('false') + end + end + + context 'when using a single RabbitMQ server with enable rabbbit_ha_queues' do + let :pre_condition do + "class { 'trove': + nova_proxy_admin_pass => 'verysecrete', + rabbit_ha_queues => 'true', + rabbit_host => '10.0.0.1'}" + end + it 'configures trove-api with RabbitMQ' do + is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_host').with_value('10.0.0.1') + is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end @@ -102,6 +116,7 @@ describe 'trove::taskmanager' do end it 'configures trove-taskmanager with RabbitMQ' do is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2']) + is_expected.to contain_trove_taskmanager_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('true') end end