Merge "Avoid logging traceback when detach device not found" into stable/rocky
This commit is contained in:
commit
7efda0632d
|
@ -325,6 +325,11 @@ class GuestTestCase(test.NoDBTestCase):
|
||||||
inc_sleep_time=.01, max_retry_count=3)
|
inc_sleep_time=.01, max_retry_count=3)
|
||||||
# Some time later, we can do the wait/retry to ensure detach
|
# Some time later, we can do the wait/retry to ensure detach
|
||||||
self.assertRaises(exception.DeviceNotFound, retry_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")
|
@mock.patch.object(libvirt_guest.Guest, "detach_device")
|
||||||
def test_detach_device_with_retry_operation_internal(self, mock_detach):
|
def test_detach_device_with_retry_operation_internal(self, mock_detach):
|
||||||
|
|
|
@ -404,7 +404,7 @@ class Guest(object):
|
||||||
device, persistent, live)
|
device, persistent, live)
|
||||||
|
|
||||||
except libvirt.libvirtError as ex:
|
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()
|
errcode = ex.get_error_code()
|
||||||
if errcode in (libvirt.VIR_ERR_OPERATION_FAILED,
|
if errcode in (libvirt.VIR_ERR_OPERATION_FAILED,
|
||||||
libvirt.VIR_ERR_INTERNAL_ERROR):
|
libvirt.VIR_ERR_INTERNAL_ERROR):
|
||||||
|
@ -421,6 +421,10 @@ class Guest(object):
|
||||||
# detach fails because the device is not found
|
# detach fails because the device is not found
|
||||||
raise exception.DeviceNotFound(
|
raise exception.DeviceNotFound(
|
||||||
device=alternative_device_name)
|
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)
|
conf = get_device_conf_func(device)
|
||||||
if conf is None:
|
if conf is None:
|
||||||
|
|
Loading…
Reference in New Issue