Fix alias for ext-gw-mode extension in nicira plugin

Also add a unit test for verifying that a 400 is raised when
enable_snat is an invalid string.

Bug 1207556

Change-Id: If33b8c72a08fbf7de1a837a65f083f09903c1809
This commit is contained in:
Salvatore Orlando 2013-08-01 16:03:15 -07:00
parent 0a21ea951b
commit e55e8b14bd
2 changed files with 26 additions and 15 deletions

View File

@ -150,7 +150,7 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
supported_extension_aliases = ["agent",
"binding",
"dhcp_agent_scheduler",
"ext_gw_mode",
"ext-gw-mode",
"extraroute",
"mac-learning",
"network-gateway",

View File

@ -326,7 +326,8 @@ class ExtGwModeTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
expected_code=exc.HTTPOk.code,
neutron_context=None):
ext_gw_info = {'network_id': network_id}
if snat_enabled in (True, False):
# Need to set enable_snat also if snat_enabled == False
if snat_enabled is not None:
ext_gw_info['enable_snat'] = snat_enabled
return self._update('routers', router_id,
{'router': {'external_gateway_info':
@ -378,21 +379,27 @@ class ExtGwModeTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
self._test_router_create_show_ext_gwinfo(False, False)
def _test_router_update_ext_gwinfo(self, snat_input_value,
snat_expected_value):
snat_expected_value=False,
expected_http_code=exc.HTTPOk.code):
with self.router() as r:
with self.subnet() as s:
ext_net_id = s['subnet']['network_id']
self._set_net_external(ext_net_id)
self._set_router_external_gateway(
r['router']['id'], ext_net_id,
snat_enabled=snat_input_value)
body = self._show('routers', r['router']['id'])
res_gw_info = body['router']['external_gateway_info']
self.assertEqual(res_gw_info['network_id'], ext_net_id)
self.assertEqual(res_gw_info['enable_snat'],
snat_expected_value)
self._remove_external_gateway_from_router(
r['router']['id'], ext_net_id)
try:
ext_net_id = s['subnet']['network_id']
self._set_net_external(ext_net_id)
self._set_router_external_gateway(
r['router']['id'], ext_net_id,
snat_enabled=snat_input_value,
expected_code=expected_http_code)
if expected_http_code != exc.HTTPOk.code:
return
body = self._show('routers', r['router']['id'])
res_gw_info = body['router']['external_gateway_info']
self.assertEqual(res_gw_info['network_id'], ext_net_id)
self.assertEqual(res_gw_info['enable_snat'],
snat_expected_value)
finally:
self._remove_external_gateway_from_router(
r['router']['id'], ext_net_id)
def test_router_update_ext_gwinfo_default(self):
self._test_router_update_ext_gwinfo(None, True)
@ -402,3 +409,7 @@ class ExtGwModeTestCase(test_db_plugin.NeutronDbPluginV2TestCase,
def test_router_update_ext_gwinfo_with_snat_disabled(self):
self._test_router_update_ext_gwinfo(False, False)
def test_router_update_ext_gwinfo_with_invalid_snat_setting(self):
self._test_router_update_ext_gwinfo(
'xxx', None, expected_http_code=exc.HTTPBadRequest.code)