]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Return 400 if creating a distributed router on old NVP platforms
authorarmando-migliaccio <amigliaccio@nicira.com>
Tue, 13 Aug 2013 21:13:14 +0000 (14:13 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Fri, 30 Aug 2013 15:41:56 +0000 (08:41 -0700)
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

neutron/plugins/nicira/NeutronPlugin.py
neutron/plugins/nicira/nvplib.py
neutron/tests/unit/nicira/test_nicira_plugin.py

index 46c6fbf868ee93a38d222bb948a6dec52ddd4dee..0e88e8bfc9ba14d86d4897dda31ba0c013857e49 100644 (file)
@@ -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"))
index 58ff0edbed5f819d2fedc2c6b4a05db17f1d08f3..2b0e6e5b485ea5257be5b8ee1209bdf4a71f7c08 100644 (file)
@@ -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):
index 7d737683487ec72c4ced597dd1d8e8dbf6a30e5b..99500c24110e1af49f4cf41c7010937c63318a5f 100644 (file)
@@ -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',