NSX|v: do not resize a router if not necessary
Do not update the size of an exclusive router if it already has this size. Change-Id: I5dbc527d1b00636ca7b8dce4706e9b5e61c815ea
This commit is contained in:
parent
4bf1a654f1
commit
b2e2f910d6
@ -68,15 +68,8 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver):
|
||||
if 'name' in r:
|
||||
self.edge_manager.rename_lrouter(context, router_id, r['name'])
|
||||
if r.get('router_size'):
|
||||
edge_id = edge_utils.get_router_edge_id(context, router_id)
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
edge_cfg = self.vcns.get_edge(edge_id)[1]
|
||||
if edge_cfg.get('appliances'):
|
||||
edge_cfg['appliances']['applianceSize'] = r['router_size']
|
||||
self.vcns.update_edge(edge_id, edge_cfg)
|
||||
nsxv_db.update_nsxv_router_binding(
|
||||
context.session, router_id,
|
||||
appliance_size=r['router_size'])
|
||||
self.edge_manager.resize_lrouter(context, router_id,
|
||||
r['router_size'])
|
||||
return self.plugin.get_router(context, router_id)
|
||||
|
||||
def detach_router(self, context, router_id, router):
|
||||
|
@ -525,6 +525,24 @@ class EdgeApplianceDriver(object):
|
||||
LOG.error(_LE("Failed to rename edge: %s"),
|
||||
e.response)
|
||||
|
||||
def resize_edge(self, edge_id, size):
|
||||
"""update the size of a router edge."""
|
||||
try:
|
||||
# First get the current edge structure
|
||||
# [0] is the status, [1] is the body
|
||||
edge = self.vcns.get_edge(edge_id)[1]
|
||||
if edge.get('appliances'):
|
||||
if edge['appliances']['applianceSize'] == size:
|
||||
LOG.debug('Edge %s is already with size %s',
|
||||
edge_id, size)
|
||||
return
|
||||
# set the new size in the request
|
||||
edge['appliances']['applianceSize'] = size
|
||||
# update the edge
|
||||
self.vcns.update_edge(edge_id, edge)
|
||||
except exceptions.VcnsApiException as e:
|
||||
LOG.error(_LE("Failed to resize edge: %s"), e.response)
|
||||
|
||||
def delete_edge(self, context, router_id, edge_id, dist=False):
|
||||
try:
|
||||
nsxv_db.delete_nsxv_router_binding(context.session, router_id)
|
||||
|
@ -755,6 +755,21 @@ class EdgeManager(object):
|
||||
router_name = self._build_lrouter_name(router_id, new_name)
|
||||
self.nsxv_manager.rename_edge(edge_id, router_name)
|
||||
|
||||
def resize_lrouter(self, context, router_id, new_size):
|
||||
# get the router edge-id
|
||||
binding = nsxv_db.get_nsxv_router_binding(context.session, router_id)
|
||||
if not binding or not binding['edge_id']:
|
||||
LOG.warning(_LW("router binding for router: %s "
|
||||
"not found"), router_id)
|
||||
return
|
||||
edge_id = binding['edge_id']
|
||||
with locking.LockManager.get_lock(str(edge_id)):
|
||||
# update the router on backend
|
||||
self.nsxv_manager.resize_edge(edge_id, new_size)
|
||||
# update the DB
|
||||
nsxv_db.update_nsxv_router_binding(
|
||||
context.session, router_id, appliance_size=new_size)
|
||||
|
||||
def update_dhcp_edge_bindings(self, context, network_id):
|
||||
"""Reconfigure the DHCP to the edge."""
|
||||
resource_id = (vcns_const.DHCP_EDGE_PREFIX + network_id)[:36]
|
||||
|
@ -2609,6 +2609,24 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase,
|
||||
edge_id,
|
||||
new_name + '-' + router_id)
|
||||
|
||||
def test_router_resize(self):
|
||||
with self.router() as r:
|
||||
with mock.patch.object(edge_appliance_driver.EdgeApplianceDriver,
|
||||
'resize_edge') as edge_resize:
|
||||
new_size = 'large'
|
||||
router_id = r['router']['id']
|
||||
# get the edge of this router
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
router_obj = ex_router_driver.RouterExclusiveDriver(plugin)
|
||||
ctx = context.get_admin_context()
|
||||
edge_id = router_obj._get_edge_id_or_raise(ctx, router_id)
|
||||
|
||||
# update the router size
|
||||
body = self._update('routers', router_id,
|
||||
{'router': {'router_size': new_size}})
|
||||
self.assertEqual(new_size, body['router']['router_size'])
|
||||
edge_resize.assert_called_once_with(edge_id, new_size)
|
||||
|
||||
def _test_router_update_gateway_on_l3_ext_net(self, vlan_id=None,
|
||||
validate_ext_gw=False,
|
||||
distributed=False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user