Merge "Tests: Clean up RBD image unit tests"
This commit is contained in:
commit
774d784aca
@ -1825,28 +1825,25 @@ class RBDTestCase(test.TestCase):
|
|||||||
self.assertTrue(mock_get_fsid.called)
|
self.assertTrue(mock_get_fsid.called)
|
||||||
|
|
||||||
def _copy_image(self, volume_busy=False):
|
def _copy_image(self, volume_busy=False):
|
||||||
with mock.patch.object(tempfile, 'NamedTemporaryFile'):
|
self.mock_object(tempfile, 'NamedTemporaryFile')
|
||||||
with mock.patch.object(os.path, 'exists') as mock_exists:
|
self.mock_object(os.path, 'exists', return_value=True)
|
||||||
mock_exists.return_value = True
|
self.mock_object(image_utils, 'fetch_to_raw')
|
||||||
with mock.patch.object(image_utils, 'fetch_to_raw'):
|
self.mock_object(self.driver, '_resize')
|
||||||
with mock.patch.object(self.driver, 'delete_volume') \
|
|
||||||
as mock_dv:
|
with mock.patch.object(self.driver, 'delete_volume') as mock_dv:
|
||||||
with mock.patch.object(self.driver, '_resize'):
|
mock_image_service = mock.MagicMock()
|
||||||
mock_image_service = mock.MagicMock()
|
args = [None, self.volume_a, mock_image_service, None]
|
||||||
args = [None, self.volume_a,
|
if volume_busy:
|
||||||
mock_image_service, None]
|
mock_dv.side_effect = exception.VolumeIsBusy("doh")
|
||||||
if volume_busy:
|
self.assertRaises(
|
||||||
mock_dv.side_effect = (
|
exception.VolumeIsBusy,
|
||||||
exception.VolumeIsBusy("doh"))
|
self.driver.copy_image_to_volume,
|
||||||
self.assertRaises(
|
*args)
|
||||||
exception.VolumeIsBusy,
|
self.assertEqual(
|
||||||
self.driver.copy_image_to_volume,
|
self.cfg.rados_connection_retries,
|
||||||
*args)
|
mock_dv.call_count)
|
||||||
self.assertEqual(
|
else:
|
||||||
self.cfg.rados_connection_retries,
|
self.driver.copy_image_to_volume(*args)
|
||||||
mock_dv.call_count)
|
|
||||||
else:
|
|
||||||
self.driver.copy_image_to_volume(*args)
|
|
||||||
|
|
||||||
@mock.patch('cinder.volume.drivers.rbd.fileutils.delete_if_exists')
|
@mock.patch('cinder.volume.drivers.rbd.fileutils.delete_if_exists')
|
||||||
@mock.patch('cinder.volume.volume_utils.check_encryption_provider',
|
@mock.patch('cinder.volume.volume_utils.check_encryption_provider',
|
||||||
@ -1862,24 +1859,24 @@ class RBDTestCase(test.TestCase):
|
|||||||
enc_info = {'encryption_key_id': key_id,
|
enc_info = {'encryption_key_id': key_id,
|
||||||
'cipher': 'aes-xts-essiv',
|
'cipher': 'aes-xts-essiv',
|
||||||
'key_size': 256}
|
'key_size': 256}
|
||||||
with mock.patch('cinder.volume.volume_utils.check_encryption_provider',
|
|
||||||
return_value=enc_info), \
|
self.mock_object(cinder.volume.volume_utils,
|
||||||
mock.patch('cinder.volume.drivers.rbd.open'), \
|
'check_encryption_provider',
|
||||||
mock.patch('os.rename'):
|
return_value=enc_info)
|
||||||
with mock.patch.object(tempfile, 'NamedTemporaryFile'):
|
self.mock_object(cinder.volume.drivers.rbd, 'open')
|
||||||
with mock.patch.object(os.path, 'exists') as mock_exists:
|
self.mock_object(os, 'rename')
|
||||||
mock_exists.return_value = True
|
self.mock_object(tempfile, 'NamedTemporaryFile')
|
||||||
with mock.patch.object(image_utils, 'fetch_to_raw'):
|
self.mock_object(os.path, 'exists', return_value=True)
|
||||||
with mock.patch.object(self.driver, 'delete_volume'):
|
|
||||||
with mock.patch.object(self.driver, '_resize'):
|
self.mock_object(image_utils, 'fetch_to_raw')
|
||||||
mock_image_service = mock.MagicMock()
|
self.mock_object(self.driver, 'delete_volume')
|
||||||
args = [self.context, self.volume_a,
|
self.mock_object(self.driver, '_resize')
|
||||||
mock_image_service, None]
|
|
||||||
self.driver.copy_image_to_encrypted_volume(
|
mock_image_service = mock.MagicMock()
|
||||||
*args)
|
args = [self.context, self.volume_a, mock_image_service, None]
|
||||||
mock_temp_delete.assert_called()
|
self.driver.copy_image_to_encrypted_volume(*args)
|
||||||
self.assertEqual(1,
|
mock_temp_delete.assert_called()
|
||||||
mock_temp_delete.call_count)
|
self.assertEqual(1, mock_temp_delete.call_count)
|
||||||
|
|
||||||
@common_mocks
|
@common_mocks
|
||||||
def test_copy_image_no_volume_tmp(self):
|
def test_copy_image_no_volume_tmp(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user