]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Made provision for providing optional arguments
authorabhishekkekane <abhishek.kekane@nttdata.com>
Tue, 10 Jun 2014 06:29:20 +0000 (06:29 +0000)
committerabhishekkekane <abhishek.kekane@nttdata.com>
Mon, 16 Jun 2014 06:41:00 +0000 (06:41 +0000)
The 'quota_committed' attribute of 'RequestContext' object is
a transient property, so it will not be saved in the taskflow
persistent storage. The updated value of 'quota_committed'
attribute will not be available while resuming/reverting the
flow, if cinder api-service is down/stopped after committing
the quota.

Since this 'quota_committed' attribute is not used anywhere
in cinder project other than in create-volume taskflow api, so
removed 'quota_committed' from RequestContext and made
provision to pass it as an optional argument which will be
passed to api-flow via create_what dictionary, in order to
make it persistent and use it as and when needed.

Change-Id: I719067a8e1824add45fb525c106642a9c0e6bb46

cinder/context.py
cinder/volume/api.py
cinder/volume/flows/api/create_volume.py

index e2a7f46e157e62bc6dba05447f84fb6765cd6d8b..8ac8962231ad52cfdc6630256909f43fe2beb32c 100644 (file)
@@ -89,7 +89,6 @@ class RequestContext(object):
         self.quota_class = quota_class
         if overwrite or not hasattr(local.store, 'context'):
             self.update_store()
-        self.quota_committed = False
 
         if service_catalog:
             # Only include required parts of service_catalog
index 2fd65bfea474469c506109a1575f691d953ba409..8e4201ccbae9a43dd809038549401f9da549ba7f 100644 (file)
@@ -174,6 +174,7 @@ class API(base.Base):
             'scheduler_hints': scheduler_hints,
             'key_manager': self.key_manager,
             'backup_source_volume': backup_source_volume,
+            'optional_args': {'is_quota_committed': False}
         }
 
         try:
index 27603c0d3eb69ff2f916f2da5b7dfdbc8a0b3378..8da6032300e190e41839e1a1023967c817b66f7f 100644 (file)
@@ -408,7 +408,7 @@ class EntryCreateTask(flow_utils.CinderTask):
         self.db = db
         self.provides.update()
 
-    def execute(self, context, **kwargs):
+    def execute(self, context, optional_args, **kwargs):
         """Creates a database entry for the given inputs and returns details.
 
         Accesses the database and creates a new entry for the to be created
@@ -449,11 +449,12 @@ class EntryCreateTask(flow_utils.CinderTask):
             'volume': volume,
         }
 
-    def revert(self, context, result, **kwargs):
+    def revert(self, context, result, optional_args, **kwargs):
         # We never produced a result and therefore can't destroy anything.
         if isinstance(result, misc.Failure):
             return
-        if context.quota_committed:
+
+        if optional_args['is_quota_committed']:
             # Committed quota doesn't rollback as the volume has already been
             # created at this point, and the quota has already been absorbed.
             return
@@ -488,7 +489,7 @@ class QuotaReserveTask(flow_utils.CinderTask):
     def __init__(self):
         super(QuotaReserveTask, self).__init__(addons=[ACTION])
 
-    def execute(self, context, size, volume_type_id):
+    def execute(self, context, size, volume_type_id, optional_args):
         try:
             reserve_opts = {'volumes': 1, 'gigabytes': size}
             QUOTAS.add_volume_type_opts(context, reserve_opts, volume_type_id)
@@ -533,11 +534,12 @@ class QuotaReserveTask(flow_utils.CinderTask):
                 # If nothing was reraised, ensure we reraise the initial error
                 raise
 
-    def revert(self, context, result, **kwargs):
+    def revert(self, context, result, optional_args, **kwargs):
         # We never produced a result and therefore can't destroy anything.
         if isinstance(result, misc.Failure):
             return
-        if context.quota_committed:
+
+        if optional_args['is_quota_committed']:
             # The reservations have already been committed and can not be
             # rolled back at this point.
             return
@@ -571,9 +573,11 @@ class QuotaCommitTask(flow_utils.CinderTask):
     def __init__(self):
         super(QuotaCommitTask, self).__init__(addons=[ACTION])
 
-    def execute(self, context, reservations, volume_properties):
+    def execute(self, context, reservations, volume_properties,
+                optional_args):
         QUOTAS.commit(context, reservations)
-        context.quota_committed = True
+        # updating is_quota_committed attribute of optional_args dictionary
+        optional_args['is_quota_committed'] = True
         return {'volume_properties': volume_properties}
 
     def revert(self, context, result, **kwargs):