From 8ff2c0d8e7062518925b58be251ed4eb9d5bf331 Mon Sep 17 00:00:00 2001 From: Jerry Cai Date: Fri, 11 Sep 2015 11:20:28 +0800 Subject: [PATCH] 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 --- .../powervc/volume/manager/manager.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cinder-powervc/powervc/volume/manager/manager.py b/cinder-powervc/powervc/volume/manager/manager.py index f63f325..19ce933 100644 --- a/cinder-powervc/powervc/volume/manager/manager.py +++ b/cinder-powervc/powervc/volume/manager/manager.py @@ -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")