Added checks on deleting cluster
Checks if cluster is going to be deleted can prevent race condition problems. Change-Id: I85e8bcd2d61ff60ba7eadce1242b0489e354889d Closes-Bug: #1392490
This commit is contained in:
parent
7505c71848
commit
00401e0f5b
@ -144,9 +144,10 @@ def ops_error_handler(f):
|
||||
ctx = context.ctx()
|
||||
cluster = conductor.cluster_get(ctx, cluster_id)
|
||||
# check if cluster still exists (it might have been removed)
|
||||
if cluster is None:
|
||||
LOG.info(_LI("Cluster with %s was deleted. Canceling current "
|
||||
"operation."), cluster_id)
|
||||
if cluster is None or cluster.status == 'Deleting':
|
||||
LOG.info(_LI("Cluster %s was deleted or marked for "
|
||||
"deletion. Canceling current operation."),
|
||||
cluster_id)
|
||||
return
|
||||
|
||||
LOG.exception(
|
||||
|
@ -73,19 +73,26 @@ def natural_sort_key(s):
|
||||
|
||||
|
||||
def change_cluster_status(cluster, status, status_description=None):
|
||||
if cluster is None:
|
||||
return None
|
||||
ctx = context.ctx()
|
||||
|
||||
# Update cluster status. Race conditions with deletion are still possible,
|
||||
# but this reduces probability at least.
|
||||
cluster = conductor.cluster_get(ctx, cluster) if cluster else None
|
||||
|
||||
# 'Deleting' is final and can't be changed
|
||||
if cluster is None or cluster.status == 'Deleting':
|
||||
return cluster
|
||||
|
||||
update_dict = {"status": status}
|
||||
if status_description:
|
||||
update_dict["status_description"] = status_description
|
||||
|
||||
cluster = conductor.cluster_update(context.ctx(), cluster, update_dict)
|
||||
cluster = conductor.cluster_update(ctx, cluster, update_dict)
|
||||
|
||||
LOG.info(_LI("Cluster status has been changed: id=%(id)s, New status="
|
||||
"%(status)s"), {'id': cluster.id, 'status': cluster.status})
|
||||
|
||||
sender.notify(context.ctx(), cluster.id, cluster.name, cluster.status,
|
||||
sender.notify(ctx, cluster.id, cluster.name, cluster.status,
|
||||
"update")
|
||||
|
||||
return cluster
|
||||
|
Loading…
Reference in New Issue
Block a user