diff --git a/lib/puppet/provider/neutron.rb b/lib/puppet/provider/neutron.rb index 049d31808..4dcfeee0f 100644 --- a/lib/puppet/provider/neutron.rb +++ b/lib/puppet/provider/neutron.rb @@ -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 diff --git a/spec/unit/provider/neutron_spec.rb b/spec/unit/provider/neutron_spec.rb index 98cc5b082..139b2f306 100644 --- a/spec/unit/provider/neutron_spec.rb +++ b/spec/unit/provider/neutron_spec.rb @@ -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