Merge "Fix parsing of network gateway id for router"

This commit is contained in:
Jenkins 2015-07-08 15:22:23 +00:00 committed by Gerrit Code Review
commit 6e786883de
2 changed files with 31 additions and 1 deletions

View File

@ -119,7 +119,7 @@ EOT
end
def parse_gateway_network_id(external_gateway_info_)
match_data = /\{"network_id": "(.*?)"/.match(external_gateway_info_)
match_data = /\{"network_id": "(.*?)"/.match(external_gateway_info_.gsub(/\\"/,'"'))
if match_data
match_data[1]
else

View File

@ -3,6 +3,7 @@ require 'spec_helper'
require 'puppet/provider/neutron_router/neutron'
provider_class = Puppet::Type.type(:neutron_router).provider(:neutron)
klass = Puppet::Provider::Neutron
describe provider_class do
@ -72,4 +73,33 @@ tenant_id="60f9544eb94c42a6b7e8e98c2be981b1"'
end
describe 'when parsing an external gateway info' do
let :resource do
Puppet::Type::Neutron_router.new(router_attrs)
end
let :provider do
provider_class.new(resource)
end
after :each do
klass.reset
end
it 'should detect a gateway net id' do
klass.stubs(:auth_neutron).returns(
'external_gateway_info="{\"network_id\": \"1b-b1\", \"enable_snat\": true, \"external_fixed_ips\": [{\"subnet_id\": \"1b-b1\", \"ip_address\": \"1.1.1.1\"}]}"'
)
result = klass.get_neutron_resource_attrs 'foo', nil
expect(provider.parse_gateway_network_id(result['external_gateway_info'])).to eql('1b-b1')
end
it 'should return empty value, if there is no net id found' do
klass.stubs(:auth_neutron).returns('external_gateway_info="{}"')
result = klass.get_neutron_resource_attrs 'foo', nil
expect(provider.parse_gateway_network_id(result['external_gateway_info'])).to eql('')
end
end
end