]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Tweak version nvp/nsx version validation logic for router operations
authorarmando-migliaccio <armamig@gmail.com>
Thu, 30 Jan 2014 02:53:46 +0000 (18:53 -0800)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:12 +0000 (15:20 +0800)
This patch improves how the nsx/nvp controller version is validated
prior to some router operations. This is done by greatly simplifying
the boolean condition.

Missing unit tests are also added for increased coverage.

Closes-bug: 1274361

Change-Id: I1b21444fd86b6e6a0c72bb5a43f1707934dd70e4

neutron/plugins/nicira/nvplib.py
neutron/tests/unit/nicira/test_nvplib.py

index b7b3655bafd1b8ae2d67615197fe8350bff9d7d9..e7e7c8ae747b599ddfee0fa489a83b2fa3a47a7c 100644 (file)
@@ -386,7 +386,7 @@ def create_explicit_routing_lrouter(cluster, tenant_id,
 def create_lrouter(cluster, *args, **kwargs):
     if kwargs.get('distributed', None):
         v = cluster.api_client.get_nvp_version()
-        if (v.major < 3) or (v.major == 3 and v.minor < 1):
+        if (v.major, v.minor) < (3, 1):
             raise nvp_exc.NvpInvalidVersion(version=v)
         return v
 
@@ -611,7 +611,7 @@ def update_explicit_routing_lrouter(cluster, router_id,
 def update_lrouter(cluster, *args, **kwargs):
     if kwargs.get('routes', None):
         v = cluster.api_client.get_nvp_version()
-        if (v.major < 3) or (v.major >= 3 and v.minor < 2):
+        if (v.major, v.minor) < (3, 2):
             raise nvp_exc.NvpInvalidVersion(version=v)
         return v
 
index 6488d08cf3c497935c33936956594a9a92c3a5d5..57b57a0d1ccfb2364eefcf5ce3af46894e270ae7 100644 (file)
@@ -638,6 +638,45 @@ class TestNvplibLogicalRouters(NvplibTestCase):
         self._verify_lrouter(res_lrouter, lrouter['uuid'],
                              '*' * 40, '10.0.0.1', 'pippo')
 
+    def _test_version_dependent_update_lrouter(self, version):
+        def foo(*args, **kwargs):
+            return version
+
+        foo_func_dict = {
+            'update_lrouter': {
+                2: {-1: foo},
+                3: {-1: foo, 2: foo}
+            }
+        }
+
+        with mock.patch.object(self.fake_cluster.api_client,
+                               'get_nvp_version',
+                               return_value=NvpApiClient.NVPVersion(version)):
+            with mock.patch.dict(nvplib.NVPLIB_FUNC_DICT,
+                                 foo_func_dict, clear=True):
+                return nvplib.update_lrouter(
+                    self.fake_cluster, 'foo_router_id', 'foo_router_name',
+                    'foo_nexthop', routes={'foo_destination': 'foo_address'})
+
+    def test_version_dependent_update_lrouter_old_versions(self):
+        self.assertRaises(nvp_exc.NvpInvalidVersion,
+                          self._test_version_dependent_update_lrouter,
+                          "2.9")
+        self.assertRaises(nvp_exc.NvpInvalidVersion,
+                          self._test_version_dependent_update_lrouter,
+                          "3.0")
+        self.assertRaises(nvp_exc.NvpInvalidVersion,
+                          self._test_version_dependent_update_lrouter,
+                          "3.1")
+
+    def test_version_dependent_update_lrouter_new_versions(self):
+        self.assertEqual("3.2",
+                         self._test_version_dependent_update_lrouter("3.2"))
+        self.assertEqual("4.0",
+                         self._test_version_dependent_update_lrouter("4.0"))
+        self.assertEqual("4.1",
+                         self._test_version_dependent_update_lrouter("4.1"))
+
     def test_update_lrouter_no_nexthop(self):
         lrouter = nvplib.create_lrouter(self.fake_cluster,
                                         'pippo',