From 971a63bd9cf675a00bce1244ec101577b5c17cac Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Tue, 10 Jun 2014 06:29:20 +0000 Subject: [PATCH] Made provision for providing optional arguments 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 | 1 - cinder/volume/api.py | 1 + cinder/volume/flows/api/create_volume.py | 20 ++++++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cinder/context.py b/cinder/context.py index e2a7f46e1..8ac896223 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -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 diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 2fd65bfea..8e4201ccb 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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: diff --git a/cinder/volume/flows/api/create_volume.py b/cinder/volume/flows/api/create_volume.py index 27603c0d3..8da603230 100644 --- a/cinder/volume/flows/api/create_volume.py +++ b/cinder/volume/flows/api/create_volume.py @@ -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): -- 2.45.2