From d7623249847010edd2b97085506064da0b642d8d Mon Sep 17 00:00:00 2001 From: Abhijeet Malawade Date: Fri, 27 Sep 2013 05:13:52 -0700 Subject: [PATCH] Quotas roll back failure of create volume task Fixes quotas rollback issue if volume creation fails * Added revert method in QuotaCommitTask to rollback * volume reservations. Fixes bug #1230176 Change-Id: I0983ea876983b4294ed0aebb49a065715a185b4e --- cinder/volume/flows/create_volume/__init__.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cinder/volume/flows/create_volume/__init__.py b/cinder/volume/flows/create_volume/__init__.py index 119b6bf5b..bb7acd348 100644 --- a/cinder/volume/flows/create_volume/__init__.py +++ b/cinder/volume/flows/create_volume/__init__.py @@ -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): -- 2.45.2