provider/neutron.rb: fix list_router_ports

The json output of neutron router-interface-list may contain an
an empty 'fixed_ips' field for a port, but JSON.parse does not
work with empty strings. A check is added to ensure that empty
'fixed_ips' fields are directly removed.

Change-Id: Ie130e1c0b9b8fbbfc679ce0c8b5320226249617f
This commit is contained in:
Charlie Brown 2015-12-25 13:44:29 +08:00 committed by Wenxin Wang
parent d5b2757363
commit 791a0f146b
2 changed files with 27 additions and 2 deletions

View File

@ -210,8 +210,10 @@ correctly configured.")
self.find_and_parse_json(cmd_output).each do |port|
if port['fixed_ips']
fixed_ips = JSON.parse(port['fixed_ips'])
port['subnet_id'] = fixed_ips['subnet_id']
if !port['fixed_ips'].empty?
fixed_ips = JSON.parse(port['fixed_ips'])
port['subnet_id'] = fixed_ips['subnet_id']
end
port.delete('fixed_ips')
end
results << port

View File

@ -243,6 +243,29 @@ describe Puppet::Provider::Neutron do
expect(result).to eql(expected)
end
it 'should handle empty fixed_ips field' do
output = '''
[
{
"id": "1345e576-a21f-4c2e-b24a-b245639852ab",
"name": "",
"mac_address": "fa:16:3e:e3:e6:38",
"fixed_ips": ""
}
]
'''
expected =
[{ "name"=>"",
"id"=>"1345e576-a21f-4c2e-b24a-b245639852ab",
"mac_address"=>"fa:16:3e:e3:e6:38"}]
klass.expects(:auth_neutron).
with('router-port-list', '--format=json', router).
returns(output)
result = klass.list_router_ports(router)
expect(result).to eql(expected)
end
end
describe 'when parsing creation output' do