Merge "Avoid logging traceback when detach device not found" into stable/rocky

This commit is contained in:
Zuul 2019-08-08 16:19:47 +00:00 committed by Gerrit Code Review
commit 7efda0632d
2 changed files with 10 additions and 1 deletions

View File

@ -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):

View File

@ -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: