From e55e8b14bd91c0d52742c9298370e58874a38e37 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Thu, 1 Aug 2013 16:03:15 -0700 Subject: [PATCH] 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 --- neutron/plugins/nicira/NeutronPlugin.py | 2 +- .../tests/unit/test_extension_ext_gw_mode.py | 39 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/neutron/plugins/nicira/NeutronPlugin.py b/neutron/plugins/nicira/NeutronPlugin.py index c952b84a20..38ffe192cc 100644 --- a/neutron/plugins/nicira/NeutronPlugin.py +++ b/neutron/plugins/nicira/NeutronPlugin.py @@ -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", diff --git a/neutron/tests/unit/test_extension_ext_gw_mode.py b/neutron/tests/unit/test_extension_ext_gw_mode.py index 5da43518f9..65e11314a2 100644 --- a/neutron/tests/unit/test_extension_ext_gw_mode.py +++ b/neutron/tests/unit/test_extension_ext_gw_mode.py @@ -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)