Fix parsing of network gateway id for router

The neutron router-show command with shell formating outputs the
external_gateway_info with literal backslashes to escape the double
quotes. The provider must then match against the literal slashes when
extracting the gateway id. If this is not done, the provider cannot
detect the gateway id from the external_gateway_info property and will
always attempt to change the gateway name from '' to the desired name.

Change-Id: I85a18ed08886cebd14f61b65b3681a75a8d41741
This commit is contained in:
Colleen Murphy 2015-05-31 01:01:38 -07:00 committed by Bogdan Dobrelya
parent 12bace6b7c
commit 7dc6dd0e71
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
@ -50,4 +51,33 @@ describe provider_class do
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