From 5b4a439df15b48096d8389dbb22c1b71f642ccfa Mon Sep 17 00:00:00 2001 From: iberezovskiy Date: Thu, 17 Mar 2016 14:21:39 +0300 Subject: [PATCH] Fix values for rabbit_hosts When rabbit_hosts parameter isn't set (service_default is used) we are forming its value in that way: "$rabbit_host:$rabbit_port". But when host or port or both aren't set (they are also service_default) we can get rabbit_hosts set to "$rabbit_host:" or ":$rabbit_port" or ":". This patch fixes the issue. rabbit_hosts parameter will be set only if it's passed. Change-Id: I9aed2b8a8718e0b0cfca3e25ef93fcff2ad8444a --- manifests/messaging_rabbit.pp | 7 +++--- spec/defines/oslo_messaging_rabbit_spec.rb | 28 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/manifests/messaging_rabbit.pp b/manifests/messaging_rabbit.pp index 4e78a6d..2022bd7 100644 --- a/manifests/messaging_rabbit.pp +++ b/manifests/messaging_rabbit.pp @@ -189,13 +189,14 @@ define oslo::messaging_rabbit( $rabbit_ha_queues_orig = $rabbit_ha_queues } # Do not set rabbit_port and rabbit_host - $rabbit_port_orig = $::os_service_default - $rabbit_host_orig = $::os_service_default + $rabbit_port_orig = $::os_service_default + $rabbit_host_orig = $::os_service_default } else { - $rabbit_hosts_orig = "${rabbit_host}:${rabbit_port}" $rabbit_port_orig = $rabbit_port $rabbit_host_orig = $rabbit_host $rabbit_ha_queues_orig = $rabbit_ha_queues + # Do not set rabbit_hosts if host or port or both are set + $rabbit_hosts_orig = $::os_service_default } $rabbit_options = { 'oslo_messaging_rabbit/amqp_durable_queues' => { value => $amqp_durable_queues }, diff --git a/spec/defines/oslo_messaging_rabbit_spec.rb b/spec/defines/oslo_messaging_rabbit_spec.rb index 2cb65af..2e51726 100644 --- a/spec/defines/oslo_messaging_rabbit_spec.rb +++ b/spec/defines/oslo_messaging_rabbit_spec.rb @@ -15,6 +15,7 @@ describe 'oslo::messaging_rabbit' do is_expected.to contain_keystone_config('oslo_messaging_rabbit/kombu_compression').with_value('') is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_host').with_value('') is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_port').with_value('') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_hosts').with_value('') is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('') is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_userid').with_value('') is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_password').with_value('') @@ -128,6 +129,33 @@ describe 'oslo::messaging_rabbit' do end end + context 'with rabbit host set without rabbit port' do + let :params do + { :rabbit_host => 'rabbit1' } + end + + it 'configures rabbit' do + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_host').with_value('rabbit1') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_port').with_value('') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_hosts').with_value('') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('') + end + end + + context 'with rabbit host and port' do + let :params do + { :rabbit_host => 'rabbit1', + :rabbit_port => '5673' } + end + + it 'configures rabbit' do + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_host').with_value('rabbit1') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_port').with_value('5673') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_hosts').with_value('') + is_expected.to contain_keystone_config('oslo_messaging_rabbit/rabbit_ha_queues').with_value('') + end + end + context 'with incorrect rabbit hosts' do let :params do { :rabbit_hosts => 'rabbit1:5672,rabbit2:5673' }