Merge "Allow explicitly setting enable_snat to either value"

This commit is contained in:
Zuul
2018-05-26 03:20:42 +00:00
committed by Gerrit Code Review
2 changed files with 22 additions and 7 deletions

View File

@ -4086,11 +4086,9 @@ class OpenStackCloud(_normalize.Normalizer):
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.TestCase):
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.TestCase):
'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()