NSX|V: validate GW information is correct when attaching router

Commit 5e79efbcf3fdcbae06400cf24556403ccd3537d9 skipped testing
this to unblock the gate. Now we fix the test and ensure that code
also works with update.

Change-Id: I0586dea335b9d52f4f1703f4e192d3f5a8512ee3
This commit is contained in:
Gary Kotton 2016-06-19 04:32:07 -07:00
parent 673dc7c131
commit dfc54e63b0
2 changed files with 25 additions and 1 deletions

View File

@ -1929,6 +1929,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
raise n_exc.InvalidInput(error_message=err_msg)
def update_router(self, context, router_id, router):
# Validate that the gateway information is relevant
self._extract_external_gw(context, router, is_extract=False)
# Toggling the distributed flag is not supported
if 'distributed' in router['router']:
r = self.get_router(context, router_id)

View File

@ -1900,8 +1900,30 @@ class L3NatTest(test_l3_plugin.L3BaseForIntTests, NsxVPluginV2TestCase):
def test_router_add_gateway_no_subnet(self):
self.skipTest('No support for no subnet gateway set')
def _set_net_external(self, net_id):
self._update('networks', net_id,
{'network': {external_net.EXTERNAL: True}})
def _add_external_gateway_to_router(self, router_id, network_id,
expected_code=webob.exc.HTTPOk.code,
neutron_context=None, ext_ips=None):
ext_ips = ext_ips or []
body = {'router':
{'external_gateway_info': {'network_id': network_id}}}
if ext_ips:
body['router']['external_gateway_info'][
'external_fixed_ips'] = ext_ips
return self._update('routers', router_id, body,
expected_code=expected_code,
neutron_context=neutron_context)
def test_router_add_gateway_no_subnet_forbidden(self):
self.skipTest('TBD - unblock gate')
with self.router() as r:
with self.network() as n:
self._set_net_external(n['network']['id'])
self._add_external_gateway_to_router(
r['router']['id'], n['network']['id'],
expected_code=webob.exc.HTTPBadRequest.code)
class L3NatTestCaseBase(test_l3_plugin.L3NatTestCaseMixin):