Merge "Silently continue when disconnecting missing vhds"
This commit is contained in:
commit
1ceb2bcaf5
|
@ -817,23 +817,30 @@ class VHDUtilsTestCase(test_base.BaseTestCase):
|
|||
bool(attach_flag &
|
||||
w_const.ATTACH_VIRTUAL_DISK_FLAG_PERMANENT_LIFETIME))
|
||||
|
||||
@ddt.data(True, False)
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch.object(vhdutils.VHDUtils, '_open')
|
||||
def test_detach_virtual_disk(self, mock_open):
|
||||
def test_detach_virtual_disk(self, exists, mock_open, mock_exists):
|
||||
mock_exists.return_value = exists
|
||||
self._mock_run.return_value = w_const.ERROR_NOT_READY
|
||||
|
||||
self._vhdutils.detach_virtual_disk(mock.sentinel.vhd_path)
|
||||
|
||||
mock_open.assert_called_once_with(
|
||||
mock.sentinel.vhd_path,
|
||||
open_access_mask=w_const.VIRTUAL_DISK_ACCESS_DETACH)
|
||||
mock_exists.assert_called_once_with(mock.sentinel.vhd_path)
|
||||
if exists:
|
||||
mock_open.assert_called_once_with(
|
||||
mock.sentinel.vhd_path,
|
||||
open_access_mask=w_const.VIRTUAL_DISK_ACCESS_DETACH)
|
||||
|
||||
self._mock_run.assert_called_once_with(
|
||||
vhdutils.virtdisk.DetachVirtualDisk,
|
||||
mock_open.return_value,
|
||||
0, 0,
|
||||
ignored_error_codes=[w_const.ERROR_NOT_READY],
|
||||
**self._run_args)
|
||||
self._mock_close.assert_called_once_with(mock_open.return_value)
|
||||
self._mock_run.assert_called_once_with(
|
||||
vhdutils.virtdisk.DetachVirtualDisk,
|
||||
mock_open.return_value,
|
||||
0, 0,
|
||||
ignored_error_codes=[w_const.ERROR_NOT_READY],
|
||||
**self._run_args)
|
||||
self._mock_close.assert_called_once_with(mock_open.return_value)
|
||||
else:
|
||||
mock_open.assert_not_called()
|
||||
|
||||
@mock.patch.object(vhdutils.VHDUtils, '_open')
|
||||
def test_get_virtual_disk_physical_path(self, mock_open):
|
||||
|
|
|
@ -589,6 +589,11 @@ class VHDUtils(object):
|
|||
return handle
|
||||
|
||||
def detach_virtual_disk(self, vhd_path):
|
||||
if not os.path.exists(vhd_path):
|
||||
LOG.debug("Image %s could not be found. Skipping detach.",
|
||||
vhd_path)
|
||||
return
|
||||
|
||||
open_access_mask = w_const.VIRTUAL_DISK_ACCESS_DETACH
|
||||
handle = self._open(vhd_path, open_access_mask=open_access_mask)
|
||||
|
||||
|
|
Loading…
Reference in New Issue