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:
@@ -113,6 +113,9 @@ EOS
|
|||||||
|
|
||||||
if v.include?('hosts')
|
if v.include?('hosts')
|
||||||
hosts = function_normalize_ip_for_uri([v['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')
|
hosts = hosts.map{ |h| "#{h}:#{v['port']}" } if v.include?('port')
|
||||||
if parts.include?(:userinfo)
|
if parts.include?(:userinfo)
|
||||||
parts[:hostinfo] = hosts.map { |h| "#{parts[:userinfo]}@#{h}" }.join(',')
|
parts[:hostinfo] = hosts.map { |h| "#{parts[:userinfo]}@#{h}" }.join(',')
|
||||||
|
@@ -37,6 +37,19 @@ describe 'os_transport_url' do
|
|||||||
|
|
||||||
context 'creates the correct transport URI' 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
|
it 'with all params for a single host' do
|
||||||
is_expected.to run.with_params({
|
is_expected.to run.with_params({
|
||||||
'transport' => 'rabbit',
|
'transport' => 'rabbit',
|
||||||
|
Reference in New Issue
Block a user