Merge "Tests: Clean up RBD image unit tests"

This commit is contained in:
Zuul 2024-10-04 17:32:35 +00:00 committed by Gerrit Code Review
commit 774d784aca

View File

@ -1825,19 +1825,16 @@ 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, args = [None, self.volume_a, mock_image_service, None]
mock_image_service, None]
if volume_busy: if volume_busy:
mock_dv.side_effect = ( mock_dv.side_effect = exception.VolumeIsBusy("doh")
exception.VolumeIsBusy("doh"))
self.assertRaises( self.assertRaises(
exception.VolumeIsBusy, exception.VolumeIsBusy,
self.driver.copy_image_to_volume, self.driver.copy_image_to_volume,
@ -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')
self.mock_object(self.driver, 'delete_volume')
self.mock_object(self.driver, '_resize')
mock_image_service = mock.MagicMock() mock_image_service = mock.MagicMock()
args = [self.context, self.volume_a, args = [self.context, self.volume_a, mock_image_service, None]
mock_image_service, None] self.driver.copy_image_to_encrypted_volume(*args)
self.driver.copy_image_to_encrypted_volume(
*args)
mock_temp_delete.assert_called() mock_temp_delete.assert_called()
self.assertEqual(1, self.assertEqual(1, mock_temp_delete.call_count)
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):