Allow explicitly setting enable_snat to either value

The original code did not allow someone to set enable_snat to True.
Turns out on some clouds the default is the opposite.

Change-Id: Ic3bbfa35f7c6184faa60922b4dd796708de57136
This commit is contained in:
Monty Taylor 2018-05-18 09:15:49 -05:00 committed by Artem Goncharov
parent dcbcfbf124
commit 60aafcc4bc
2 changed files with 22 additions and 7 deletions

View File

@ -4209,11 +4209,9 @@ class OpenStackCloud(
info = {}
if ext_gateway_net_id:
info['network_id'] = ext_gateway_net_id
# Only send enable_snat if it is different from the Neutron
# default of True. Sending it can cause a policy violation error
# on some clouds.
if enable_snat is not None and not enable_snat:
info['enable_snat'] = False
# Only send enable_snat if it is explicitly set.
if enable_snat is not None:
info['enable_snat'] = enable_snat
if ext_fixed_ips:
info['external_fixed_ips'] = ext_fixed_ips
if info:

View File

@ -144,8 +144,8 @@ class TestRouter(base.RequestsMockTestCase):
availability_zone_hints=['nova'])
self.assert_calls()
def test_create_router_with_enable_snat_True(self):
"""Do not send enable_snat when same as neutron default."""
def test_create_router_without_enable_snat(self):
"""Do not send enable_snat when not given."""
self.register_uris([
dict(method='POST',
uri=self.get_mock_url(
@ -156,6 +156,23 @@ class TestRouter(base.RequestsMockTestCase):
'name': self.router_name,
'admin_state_up': True}}))
])
self.cloud.create_router(
name=self.router_name, admin_state_up=True)
self.assert_calls()
def test_create_router_with_enable_snat_True(self):
"""Send enable_snat when it is True."""
self.register_uris([
dict(method='POST',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'routers.json']),
json={'router': self.mock_router_rep},
validate=dict(
json={'router': {
'name': self.router_name,
'admin_state_up': True,
'external_gateway_info': {'enable_snat': True}}}))
])
self.cloud.create_router(
name=self.router_name, admin_state_up=True, enable_snat=True)
self.assert_calls()