Avoid logging traceback when detach device not found
We use the oslo.utils save_and_reraise_exception context manager in our detach device code and catch specific exceptions that mean 'not found' and raise DeviceNotFound instead. When we do that, the save_and_reraise_exception context manager logs an ERROR traceback of the original exception, for informational purposes. This is misleading when trying to debug other issues, as it makes it look like the caught exception caused a problem. This passes the reraise=False keyword arg to the context manager and sets the 'reraise' attribute to True only if we are not going to raise a different exception. Related-Bug: #1836212 Change-Id: Icce1e31fe3ebcbf9e4897bbfa57b7f3d1fba67a3 (cherry picked from commit738774b942
) (cherry picked from commitd833422264
)
This commit is contained in:
parent
9c6d900486
commit
3a1be7afd0
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue