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
changes/96/655696/2
Lee Yarwood 2 months ago
parent
commit
bc57ae5073
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

@@ -7794,6 +7794,46 @@ class LibvirtConnTestCase(test.NoDBTestCase,
7794 7794
                 disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
7795 7795
             mock_log.warning.assert_called_once()
7796 7796
 
7797
+    @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
7798
+    def test_attach_volume_with_libvirt_exception(self, mock_get_info):
7799
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7800
+        instance = objects.Instance(**self.test_instance)
7801
+        connection_info = {"driver_volume_type": "fake",
7802
+                           "data": {"device_path": "/fake",
7803
+                                    "access_mode": "rw"}}
7804
+        bdm = {'device_name': 'vdb',
7805
+               'disk_bus': 'fake-bus',
7806
+               'device_type': 'fake-type'}
7807
+        disk_info = {'bus': bdm['disk_bus'], 'type': bdm['device_type'],
7808
+                     'dev': 'vdb'}
7809
+        libvirt_exc = fakelibvirt.make_libvirtError(fakelibvirt.libvirtError,
7810
+            "Target vdb already exists', device is busy",
7811
+            error_code=fakelibvirt.VIR_ERR_INTERNAL_ERROR)
7812
+
7813
+        with test.nested(
7814
+            mock.patch.object(drvr._host, 'get_guest'),
7815
+            mock.patch('nova.virt.libvirt.driver.LOG'),
7816
+            mock.patch.object(drvr, '_connect_volume'),
7817
+            mock.patch.object(drvr, '_get_volume_config'),
7818
+            mock.patch.object(drvr, '_check_discard_for_attach_volume'),
7819
+            mock.patch.object(drvr, '_build_device_metadata'),
7820
+        ) as (mock_get_guest, mock_log, mock_connect_volume,
7821
+              mock_get_volume_config, mock_check_discard, mock_build_metadata):
7822
+
7823
+            mock_conf = mock.MagicMock()
7824
+            mock_guest = mock.MagicMock()
7825
+            mock_guest.attach_device.side_effect = libvirt_exc
7826
+            mock_get_volume_config.return_value = mock_conf
7827
+            mock_get_guest.return_value = mock_guest
7828
+            mock_get_info.return_value = disk_info
7829
+            mock_build_metadata.return_value = objects.InstanceDeviceMetadata()
7830
+
7831
+            self.assertRaises(fakelibvirt.libvirtError, drvr.attach_volume,
7832
+                self.context, connection_info, instance, "/dev/vdb",
7833
+                disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
7834
+            mock_log.exception.assert_called_once_with(u'Failed to attach '
7835
+                'volume at mountpoint: %s', '/dev/vdb', instance=instance)
7836
+
7797 7837
     @mock.patch('nova.utils.get_image_from_system_metadata')
7798 7838
     @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
7799 7839
     @mock.patch('nova.virt.libvirt.host.Host._get_domain')

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

@@ -1542,11 +1542,15 @@ class LibvirtDriver(driver.ComputeDriver):
1542 1542
         # distributions provide Libvirt 3.3.0 or earlier with
1543 1543
         # https://libvirt.org/git/?p=libvirt.git;a=commit;h=7189099 applied.
1544 1544
         except libvirt.libvirtError as ex:
1545
-            if 'Incorrect number of padding bytes' in six.text_type(ex):
1546
-                LOG.warning(_('Failed to attach encrypted volume due to a '
1547
-                    'known Libvirt issue, see the following bug for details: '
1548
-                    'https://bugzilla.redhat.com/show_bug.cgi?id=1447297'))
1549
-                raise
1545
+            with excutils.save_and_reraise_exception():
1546
+                if 'Incorrect number of padding bytes' in six.text_type(ex):
1547
+                    LOG.warning(_('Failed to attach encrypted volume due to a '
1548
+                                  'known Libvirt issue, see the following bug '
1549
+                                  'for details: '
1550
+                                  'https://bugzilla.redhat.com/1447297'))
1551
+                else:
1552
+                    LOG.exception(_('Failed to attach volume at mountpoint: '
1553
+                                    '%s'), mountpoint, instance=instance)
1550 1554
         except Exception:
1551 1555
             LOG.exception(_('Failed to attach volume at mountpoint: %s'),
1552 1556
                           mountpoint, instance=instance)

Loading…
Cancel
Save