Merge "Mock qemu calls in sheepdog tests"
This commit is contained in:
commit
ceda07c0fc
@ -1195,14 +1195,11 @@ class SheepdogDriverTestCase(test.TestCase):
|
|||||||
fake_context = {}
|
fake_context = {}
|
||||||
fake_volume = {'name': 'volume-00000001'}
|
fake_volume = {'name': 'volume-00000001'}
|
||||||
fake_image_service = mock.Mock()
|
fake_image_service = mock.Mock()
|
||||||
fake_image_service_update = mock.Mock()
|
|
||||||
fake_image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
|
fake_image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
|
||||||
temp_file = mock_temp.return_value.__enter__.return_value
|
temp_file = mock_temp.return_value.__enter__.return_value
|
||||||
|
|
||||||
patch = mock.patch.object
|
patch = mock.patch.object
|
||||||
with patch(self.driver, '_try_execute') as fake_try_execute:
|
with patch(self.driver, '_try_execute') as fake_try_execute:
|
||||||
with patch(fake_image_service,
|
|
||||||
'update') as fake_image_service_update:
|
|
||||||
self.driver.copy_volume_to_image(fake_context,
|
self.driver.copy_volume_to_image(fake_context,
|
||||||
fake_volume,
|
fake_volume,
|
||||||
fake_image_service,
|
fake_image_service,
|
||||||
@ -1220,26 +1217,44 @@ class SheepdogDriverTestCase(test.TestCase):
|
|||||||
mock.ANY)
|
mock.ANY)
|
||||||
mock_open.assert_called_once_with(temp_file, 'rb')
|
mock_open.assert_called_once_with(temp_file, 'rb')
|
||||||
fake_try_execute.assert_called_once_with(*expected_cmd)
|
fake_try_execute.assert_called_once_with(*expected_cmd)
|
||||||
fake_image_service_update.assert_called_once_with(
|
fake_image_service.update.assert_called_once_with(
|
||||||
fake_context, fake_image_meta['id'], mock.ANY, mock.ANY)
|
fake_context, fake_image_meta['id'], mock.ANY, mock.ANY)
|
||||||
|
|
||||||
@mock.patch('os.makedirs')
|
@mock.patch('six.moves.builtins.open')
|
||||||
def test_copy_volume_to_image_nonexistent_volume(self, mock_make):
|
@mock.patch('cinder.image.image_utils.temporary_file')
|
||||||
|
def test_copy_volume_to_image_nonexistent_volume(self, mock_temp,
|
||||||
|
mock_open):
|
||||||
fake_context = {}
|
fake_context = {}
|
||||||
fake_volume = {
|
fake_volume = {
|
||||||
'name': 'nonexistent-volume-82c4539e-c2a5-11e4-a293-0aa186c60fe0'}
|
'name': 'nonexistent-volume-82c4539e-c2a5-11e4-a293-0aa186c60fe0'}
|
||||||
fake_image_service = mock.Mock()
|
fake_image_service = mock.Mock()
|
||||||
fake_image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
|
fake_image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
|
||||||
|
|
||||||
# The command is expected to fail, so we don't want to retry it.
|
patch = mock.patch.object
|
||||||
self.driver._try_execute = self.driver._execute
|
with patch(self.driver, '_try_execute') as fake_try_execute:
|
||||||
|
fake_try_execute.side_effect = (
|
||||||
|
processutils.ProcessExecutionError)
|
||||||
|
args = (fake_context, fake_volume, fake_image_service,
|
||||||
|
fake_image_meta)
|
||||||
|
expected_cmd = ('qemu-img',
|
||||||
|
'convert',
|
||||||
|
'-f', 'raw',
|
||||||
|
'-t', 'none',
|
||||||
|
'-O', 'raw',
|
||||||
|
'sheepdog:%s:%s:%s' % (
|
||||||
|
self._addr,
|
||||||
|
self._port,
|
||||||
|
fake_volume['name']),
|
||||||
|
mock.ANY)
|
||||||
|
|
||||||
args = (fake_context, fake_volume, fake_image_service, fake_image_meta)
|
self.assertRaises(processutils.ProcessExecutionError,
|
||||||
expected_errors = (processutils.ProcessExecutionError, OSError)
|
|
||||||
self.assertRaises(expected_errors,
|
|
||||||
self.driver.copy_volume_to_image,
|
self.driver.copy_volume_to_image,
|
||||||
*args)
|
*args)
|
||||||
|
|
||||||
|
fake_try_execute.assert_called_once_with(*expected_cmd)
|
||||||
|
mock_open.assert_not_called()
|
||||||
|
fake_image_service.update.assert_not_called()
|
||||||
|
|
||||||
@mock.patch.object(sheepdog.SheepdogClient, 'create_snapshot')
|
@mock.patch.object(sheepdog.SheepdogClient, 'create_snapshot')
|
||||||
@mock.patch.object(sheepdog.SheepdogClient, 'clone')
|
@mock.patch.object(sheepdog.SheepdogClient, 'clone')
|
||||||
@mock.patch.object(sheepdog.SheepdogClient, 'delete_snapshot')
|
@mock.patch.object(sheepdog.SheepdogClient, 'delete_snapshot')
|
||||||
|
Loading…
Reference in New Issue
Block a user