Skip to content

Commit 786083c

Browse files
committed
libvirt: Always disconnect volumes after libvirtError exceptions
Building on Ib440f4f2e484312af5f393722363846f6c95b760 we should always attempt to disconnect volumes from the host when exceptions are thrown while attempting to attach a volume to a domain. This was previously done for generic exceptions but not for libvirtError exceptions. Closes-Bug: #1826523 Change-Id: If21230869826c992e7d0398434b9a4b255940213 (cherry picked from commit 091a910) (cherry picked from commit 048d5b7)
1 parent 34b4220 commit 786083c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7759,11 +7759,13 @@ def test_attach_volume_with_libvirt_bug_breadcrumb(self, mock_get_info):
77597759
mock.patch.object(drvr._host, 'get_guest'),
77607760
mock.patch('nova.virt.libvirt.driver.LOG'),
77617761
mock.patch.object(drvr, '_connect_volume'),
7762+
mock.patch.object(drvr, '_disconnect_volume'),
77627763
mock.patch.object(drvr, '_get_volume_config'),
77637764
mock.patch.object(drvr, '_check_discard_for_attach_volume'),
77647765
mock.patch.object(drvr, '_build_device_metadata'),
77657766
) as (mock_get_guest, mock_log, mock_connect_volume,
7766-
mock_get_volume_config, mock_check_discard, mock_build_metadata):
7767+
mock_disconnect_volume, mock_get_volume_config,
7768+
mock_check_discard, mock_build_metadata):
77677769

77687770
mock_conf = mock.MagicMock()
77697771
mock_guest = mock.MagicMock()
@@ -7777,6 +7779,7 @@ def test_attach_volume_with_libvirt_bug_breadcrumb(self, mock_get_info):
77777779
self.context, connection_info, instance, "/dev/vdb",
77787780
disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
77797781
mock_log.warning.assert_called_once()
7782+
mock_disconnect_volume.assert_called_once()
77807783

77817784
@mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')
77827785
def test_attach_volume_with_libvirt_exception(self, mock_get_info):
@@ -7798,11 +7801,13 @@ def test_attach_volume_with_libvirt_exception(self, mock_get_info):
77987801
mock.patch.object(drvr._host, 'get_guest'),
77997802
mock.patch('nova.virt.libvirt.driver.LOG'),
78007803
mock.patch.object(drvr, '_connect_volume'),
7804+
mock.patch.object(drvr, '_disconnect_volume'),
78017805
mock.patch.object(drvr, '_get_volume_config'),
78027806
mock.patch.object(drvr, '_check_discard_for_attach_volume'),
78037807
mock.patch.object(drvr, '_build_device_metadata'),
78047808
) as (mock_get_guest, mock_log, mock_connect_volume,
7805-
mock_get_volume_config, mock_check_discard, mock_build_metadata):
7809+
mock_disconnect_volume, mock_get_volume_config,
7810+
mock_check_discard, mock_build_metadata):
78067811

78077812
mock_conf = mock.MagicMock()
78087813
mock_guest = mock.MagicMock()
@@ -7817,6 +7822,7 @@ def test_attach_volume_with_libvirt_exception(self, mock_get_info):
78177822
disk_bus=bdm['disk_bus'], device_type=bdm['device_type'])
78187823
mock_log.exception.assert_called_once_with(u'Failed to attach '
78197824
'volume at mountpoint: %s', '/dev/vdb', instance=instance)
7825+
mock_disconnect_volume.assert_called_once()
78207826

78217827
@mock.patch('nova.utils.get_image_from_system_metadata')
78227828
@mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm')

nova/virt/libvirt/driver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ def attach_volume(self, context, connection_info, instance, mountpoint,
14771477
else:
14781478
LOG.exception(_('Failed to attach volume at mountpoint: '
14791479
'%s'), mountpoint, instance=instance)
1480+
self._disconnect_volume(context, connection_info, instance,
1481+
encryption=encryption)
14801482
except Exception:
14811483
LOG.exception(_('Failed to attach volume at mountpoint: %s'),
14821484
mountpoint, instance=instance)

0 commit comments

Comments
 (0)