Fix os_transport_url with single hosts array

If an array with a single host is passed into the hosts param, the
function was erroring because the host was getting converted to a string
when it was checking for bracketing for ipv6. This change checks the
type and fixes the case where a single host is being passed so it
continues to function.

Change-Id: I91b9959a6f71b4e6885e55a568116cc28cf16ddd
Closes-Bug: #1650042
This commit is contained in:
Alex Schultz
2016-12-14 15:21:03 -07:00
parent d91a4c7b36
commit 8d37c059d2
2 changed files with 16 additions and 0 deletions

View File

@@ -113,6 +113,9 @@ EOS
if v.include?('hosts')
hosts = function_normalize_ip_for_uri([v['hosts']])
# normalize_ip_for_uri may return a string, so check that we still have an
# array
hosts = [hosts] if hosts.kind_of?(String)
hosts = hosts.map{ |h| "#{h}:#{v['port']}" } if v.include?('port')
if parts.include?(:userinfo)
parts[:hostinfo] = hosts.map { |h| "#{parts[:userinfo]}@#{h}" }.join(',')

View File

@@ -37,6 +37,19 @@ describe 'os_transport_url' do
context 'creates the correct transport URI' do
it 'with a single host array for hosts' do
is_expected.to run.with_params({
'transport' => 'rabbit',
'hosts' => [ '127.0.0.1' ],
'port' => '5672',
'username' => 'guest',
'password' => 's3cr3t',
'virtual_host' => 'virt',
'ssl' => '1',
'query' => { 'read_timeout' => '60' },
}).and_return('rabbit://guest:s3cr3t@127.0.0.1:5672/virt?read_timeout=60&ssl=1')
end
it 'with all params for a single host' do
is_expected.to run.with_params({
'transport' => 'rabbit',