From 30d37f1188391e0732020ac8818f470e54487bee Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 29 Jan 2014 18:53:46 -0800 Subject: [PATCH] Tweak version nvp/nsx version validation logic for router operations 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 | 4 +-- neutron/tests/unit/nicira/test_nvplib.py | 39 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/nicira/nvplib.py b/neutron/plugins/nicira/nvplib.py index b7b3655ba..e7e7c8ae7 100644 --- a/neutron/plugins/nicira/nvplib.py +++ b/neutron/plugins/nicira/nvplib.py @@ -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 diff --git a/neutron/tests/unit/nicira/test_nvplib.py b/neutron/tests/unit/nicira/test_nvplib.py index 6488d08cf..57b57a0d1 100644 --- a/neutron/tests/unit/nicira/test_nvplib.py +++ b/neutron/tests/unit/nicira/test_nvplib.py @@ -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', -- 2.45.2