From 24cfd0d6f2667d65f81b43fc76af71fd33b78de7 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Sat, 4 Aug 2012 00:37:05 -0400 Subject: Remove temporary hack from wrap_instance_fault. The wrap_instance_fault decorator had a temporary hack in place while methods in the compute manager were being converted to be able to take an instance instead of an instance_uuid. Now that it's done, the decorator can be simplified. Part of blueprint no-db-messaging. Change-Id: I496d58137ef720ff31acc70a2b7acc670a088ce6 --- nova/compute/manager.py | 46 +++++++++----------------------------- nova/tests/compute/test_compute.py | 2 +- 2 files changed, 11 insertions(+), 37 deletions(-) (limited to 'nova') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index deb664170..d8c021a52 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -219,49 +219,23 @@ def wrap_instance_fault(function): an instance that may get thrown. It then logs an instance fault in the db. """ - # NOTE(russellb): There are two versions of the wrap_instance_fault - # decorator. This function is the core code for it. This just serves - # as a transition from when every function expected a context - # and instance_uuid as positional arguments to where everything is a kwarg, - # and the function may get either an instance_uuid or an instance. - def _wrap_instance_fault_core(self, cb, context, *args, **kwargs): + @functools.wraps(function) + def decorated_function(self, context, *args, **kwargs): try: - return cb(self, context, *args, **kwargs) + return function(self, context, *args, **kwargs) except exception.InstanceNotFound: raise except Exception, e: with excutils.save_and_reraise_exception(): + instance = kwargs.get('instance', None) + if instance: + instance_uuid = instance['uuid'] + else: + instance_uuid = kwargs['instance_uuid'] self._add_instance_fault_from_exc(context, - kwargs['instance_uuid'], e, sys.exc_info()) - - @functools.wraps(function) - def decorated_function(self, context, instance_uuid, *args, **kwargs): - - def _cb(self, context, *args, **kwargs): - instance_uuid = kwargs.pop('instance_uuid') - return function(self, context, instance_uuid, *args, **kwargs) - - kwargs['instance_uuid'] = instance_uuid - - return _wrap_instance_fault_core(self, _cb, context, *args, **kwargs) + instance_uuid, e, sys.exc_info()) - @functools.wraps(function) - def decorated_function_new(self, context, *args, **kwargs): - if 'instance_uuid' not in kwargs: - kwargs['instance_uuid'] = kwargs['instance']['uuid'] - - def _cb(self, context, *args, **kwargs): - return function(self, context, *args, **kwargs) - - return _wrap_instance_fault_core(self, _cb, context, *args, **kwargs) - - expected_args = ['context', 'instance_uuid'] - argspec = inspect.getargspec(function) - - if expected_args == argspec.args[1:len(expected_args) + 1]: - return decorated_function - else: - return decorated_function_new + return decorated_function def _get_image_meta(context, image_ref): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 387c2c1cc..0b0316e26 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -234,7 +234,7 @@ class ComputeTestCase(BaseTestCase): raise NotImplementedError() self.assertRaises(NotImplementedError, failer, - self.compute, self.context, inst_uuid) + self.compute, self.context, instance_uuid=inst_uuid) self.assertTrue(called['fault_added']) -- cgit