Browse Source

libvirt: Stop ignoring unknown libvirtError exceptions during volume attach

Id346bce6e47431988cce7001abcf29a9faf2936a attempted to introduce a
simple breadcrumb in the logs to highlight a known Libvirt issue.
Unfortunately this change resulted in libvirtError exceptions that
didn't match the known issue being silently ignored.

This change corrects this by using excutils.save_and_reraise_exception
to ensure all libvirtError exceptions are logged and raised regardless
of being linked to the known issue.

Change-Id: Ib440f4f2e484312af5f393722363846f6c95b760
Closes-Bug: #1825882
(cherry picked from commit bc57ae5073)
(cherry picked from commit b3dedefcc5)
(cherry picked from commit 34b4220448)
tags/17.0.11
Lee Yarwood 2 months ago
parent
commit
63b45a87b8
2 changed files with 49 additions and 5 deletions
  1. 40
    0
      nova/tests/unit/virt/libvirt/test_driver.py
  2. 9
    5
      nova/virt/libvirt/driver.py

+ 40
- 0
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -7300,6 +7300,46 @@ class LibvirtConnTestCase(test.NoDBTestCase,
7300 7300
                 disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
7301 7301
             mock_log.warning.assert_called_once()
7302 7302
 
7303
+    @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
7304
+    def test_attach_volume_with_libvirt_exception(self, mock_get_info):
7305
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7306
+        instance = objects.Instance(**self.test_instance)
7307
+        connection_info = {"driver_volume_type": "fake",
7308
+                           "data": {"device_path": "/fake",
7309
+                                    "access_mode": "rw"}}
7310
+        bdm = {'device_name': 'vdb',
7311
+               'disk_bus': 'fake-bus',
7312
+               'device_type': 'fake-type'}
7313
+        disk_info = {'bus': bdm['disk_bus'], 'type': bdm['device_type'],
7314
+                     'dev': 'vdb'}
7315
+        libvirt_exc = fakelibvirt.make_libvirtError(fakelibvirt.libvirtError,
7316
+            "Target vdb already exists', device is busy",
7317
+            error_code=fakelibvirt.VIR_ERR_INTERNAL_ERROR)
7318
+
7319
+        with test.nested(
7320
+            mock.patch.object(drvr._host, 'get_guest'),
7321
+            mock.patch('nova.virt.libvirt.driver.LOG'),
7322
+            mock.patch.object(drvr, '_connect_volume'),
7323
+            mock.patch.object(drvr, '_get_volume_config'),
7324
+            mock.patch.object(drvr, '_check_discard_for_attach_volume'),
7325
+            mock.patch.object(drvr, '_build_device_metadata'),
7326
+        ) as (mock_get_guest, mock_log, mock_connect_volume,
7327
+              mock_get_volume_config, mock_check_discard, mock_build_metadata):
7328
+
7329
+            mock_conf = mock.MagicMock()
7330
+            mock_guest = mock.MagicMock()
7331
+            mock_guest.attach_device.side_effect = libvirt_exc
7332
+            mock_get_volume_config.return_value = mock_conf
7333
+            mock_get_guest.return_value = mock_guest
7334
+            mock_get_info.return_value = disk_info
7335
+            mock_build_metadata.return_value = objects.InstanceDeviceMetadata()
7336
+
7337
+            self.assertRaises(fakelibvirt.libvirtError, drvr.attach_volume,
7338
+                self.context, connection_info, instance, "/dev/vdb",
7339
+                disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
7340
+            mock_log.exception.assert_called_once_with(u'Failed to attach '
7341
+                'volume at mountpoint: %s', '/dev/vdb', instance=instance)
7342
+
7303 7343
     @mock.patch('nova.utils.get_image_from_system_metadata')
7304 7344
     @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
7305 7345
     @mock.patch('nova.virt.libvirt.host.Host._get_domain')

+ 9
- 5
nova/virt/libvirt/driver.py View File

@@ -1490,11 +1490,15 @@ class LibvirtDriver(driver.ComputeDriver):
1490 1490
         # distributions provide Libvirt 3.3.0 or earlier with
1491 1491
         # https://libvirt.org/git/?p=libvirt.git;a=commit;h=7189099 applied.
1492 1492
         except libvirt.libvirtError as ex:
1493
-            if 'Incorrect number of padding bytes' in six.text_type(ex):
1494
-                LOG.warning(_('Failed to attach encrypted volume due to a '
1495
-                    'known Libvirt issue, see the following bug for details: '
1496
-                    'https://bugzilla.redhat.com/show_bug.cgi?id=1447297'))
1497
-                raise
1493
+            with excutils.save_and_reraise_exception():
1494
+                if 'Incorrect number of padding bytes' in six.text_type(ex):
1495
+                    LOG.warning(_('Failed to attach encrypted volume due to a '
1496
+                                  'known Libvirt issue, see the following bug '
1497
+                                  'for details: '
1498
+                                  'https://bugzilla.redhat.com/1447297'))
1499
+                else:
1500
+                    LOG.exception(_('Failed to attach volume at mountpoint: '
1501
+                                    '%s'), mountpoint, instance=instance)
1498 1502
         except Exception:
1499 1503
             LOG.exception(_('Failed to attach volume at mountpoint: %s'),
1500 1504
                           mountpoint, instance=instance)

Loading…
Cancel
Save