@utils.expects_func_args('instance')
def reverts_task_state(function):
 @functools.wraps(function)
 def decorated_function(self, context, *args, **kwargs):
  try:
   return function(self, context, *args, **kwargs)
  except exception.UnexpectedTaskStateError as e:
   with excutils.save_and_reraise_exception():
    LOG.info(_LI('Task possibly preempted: %s'), e.format_message())
  except Exception:
   with excutils.save_and_reraise_exception():
    wrapped_func = safe_utils.get_wrapped_function(function)
    keyed_args = inspect.getcallargs(wrapped_func, self, context, *args, **kwargs)
    instance = keyed_args['instance']
    original_task_state = instance.task_state
    try:
     self._instance_update(context, instance, task_state=None)
     LOG.info(_LI('Successfully reverted task state from %s on failure for instance.'), original_task_state, instance=instance)
    except exception.InstanceNotFound:
     pass
    except Exception as e:
     msg = _LW('Failed to revert task state for instance. Error: %s')
     LOG.warning(msg, e, instance=instance)
 return decorated_function

@ utils . expects_func_args ( 'instance' ) def reverts_task_state ( function ) : @ functools . wraps ( function ) def decorated_function ( self , context , * args , ** kwargs ) : try : return function ( self , context , * args , ** kwargs ) except exception . UnexpectedTaskStateError as e : with excutils . save_and_reraise_exception ( ) : LOG . info ( _LI ( 'Task possibly preempted: %s' ) , e . format_message ( ) ) except Exception : with excutils . save_and_reraise_exception ( ) : wrapped_func = safe_utils . get_wrapped_function ( function ) keyed_args = inspect . getcallargs ( wrapped_func , self , context , * args , ** kwargs ) instance = keyed_args [ 'instance' ] original_task_state = instance . task_state try : self . _instance_update ( context , instance , task_state = None ) LOG . info ( _LI ( 'Successfully reverted task state from %s on failure for instance.' ) , original_task_state , instance = instance ) except exception . InstanceNotFound : pass except Exception as e : msg = _LW ( 'Failed to revert task state for instance. Error: %s' ) LOG . warning ( msg , e , instance = instance ) return decorated_function
decorator to revert task_state on failure .