From 968a10ecbe513bb6fc24516939c4df718066c75e Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 8 Dec 2019 10:13:30 +0200 Subject: [PATCH] NSX|V: Fix distributed router validation Validation over router size was wrong Change-Id: I4eb8160552fe071795804021f1f002f844f43584 --- .../nsx_v/drivers/distributed_router_driver.py | 4 ++-- vmware_nsx/tests/unit/nsx_v/test_plugin.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py b/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py index bd2ebc98cf..c8b4ca58ab 100644 --- a/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py +++ b/vmware_nsx/plugins/nsx_v/drivers/distributed_router_driver.py @@ -25,6 +25,7 @@ from neutron_lib.exceptions import l3 as l3_exc from vmware_nsx.common import locking from vmware_nsx.db import nsxv_db +from vmware_nsx.extensions import routersize from vmware_nsx.plugins.nsx_v.drivers import ( abstract_router_driver as router_driver) from vmware_nsx.plugins.nsx_v import plugin as nsx_v @@ -83,8 +84,7 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver): availability_zone=az) def _validate_no_size(self, router): - if (validators.is_attr_set(router.get('routes')) and - len(router['routes']) > 0): + if validators.is_attr_set(router.get(routersize.ROUTER_SIZE)): msg = _("Cannot specify router-size for distributed router") raise n_exc.InvalidInput(error_message=msg) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index 9e0a855387..e7ed2cb1b1 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -4651,6 +4651,17 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase, p['port']['id'], expected_code=exp_code) + def test_router_update_with_size_fail(self): + """Distributed router currently does not support router size update + """ + with self.router() as r: + router_id = r['router']['id'] + body = self._show('routers', router_id) + body['router']['router_size'] = 'small' + self._update('routers', router_id, body, + expected_code=400, + neutron_context=context.get_admin_context()) + class TestNSXvAllowedAddressPairs(NsxVPluginV2TestCase, test_addr_pair.TestAllowedAddressPairs): @@ -5850,7 +5861,7 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase, self._test_create_router_with_az_hint(False) def test_router_update_with_size_fail(self): - """Shared router currently does not support static routes + """Shared router currently does not support router size update """ with self.router() as r: router_id = r['router']['id']