Skip to content

Commit 2c0cb71

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Avoid logging traceback when detach device not found"
2 parents 366ddcd + 738774b commit 2c0cb71

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

nova/tests/unit/virt/libvirt/test_guest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ def test_detach_device_with_retry_operation_failed(self, mock_detach):
327327
inc_sleep_time=.01, max_retry_count=3)
328328
# Some time later, we can do the wait/retry to ensure detach
329329
self.assertRaises(exception.DeviceNotFound, retry_detach)
330+
# Check that the save_and_reraise_exception context manager didn't log
331+
# a traceback when the libvirtError was caught and DeviceNotFound was
332+
# raised.
333+
self.assertNotIn('Original exception being dropped',
334+
self.stdlog.logger.output)
330335

331336
@mock.patch.object(libvirt_guest.Guest, "detach_device")
332337
def test_detach_device_with_retry_operation_internal(self, mock_detach):

nova/virt/libvirt/guest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _try_detach_device(conf, persistent=False, live=False):
403403
device, persistent, live)
404404

405405
except libvirt.libvirtError as ex:
406-
with excutils.save_and_reraise_exception():
406+
with excutils.save_and_reraise_exception(reraise=False) as ctx:
407407
errcode = ex.get_error_code()
408408
if errcode in (libvirt.VIR_ERR_OPERATION_FAILED,
409409
libvirt.VIR_ERR_INTERNAL_ERROR):
@@ -420,6 +420,10 @@ def _try_detach_device(conf, persistent=False, live=False):
420420
# detach fails because the device is not found
421421
raise exception.DeviceNotFound(
422422
device=alternative_device_name)
423+
# Re-raise the original exception if we're not raising
424+
# DeviceNotFound instead. This will avoid logging of a
425+
# "Original exception being dropped" traceback.
426+
ctx.reraise = True
423427

424428
conf = get_device_conf_func(device)
425429
if conf is None:

0 commit comments

Comments
 (0)