NSX|V: prevent updating router size

Changing router size is allowed only for exclusive routers.
Raise an error for this in case of shared or distributed routers.

Change-Id: I522db0a1a2160550f4a424b5b2939fd43d9b758e
This commit is contained in:
Adit Sarfaty 2019-05-19 11:44:16 +03:00
parent d753ec6945
commit 420fc333a1
3 changed files with 40 additions and 0 deletions

View File

@ -18,6 +18,7 @@ from oslo_utils import excutils
from neutron.db import l3_db
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib.db import api as db_api
from neutron_lib import exceptions as n_exc
@ -82,8 +83,15 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
self.edge_manager.create_lrouter(context, lrouter, dist=True,
availability_zone=az)
def _validate_no_size(self, router):
if (validators.is_attr_set(router.get('routes')) and
len(router['routes']) > 0):
msg = _("Cannot specify router-size for distributed router")
raise n_exc.InvalidInput(error_message=msg)
def update_router(self, context, router_id, router):
r = router['router']
self._validate_no_size(r)
is_routes_update = True if 'routes' in r else False
gw_info = self.plugin._extract_external_gw(context, router,
is_extract=True)

View File

@ -30,6 +30,7 @@ from vmware_nsx.common import exceptions as nsx_exc
from vmware_nsx.common import locking
from vmware_nsx.db import nsxv_db
from vmware_nsx.db import nsxv_models
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 md_proxy as nsx_v_md_proxy
@ -56,9 +57,15 @@ class RouterSharedDriver(router_driver.RouterBaseDriver):
msg = _("Cannot configure static routes on a shared router")
raise n_exc.InvalidInput(error_message=msg)
def _validate_no_size(self, router):
if validators.is_attr_set(router.get(routersize.ROUTER_SIZE)):
msg = _("Cannot specify router-size for shared router")
raise n_exc.InvalidInput(error_message=msg)
def update_router(self, context, router_id, router):
r = router['router']
self._validate_no_routes(r)
self._validate_no_size(r)
# If only the name and or description are updated. We do not need to
# update the backend.

View File

@ -4523,6 +4523,20 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
{'router': {'distributed': True}},
expected_code=200)
def test_router_update_size_fails(self):
"""Check distributed router cannot change it's type
"""
# create a distributed router
tenant_id = _uuid()
res = self._create_router(self.fmt, tenant_id, distributed=True)
r = self.deserialize(self.fmt, res)
router_id = r['router']['id']
# make sure changing the type fails
self._update('routers', router_id,
{'router': {'router_size': 'small'}},
expected_code=400)
def test_router_add_interface_multiple_ipv4_subnets(self):
self.skipTest('TBD')
@ -5775,6 +5789,17 @@ class TestSharedRouterTestCase(L3NatTest, L3NatTestCaseBase,
def test_create_router_without_az_hint(self):
self._test_create_router_with_az_hint(False)
def test_router_update_with_size_fail(self):
"""Shared router currently does not support static routes
"""
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 TestRouterFlavorTestCase(extension.ExtensionTestCase,
test_l3_plugin.L3NatTestCaseMixin,