From: armando-migliaccio Date: Tue, 13 Aug 2013 21:13:14 +0000 (-0700) Subject: Return 400 if creating a distributed router on old NVP platforms X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4cc297f103172ab41665e6237ceb63bff303ad86;p=openstack-build%2Fneutron-build.git Return 400 if creating a distributed router on old NVP platforms Without checking for the right NVP support, creating a distributed router will silently fail, i.e. ithe 'distributed' attribute will be ignored and a centralized router will be created instead. Supports blueprint nvp-distributed-router Change-Id: If8e40c0907d78c30f9ba918aaaff57e58ebb8055 --- diff --git a/neutron/plugins/nicira/NeutronPlugin.py b/neutron/plugins/nicira/NeutronPlugin.py index 46c6fbf86..0e88e8bfc 100644 --- a/neutron/plugins/nicira/NeutronPlugin.py +++ b/neutron/plugins/nicira/NeutronPlugin.py @@ -1639,6 +1639,12 @@ class NvpPluginV2(db_base_plugin_v2.NeutronDbPluginV2, # This will be useful for setting the value if the API request # did not specify any value for the 'distributed' attribute r['distributed'] = lrouter['distributed'] + except nvp_exc.NvpInvalidVersion: + msg = _("Cannot create a distributed router with the NVP " + "platform currently in execution. Please, try " + "without specifying the 'distributed' attribute.") + LOG.exception(msg) + raise q_exc.BadRequest(resource='router', msg=msg) except NvpApiClient.NvpApiException: raise nvp_exc.NvpPluginException( err_msg=_("Unable to create logical router on NVP Platform")) diff --git a/neutron/plugins/nicira/nvplib.py b/neutron/plugins/nicira/nvplib.py index 58ff0edbe..2b0e6e5b4 100644 --- a/neutron/plugins/nicira/nvplib.py +++ b/neutron/plugins/nicira/nvplib.py @@ -360,7 +360,11 @@ def create_explicit_routing_lrouter(cluster, tenant_id, @version_dependent def create_lrouter(cluster, *args, **kwargs): - pass + if kwargs.get('distributed', None): + v = cluster.api_client.get_nvp_version() + if (v.major < 3) or (v.major >= 3 and v.minor < 1): + raise nvp_exc.NvpInvalidVersion(version=v) + return v def delete_lrouter(cluster, lrouter_id): diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index 7d7376834..99500c241 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -480,9 +480,10 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase, def test_router_create_with_gwinfo_and_l3_ext_net_with_vlan(self): self._test_router_create_with_gwinfo_and_l3_ext_net(444) - def _test_router_create_with_distributed(self, dist_input, dist_expected): + def _test_router_create_with_distributed(self, dist_input, dist_expected, + version='3.1', return_code=201): self.mock_instance.return_value.get_nvp_version.return_value = ( - NvpApiClient.NVPVersion('3.1')) + NvpApiClient.NVPVersion(version)) data = {'tenant_id': 'whatever'} data['name'] = 'router1' @@ -491,12 +492,15 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase, 'routers', {'router': data}, self.fmt) try: res = router_req.get_response(self.ext_api) - router = self.deserialize(self.fmt, res) - self.assertIn('distributed', router['router']) - self.assertEqual(dist_expected, - router['router']['distributed']) + self.assertEqual(return_code, res.status_int) + if res.status_int == 201: + router = self.deserialize(self.fmt, res) + self.assertIn('distributed', router['router']) + self.assertEqual(dist_expected, + router['router']['distributed']) finally: - self._delete('routers', router['router']['id']) + if res.status_int == 201: + self._delete('routers', router['router']['id']) def test_router_create_distributed(self): self._test_router_create_with_distributed(True, True) @@ -507,6 +511,9 @@ class TestNiciraL3NatTestCase(test_l3_plugin.L3NatDBTestCase, def test_router_create_distributed_unspecified(self): self._test_router_create_with_distributed(None, False) + def test_router_create_distributed_returns_400(self): + self._test_router_create_with_distributed(True, None, '3.0', 400) + def test_router_create_nvp_error_returns_500(self, vlan_id=None): with mock.patch.object(nvplib, 'create_router_lport',