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)
tags/18.2.1
Lee Yarwood 2 months ago
parent
commit
34b4220448
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

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

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

@@ -1468,11 +1468,15 @@ class LibvirtDriver(driver.ComputeDriver):
1468 1468
         # distributions provide Libvirt 3.3.0 or earlier with
1469 1469
         # https://libvirt.org/git/?p=libvirt.git;a=commit;h=7189099 applied.
1470 1470
         except libvirt.libvirtError as ex:
1471
-            if 'Incorrect number of padding bytes' in six.text_type(ex):
1472
-                LOG.warning(_('Failed to attach encrypted volume due to a '
1473
-                    'known Libvirt issue, see the following bug for details: '
1474
-                    'https://bugzilla.redhat.com/show_bug.cgi?id=1447297'))
1475
-                raise
1471
+            with excutils.save_and_reraise_exception():
1472
+                if 'Incorrect number of padding bytes' in six.text_type(ex):
1473
+                    LOG.warning(_('Failed to attach encrypted volume due to a '
1474
+                                  'known Libvirt issue, see the following bug '
1475
+                                  'for details: '
1476
+                                  'https://bugzilla.redhat.com/1447297'))
1477
+                else:
1478
+                    LOG.exception(_('Failed to attach volume at mountpoint: '
1479
+                                    '%s'), mountpoint, instance=instance)
1476 1480
         except Exception:
1477 1481
             LOG.exception(_('Failed to attach volume at mountpoint: %s'),
1478 1482
                           mountpoint, instance=instance)

Loading…
Cancel
Save