NSXv: eliminate task use from update routes
Make update routes calls synchronous. Change-Id: Ic70a39977b7c8560bdc3a7b70de41fa5192ac47d
This commit is contained in:
parent
6ba97577a0
commit
874f248c5a
@ -69,11 +69,6 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
|
||||
self, context, router_id,
|
||||
newnexthop=vcns_const.INTEGRATION_EDGE_IPADDRESS,
|
||||
metadata_gateway=None):
|
||||
internal_vnic_index = None
|
||||
if newnexthop:
|
||||
internal_vnic_index = (
|
||||
edge_utils.get_internal_vnic_index_of_plr_tlr(
|
||||
context, router_id))
|
||||
routes = []
|
||||
|
||||
# If metadata service is configured, add a static route to direct
|
||||
@ -89,8 +84,7 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
|
||||
routes.extend([route for route in extra_routes
|
||||
if not route.get('external')])
|
||||
edge_utils.update_routes(self.nsx_v, context,
|
||||
router_id, routes, newnexthop,
|
||||
gateway_vnic_index=internal_vnic_index)
|
||||
router_id, routes, newnexthop)
|
||||
|
||||
def create_router(self, context, lrouter, appliance_size=None,
|
||||
allow_metadata=True):
|
||||
|
@ -687,16 +687,10 @@ class EdgeApplianceDriver(object):
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
|
||||
def _update_routes(self, task):
|
||||
edge_id = task.userdata['edge_id']
|
||||
if (task != self.updated_task['route'][edge_id] and
|
||||
task.userdata.get('skippable', True)):
|
||||
# this task does not have the latest config, abort now
|
||||
# for speedup
|
||||
return task_constants.TaskStatus.ABORT
|
||||
gateway = task.userdata['gateway']
|
||||
routes = task.userdata['routes']
|
||||
LOG.debug("VCNS: start updating routes for %s", edge_id)
|
||||
def update_routes(self, edge_id, gateway, routes):
|
||||
if gateway:
|
||||
gateway = gateway.split('/')[0]
|
||||
|
||||
static_routes = []
|
||||
for route in routes:
|
||||
if route.get('vnic_index') is None:
|
||||
@ -725,35 +719,11 @@ class EdgeApplianceDriver(object):
|
||||
}
|
||||
try:
|
||||
self.vcns.update_routes(edge_id, request)
|
||||
status = task_constants.TaskStatus.COMPLETED
|
||||
return True
|
||||
except exceptions.VcnsApiException as e:
|
||||
LOG.exception(_LE("VCNS: Failed to update routes:\n%s"),
|
||||
e.response)
|
||||
status = task_constants.TaskStatus.ERROR
|
||||
|
||||
return status
|
||||
|
||||
def update_routes(self, router_id, edge_id, gateway, routes,
|
||||
skippable=True, jobdata=None,
|
||||
gateway_vnic_index=constants.EXTERNAL_VNIC_INDEX):
|
||||
if gateway:
|
||||
gateway = gateway.split('/')[0]
|
||||
|
||||
userdata = {
|
||||
'edge_id': edge_id,
|
||||
'gateway': gateway,
|
||||
'gateway_vnic_index': gateway_vnic_index,
|
||||
'routes': routes,
|
||||
'skippable': skippable,
|
||||
'jobdata': jobdata
|
||||
}
|
||||
task_name = "update-routes-%s" % (edge_id)
|
||||
task = tasks.Task(task_name, router_id, self._update_routes,
|
||||
userdata=userdata)
|
||||
task.add_result_monitor(self.callbacks.routes_update_result)
|
||||
self.updated_task['route'][edge_id] = task
|
||||
self.task_manager.add(task)
|
||||
return task
|
||||
return False
|
||||
|
||||
def create_lswitch(self, name, tz_config, tags=None,
|
||||
port_isolation=False, replication_mode="service"):
|
||||
|
@ -1500,9 +1500,8 @@ class EdgeManager(object):
|
||||
plr_vnic_index = nsxv_db.get_edge_vnic_binding(
|
||||
context.session, plr_edge_id, lswitch_id).vnic_index
|
||||
# Clear static routes before delete internal vnic
|
||||
task = self.nsxv_manager.update_routes(
|
||||
plr_id, plr_edge_id, None, [])
|
||||
task.wait(task_const.TaskState.RESULT)
|
||||
self.nsxv_manager.update_routes(plr_edge_id, None, [])
|
||||
|
||||
# Delete internal vnic
|
||||
self.nsxv_manager.delete_interface(plr_id, plr_edge_id, plr_vnic_index)
|
||||
nsxv_db.free_edge_vnic_by_network(
|
||||
@ -1511,9 +1510,8 @@ class EdgeManager(object):
|
||||
self.delete_lrouter(context, plr_id)
|
||||
|
||||
# Clear static routes of vdr
|
||||
task = self.nsxv_manager.update_routes(
|
||||
router_id, tlr_edge_id, None, [])
|
||||
task.wait(task_const.TaskState.RESULT)
|
||||
self.nsxv_manager.update_routes(tlr_edge_id, None, [])
|
||||
|
||||
#First delete the vdr's external interface
|
||||
tlr_vnic_index = nsxv_db.get_edge_vnic_binding(
|
||||
context.session, tlr_edge_id, lswitch_id).vnic_index
|
||||
@ -1875,8 +1873,7 @@ def update_gateway(nsxv_manager, context, router_id, nexthop, routes=None):
|
||||
edge_id = binding['edge_id']
|
||||
if routes is None:
|
||||
routes = []
|
||||
task = nsxv_manager.update_routes(router_id, edge_id, nexthop, routes)
|
||||
task.wait(task_const.TaskState.RESULT)
|
||||
nsxv_manager.update_routes(edge_id, nexthop, routes)
|
||||
|
||||
|
||||
def get_routes(edge_manager, context, router_id):
|
||||
@ -1908,9 +1905,7 @@ def get_routes(edge_manager, context, router_id):
|
||||
return routes
|
||||
|
||||
|
||||
def update_routes(edge_manager, context, router_id, routes,
|
||||
nexthop=None,
|
||||
gateway_vnic_index=vcns_const.EXTERNAL_VNIC_INDEX):
|
||||
def update_routes(edge_manager, context, router_id, routes, nexthop=None):
|
||||
binding = nsxv_db.get_nsxv_router_binding(context.session, router_id)
|
||||
if not binding:
|
||||
LOG.error(_LE('Router binding not found for router %s'), router_id)
|
||||
@ -1945,9 +1940,7 @@ def update_routes(edge_manager, context, router_id, routes,
|
||||
'net_id': route['network_id'],
|
||||
'dest': route['destination'],
|
||||
'nexthop': route['nexthop']})
|
||||
task = edge_manager.update_routes(router_id, edge_id, nexthop, edge_routes,
|
||||
gateway_vnic_index=gateway_vnic_index)
|
||||
task.wait(task_const.TaskState.RESULT)
|
||||
edge_manager.update_routes(edge_id, nexthop, edge_routes)
|
||||
|
||||
|
||||
def get_internal_lswitch_id_of_plr_tlr(context, router_id):
|
||||
@ -2316,8 +2309,5 @@ class NsxVCallbacks(object):
|
||||
def interface_update_result(self, task):
|
||||
LOG.debug("interface_update_result %d", task.status)
|
||||
|
||||
def routes_update_result(self, task):
|
||||
LOG.debug("routes_update_result %d", task.status)
|
||||
|
||||
def nat_update_result(self, task):
|
||||
LOG.debug("nat_update_result %d", task.status)
|
||||
|
@ -364,10 +364,6 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['nat_update_result'] = True
|
||||
|
||||
def routes_update_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['routes_update_result'] = True
|
||||
|
||||
def interface_update_result(self, task):
|
||||
if task.status == ts_const.TaskStatus.COMPLETED:
|
||||
task.userdata['jobdata']['interface_update_result'] = True
|
||||
@ -460,7 +456,6 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
|
||||
def test_update_routes(self):
|
||||
self._deploy_edge()
|
||||
jobdata = {}
|
||||
routes = [{
|
||||
'cidr': '192.168.1.0/24',
|
||||
'nexthop': '169.254.2.1'
|
||||
@ -472,10 +467,9 @@ class VcnsDriverTestCase(base.BaseTestCase):
|
||||
'nexthop': '169.254.2.1'
|
||||
}
|
||||
]
|
||||
task = self.vcns_driver.update_routes(
|
||||
'router-id', self.edge_id, '10.0.0.1', routes, jobdata=jobdata)
|
||||
task.wait(ts_const.TaskState.RESULT)
|
||||
self.assertTrue(jobdata.get('routes_update_result'))
|
||||
result = self.vcns_driver.update_routes(
|
||||
self.edge_id, '10.0.0.1', routes)
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_update_interface(self):
|
||||
self._deploy_edge()
|
||||
|
Loading…
x
Reference in New Issue
Block a user