]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Quotas roll back failure of create volume task
authorAbhijeet Malawade <Abhijeet.Malawade@nttdata.com>
Fri, 27 Sep 2013 12:13:52 +0000 (05:13 -0700)
committerJohn Griffith <john.griffith@solidfire.com>
Thu, 3 Oct 2013 00:07:17 +0000 (18:07 -0600)
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

index 119b6bf5b6018a03a4599458306f5f72c757c26b..bb7acd3480604bd56adccf29069e350f3fc61ab1 100644 (file)
@@ -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):