Browse Source

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

tags/18.2.2
Zuul 1 month ago
parent
commit
7efda0632d
2 changed files with 10 additions and 1 deletions
  1. 5
    0
      nova/tests/unit/virt/libvirt/test_guest.py
  2. 5
    1
      nova/virt/libvirt/guest.py

+ 5
- 0
nova/tests/unit/virt/libvirt/test_guest.py View File

@@ -325,6 +325,11 @@ class GuestTestCase(test.NoDBTestCase):
325 325
             inc_sleep_time=.01, max_retry_count=3)
326 326
         # Some time later, we can do the wait/retry to ensure detach
327 327
         self.assertRaises(exception.DeviceNotFound, retry_detach)
328
+        # Check that the save_and_reraise_exception context manager didn't log
329
+        # a traceback when the libvirtError was caught and DeviceNotFound was
330
+        # raised.
331
+        self.assertNotIn('Original exception being dropped',
332
+                         self.stdlog.logger.output)
328 333
 
329 334
     @mock.patch.object(libvirt_guest.Guest, "detach_device")
330 335
     def test_detach_device_with_retry_operation_internal(self, mock_detach):

+ 5
- 1
nova/virt/libvirt/guest.py View File

@@ -404,7 +404,7 @@ class Guest(object):
404 404
                               device, persistent, live)
405 405
 
406 406
             except libvirt.libvirtError as ex:
407
-                with excutils.save_and_reraise_exception():
407
+                with excutils.save_and_reraise_exception(reraise=False) as ctx:
408 408
                     errcode = ex.get_error_code()
409 409
                     if errcode in (libvirt.VIR_ERR_OPERATION_FAILED,
410 410
                                    libvirt.VIR_ERR_INTERNAL_ERROR):
@@ -421,6 +421,10 @@ class Guest(object):
421 421
                             # detach fails because the device is not found
422 422
                             raise exception.DeviceNotFound(
423 423
                                 device=alternative_device_name)
424
+                    # Re-raise the original exception if we're not raising
425
+                    # DeviceNotFound instead. This will avoid logging of a
426
+                    # "Original exception being dropped" traceback.
427
+                    ctx.reraise = True
424 428
 
425 429
         conf = get_device_conf_func(device)
426 430
         if conf is None:

Loading…
Cancel
Save