Enhance update edge error handle

Sometimes update edge call at the backend may fail somehow. Our present
codes would just ignore the error and keep following ops which may lead
to a seriese of errors. This patch enhances update edge error handle via
marking corresponding router binding's status to ERROR. So that we can
avoid reuse this edge when we attach following service.

Change-Id: I42b632ba7c66cd4fc5e57e6bb91c9c91ec513622
This commit is contained in:
linb 2016-04-13 14:58:43 +08:00
parent c0e629a6b1
commit f351816122
3 changed files with 22 additions and 4 deletions

View File

@ -602,6 +602,7 @@ class EdgeApplianceDriver(object):
if not dist and loadbalancer_enable:
self._enable_loadbalancer(edge)
userdata = {
'router_id': router_id,
'edge_id': edge_id,
'request': edge,
'jobdata': jobdata

View File

@ -594,7 +594,8 @@ class EdgeManager(object):
dist = (binding['edge_type'] == nsxv_constants.VDR_EDGE)
edge_pool_range = self.edge_pool_dicts[binding['edge_type']].get(
binding['appliance_size'])
if (not self.check_edge_active_at_backend(binding['edge_id']) or
if (binding['status'] == plugin_const.ERROR or
not self.check_edge_active_at_backend(binding['edge_id']) or
not edge_pool_range):
nsxv_db.update_nsxv_router_binding(
context.session, router_id,
@ -631,7 +632,7 @@ class EdgeManager(object):
edge_type=binding['edge_type'])
# change edge's name at backend
task = self.nsxv_manager.update_edge(
router_id, binding['edge_id'], backup_router_id, None,
backup_router_id, binding['edge_id'], backup_router_id, None,
appliance_size=binding['appliance_size'], dist=dist)
task.wait(task_const.TaskState.RESULT)
@ -2110,7 +2111,23 @@ class NsxVCallbacks(object):
context.session, edge_id)
def edge_update_result(self, task):
LOG.debug("edge_update_result %d", task.status)
router_id = task.userdata.get('router_id')
edge_id = task.userdata.get('edge_id')
if task.status == task_const.TaskStatus.COMPLETED:
LOG.debug("Successfully updated %(edge_id)s for router "
"%(router_id)s",
{'edge_id': edge_id,
'router_id': router_id})
else:
LOG.error(_LE("Failed to update %(edge_id)s for router "
"%(router_id)s"),
{'edge_id': edge_id,
'router_id': router_id})
admin_ctx = q_context.get_admin_context()
if nsxv_db.get_nsxv_router_binding(admin_ctx.session, router_id):
nsxv_db.update_nsxv_router_binding(
admin_ctx.session, router_id,
status=plugin_const.ERROR)
def edge_delete_result(self, task):
jobdata = task.userdata['jobdata']

View File

@ -709,7 +709,7 @@ class EdgeManagerTestCase(EdgeUtilsTestCaseMixin):
self.ctx, 'fake_id')
assert not self.nsxv_manager.delete_edge.called
self.nsxv_manager.update_edge.assert_has_calls(
[mock.call('fake_id', mock.ANY, mock.ANY, None,
[mock.call(mock.ANY, mock.ANY, mock.ANY, None,
appliance_size=nsxv_constants.LARGE, dist=False)])
def test_free_edge_appliance_with_default_with_full(self):