diff --git a/nova/tests/unit/virt/libvirt/test_guest.py b/nova/tests/unit/virt/libvirt/test_guest.py index 7a275a95ebf8..250871a09ab4 100644 --- a/nova/tests/unit/virt/libvirt/test_guest.py +++ b/nova/tests/unit/virt/libvirt/test_guest.py @@ -325,6 +325,11 @@ class GuestTestCase(test.NoDBTestCase): inc_sleep_time=.01, max_retry_count=3) # Some time later, we can do the wait/retry to ensure detach self.assertRaises(exception.DeviceNotFound, retry_detach) + # Check that the save_and_reraise_exception context manager didn't log + # a traceback when the libvirtError was caught and DeviceNotFound was + # raised. + self.assertNotIn('Original exception being dropped', + self.stdlog.logger.output) @mock.patch.object(libvirt_guest.Guest, "detach_device") def test_detach_device_with_retry_operation_internal(self, mock_detach): diff --git a/nova/virt/libvirt/guest.py b/nova/virt/libvirt/guest.py index f2897aadf508..ef015ee8b9b8 100644 --- a/nova/virt/libvirt/guest.py +++ b/nova/virt/libvirt/guest.py @@ -404,7 +404,7 @@ class Guest(object): device, persistent, live) except libvirt.libvirtError as ex: - with excutils.save_and_reraise_exception(): + with excutils.save_and_reraise_exception(reraise=False) as ctx: errcode = ex.get_error_code() if errcode in (libvirt.VIR_ERR_OPERATION_FAILED, libvirt.VIR_ERR_INTERNAL_ERROR): @@ -421,6 +421,10 @@ class Guest(object): # detach fails because the device is not found raise exception.DeviceNotFound( device=alternative_device_name) + # Re-raise the original exception if we're not raising + # DeviceNotFound instead. This will avoid logging of a + # "Original exception being dropped" traceback. + ctx.reraise = True conf = get_device_conf_func(device) if conf is None: