diff options
-rw-r--r-- | nova/tests/unit/virt/libvirt/test_driver.py | 10 | ||||
-rw-r--r-- | nova/virt/libvirt/driver.py | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 5cafb59234..d4512ee3f0 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -7281,11 +7281,13 @@ class LibvirtConnTestCase(test.NoDBTestCase, mock.patch.object(drvr._host, 'get_guest'), mock.patch('nova.virt.libvirt.driver.LOG'), mock.patch.object(drvr, '_connect_volume'), + mock.patch.object(drvr, '_disconnect_volume'), mock.patch.object(drvr, '_get_volume_config'), mock.patch.object(drvr, '_check_discard_for_attach_volume'), mock.patch.object(drvr, '_build_device_metadata'), ) as (mock_get_guest, mock_log, mock_connect_volume, - mock_get_volume_config, mock_check_discard, mock_build_metadata): + mock_disconnect_volume, mock_get_volume_config, + mock_check_discard, mock_build_metadata): mock_conf = mock.MagicMock() mock_guest = mock.MagicMock() @@ -7299,6 +7301,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.context, connection_info, instance, "/dev/vdb", disk_bus=bdm['disk_bus'], device_type=bdm['device_type']) mock_log.warning.assert_called_once() + mock_disconnect_volume.assert_called_once() @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm') def test_attach_volume_with_libvirt_exception(self, mock_get_info): @@ -7320,11 +7323,13 @@ class LibvirtConnTestCase(test.NoDBTestCase, mock.patch.object(drvr._host, 'get_guest'), mock.patch('nova.virt.libvirt.driver.LOG'), mock.patch.object(drvr, '_connect_volume'), + mock.patch.object(drvr, '_disconnect_volume'), mock.patch.object(drvr, '_get_volume_config'), mock.patch.object(drvr, '_check_discard_for_attach_volume'), mock.patch.object(drvr, '_build_device_metadata'), ) as (mock_get_guest, mock_log, mock_connect_volume, - mock_get_volume_config, mock_check_discard, mock_build_metadata): + mock_disconnect_volume, mock_get_volume_config, + mock_check_discard, mock_build_metadata): mock_conf = mock.MagicMock() mock_guest = mock.MagicMock() @@ -7339,6 +7344,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, disk_bus=bdm['disk_bus'], device_type=bdm['device_type']) mock_log.exception.assert_called_once_with(u'Failed to attach ' 'volume at mountpoint: %s', '/dev/vdb', instance=instance) + mock_disconnect_volume.assert_called_once() @mock.patch('nova.utils.get_image_from_system_metadata') @mock.patch('nova.virt.libvirt.blockinfo.get_info_from_bdm') diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 42f6ec83d2..44cdc7d53a 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1499,6 +1499,8 @@ class LibvirtDriver(driver.ComputeDriver): else: LOG.exception(_('Failed to attach volume at mountpoint: ' '%s'), mountpoint, instance=instance) + self._disconnect_volume(context, connection_info, instance, + encryption=encryption) except Exception: LOG.exception(_('Failed to attach volume at mountpoint: %s'), mountpoint, instance=instance) |