Cinder duplicated volume deletion due to potential time window issue

Cinder duplicated volume deletion, which will cause multiple quota
deduction.

Change-Id: I5e970cdb682abac51599b4da93b325fc0707c8f5
Closes-Bug: #1494561
This commit is contained in:
Jerry Cai 2015-09-11 11:20:28 +08:00
parent 276880ece8
commit 8ff2c0d8e7
1 changed files with 16 additions and 12 deletions

View File

@ -775,7 +775,8 @@ class PowerVCCinderManager(service.Service):
:param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary)
"""
# wait 15sec to avoid time window that will duplicated delete volume
time.sleep(15)
pvc_volume_id = payload.get('volume_id')
# If the volume does not already exist locally then ignore
@ -997,23 +998,26 @@ class PowerVCCinderManager(service.Service):
"""
ret = False
volume_id = local_volume.get('id')
volume_name = local_volume.get('name')
volume_name = local_volume.get('display_name')
volume_size = local_volume.get('size')
if volume_id is None:
LOG.debug('Volume id is none and ignore it')
return ret
try:
db.volume_destroy(context, volume_id)
# update the quotas
reserve_opts = {'volumes': -1,
'gigabytes': -volume_size}
reservations = QUOTAS.reserve(context,
**reserve_opts)
LOG.info(_("Start to deduct quota of volume: %s, size: %s") %
(volume_name, volume_size))
QUOTAS.commit(context, reservations)
ret = True
# check first if the volume to be deleted existed.
volume_to_be_deleted = db.volume_get(context, volume_id)
if volume_to_be_deleted:
db.volume_destroy(context, volume_id)
# update the quotas
reserve_opts = {'volumes': -1,
'gigabytes': -volume_size}
reservations = QUOTAS.reserve(context,
**reserve_opts)
LOG.info(_("Start to deduct quota of volume: %s, size: %s") %
(volume_name, volume_size))
QUOTAS.commit(context, reservations)
ret = True
except Exception as e:
ret = False
LOG.debug(_("Failed to delete local volume %s, Exception: %s")