Skip to content

Commit

Permalink
Quotas roll back failure of create volume task
Browse files Browse the repository at this point in the history
Fixes quotas rollback issue if volume creation fails

* Added revert method in QuotaCommitTask to rollback
* volume reservations.

Fixes bug #1230176

Change-Id: I0983ea876983b4294ed0aebb49a065715a185b4e
  • Loading branch information
Abhijeet Malawade authored and j-griffith committed Oct 3, 2013
1 parent 911ba40 commit d762324
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cinder/volume/flows/create_volume/__init__.py
Expand Up @@ -688,11 +688,32 @@ class QuotaCommitTask(base.CinderTask):

def __init__(self):
super(QuotaCommitTask, self).__init__(addons=[ACTION])
self.requires.update(['reservations'])
self.requires.update(['reservations', 'volume_properties'])

def __call__(self, context, reservations):
def __call__(self, context, reservations, volume_properties):
QUOTAS.commit(context, reservations)
context.quota_committed = True
return {'volume_properties': volume_properties}

def revert(self, context, result, cause):
# We never produced a result and therefore can't destroy anything.
if not result:
return
volume = result['volume_properties']
try:
reserve_opts = {'volumes': -1, 'gigabytes': -volume['size']}
QUOTAS.add_volume_type_opts(context,
reserve_opts,
volume['volume_type_id'])
reservations = QUOTAS.reserve(context,
project_id=context.project_id,
**reserve_opts)
if reservations:
QUOTAS.commit(context, reservations,
project_id=context.project_id)
except Exception:
LOG.exception(_("Failed to update quota for deleting volume: %s"),
volume['id'])


class VolumeCastTask(base.CinderTask):
Expand Down

0 comments on commit d762324

Please sign in to comment.