diff options
-rw-r--r-- | nova/compute/manager.py | 22 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 47 |
2 files changed, 44 insertions, 25 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 9e7e0e1fb..7ac6b1518 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -629,8 +629,9 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.exception(msg, instance=instance) raise except Exception: + exc_info = sys.exc_info() # try to re-schedule instance: - self._reschedule_or_reraise(context, instance, + self._reschedule_or_reraise(context, instance, exc_info, requested_networks, admin_password, injected_files, is_first_time, request_spec, filter_properties) else: @@ -652,16 +653,18 @@ class ComputeManager(manager.SchedulerDependentManager): traceback.format_exception(type_, value, tb), instance_uuid=instance_uuid) - def _reschedule_or_reraise(self, context, instance, requested_networks, - admin_password, injected_files, is_first_time, - request_spec, filter_properties): + def _reschedule_or_reraise(self, context, instance, exc_info, + requested_networks, admin_password, injected_files, is_first_time, + request_spec, filter_properties): """Try to re-schedule the build or re-raise the original build error to error out the instance. """ - exc_info = sys.exc_info() instance_uuid = instance['uuid'] rescheduled = False + compute_utils.add_instance_fault_from_exc(context, instance_uuid, + exc_info[0], exc_info=exc_info) + try: self._deallocate_network(context, instance) except Exception: @@ -1850,8 +1853,9 @@ class ComputeManager(manager.SchedulerDependentManager): reservations, request_spec, filter_properties, node) except Exception: # try to re-schedule the resize elsewhere: + exc_info = sys.exc_info() self._reschedule_resize_or_reraise(context, image, instance, - instance_type, reservations, request_spec, + exc_info, instance_type, reservations, request_spec, filter_properties) finally: extra_usage_info = dict( @@ -1862,7 +1866,7 @@ class ComputeManager(manager.SchedulerDependentManager): context, instance, "resize.prep.end", extra_usage_info=extra_usage_info) - def _reschedule_resize_or_reraise(self, context, image, instance, + def _reschedule_resize_or_reraise(self, context, image, instance, exc_info, instance_type, reservations, request_spec, filter_properties): """Try to re-schedule the resize or re-raise the original error to error out the instance. @@ -1872,10 +1876,12 @@ class ComputeManager(manager.SchedulerDependentManager): if not filter_properties: filter_properties = {} - exc_info = sys.exc_info() rescheduled = False instance_uuid = instance['uuid'] + compute_utils.add_instance_fault_from_exc(context, instance_uuid, + exc_info[0], exc_info=exc_info) + try: scheduler_method = self.scheduler_rpcapi.prep_resize method_args = (instance, instance_type, image, request_spec, diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 57c234734..3bd54cbba 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -6043,7 +6043,7 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): self.compute._spawn(mox.IgnoreArg(), self.instance, None, None, None, False, None).AndRaise(test.TestingException("BuildError")) self.compute._reschedule_or_reraise(mox.IgnoreArg(), self.instance, - None, None, None, False, None, {}) + mox.IgnoreArg(), None, None, None, False, None, {}) self.mox.ReplayAll() self.compute._run_instance(self.context, None, {}, None, None, None, @@ -6061,6 +6061,8 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): except Exception: exc_info = sys.exc_info() + compute_utils.add_instance_fault_from_exc(self.context, + instance_uuid, exc_info[0], exc_info=exc_info) self.compute._deallocate_network(self.context, self.instance).AndRaise(InnerTestingException("Error")) self.compute._log_original_error(exc_info, instance_uuid) @@ -6071,7 +6073,7 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): # error: self.assertRaises(InnerTestingException, self.compute._reschedule_or_reraise, self.context, - self.instance, None, None, None, False, None, {}) + self.instance, exc_info, None, None, None, False, None, {}) def test_reschedule_fail(self): """Test handling of exception from _reschedule""" @@ -6093,9 +6095,10 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): raise test.TestingException("Original") except Exception: # not re-scheduling, should raise the original build error: + exc_info = sys.exc_info() self.assertRaises(test.TestingException, self.compute._reschedule_or_reraise, self.context, - self.instance, None, None, None, False, None, {}) + self.instance, exc_info, None, None, None, False, None, {}) def test_reschedule_false(self): """Test not-rescheduling, but no nested exception""" @@ -6104,22 +6107,25 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute, '_deallocate_network') self.mox.StubOutWithMock(self.compute, '_reschedule') - self.compute._deallocate_network(self.context, - self.instance) - self.compute._reschedule(self.context, None, instance_uuid, - {}, self.compute.scheduler_rpcapi.run_instance, method_args, - task_states.SCHEDULING).AndReturn(False) - - self.mox.ReplayAll() - try: raise test.TestingException("Original") except Exception: + exc_info = sys.exc_info() + compute_utils.add_instance_fault_from_exc(self.context, + instance_uuid, exc_info[0], exc_info=exc_info) + self.compute._deallocate_network(self.context, + self.instance) + self.compute._reschedule(self.context, None, {}, instance_uuid, + self.compute.scheduler_rpcapi.run_instance, method_args, + task_states.SCHEDULING, exc_info).AndReturn(False) + + self.mox.ReplayAll() + # re-scheduling is False, the original build error should be # raised here: self.assertRaises(test.TestingException, self.compute._reschedule_or_reraise, self.context, - self.instance, None, None, None, False, None, {}) + self.instance, exc_info, None, None, None, False, None, {}) def test_reschedule_true(self): """Test behavior when re-scheduling happens""" @@ -6133,6 +6139,8 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): except Exception: exc_info = sys.exc_info() + compute_utils.add_instance_fault_from_exc(self.context, + instance_uuid, exc_info[0], exc_info=exc_info) self.compute._deallocate_network(self.context, self.instance) self.compute._reschedule(self.context, None, {}, instance_uuid, @@ -6146,7 +6154,7 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): # re-scheduling is True, original error is logged, but nothing # is raised: self.compute._reschedule_or_reraise(self.context, self.instance, - None, None, None, False, None, {}) + exc_info, None, None, None, False, None, {}) class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): @@ -6171,7 +6179,8 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): mox.IgnoreArg()).AndRaise(test.TestingException("Original")) self.compute._reschedule_resize_or_reraise(mox.IgnoreArg(), None, - self.instance, self.instance_type, None, None, None) + self.instance, mox.IgnoreArg(), self.instance_type, None, None, + None) self.mox.ReplayAll() @@ -6195,9 +6204,11 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): try: raise test.TestingException("Original") except Exception: + exc_info = sys.exc_info() self.assertRaises(test.TestingException, self.compute._reschedule_resize_or_reraise, self.context, - None, self.instance, self.instance_type, None, {}, {}) + None, self.instance, exc_info, self.instance_type, None, + {}, {}) def test_reschedule_false(self): """Original exception should be raised if the resize is not @@ -6215,9 +6226,11 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): try: raise test.TestingException("Original") except Exception: + exc_info = sys.exc_info() self.assertRaises(test.TestingException, self.compute._reschedule_resize_or_reraise, self.context, - None, self.instance, self.instance_type, None, {}, {}) + None, self.instance, exc_info, self.instance_type, None, + {}, {}) def test_reschedule_true(self): """If rescheduled, the original resize exception should be logged""" @@ -6238,7 +6251,7 @@ class ComputeRescheduleResizeOrReraiseTestCase(BaseTestCase): self.mox.ReplayAll() self.compute._reschedule_resize_or_reraise(self.context, None, - self.instance, self.instance_type, None, {}, {}) + self.instance, exc_info, self.instance_type, None, {}, {}) class ComputeInactiveImageTestCase(BaseTestCase): |