Tests: fix quobyte breaking other tests

This patch fixes the Quobyte driver unit tests that forcefully replace
the 'convert_image' method in 'image_utils' with a Mock and then doesn't
restore it afterwards, so any method that runs afterwards and expects
'convert_image' to actually run code will fail.

This patch uses the proper mocking mechanisms that restore things
afterwards.

Change-Id: Iec1cf6ade1d97900d4db6e29555ddef8d45b9534
(cherry picked from commit e92c4d01d798873fcab95f1b15e7df830fe29b62)
This commit is contained in:
Gorka Eguileor 2022-08-19 16:04:40 +02:00 committed by Elod Illes
parent 38f84a4efb
commit 263f691e4a

View File

@ -950,8 +950,8 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_info_output, format='json')
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
image_utils.resize_image = mock.Mock()
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
self.mock_object(image_utils, 'resize_image')
mock_remote_attached.return_value = is_attached
@ -998,11 +998,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
# mocking and testing starts here
image_utils.convert_image = mock.Mock()
mock_convert = self.mock_object(image_utils, 'convert_image')
drv._read_info_file = mock.Mock(return_value=
{'active': snap_file,
snapshot['id']: snap_file})
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
drv._set_rw_permissions = mock.Mock()
drv._copy_volume_from_snapshot(snapshot, dest_volume, size)
@ -1011,7 +1011,7 @@ class QuobyteDriverTestCase(test.TestCase):
image_utils.qemu_img_info.assert_called_once_with(snap_path,
force_share=True,
run_as_root=False)
(image_utils.convert_image.
(mock_convert.
assert_called_once_with(src_vol_path,
dest_vol_path,
'raw',
@ -1055,11 +1055,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
# mocking and testing starts here
image_utils.convert_image = mock.Mock()
mock_convert = self.mock_object(image_utils, 'convert_image')
drv._read_info_file = mock.Mock(return_value=
{'active': snap_file,
snapshot['id']: snap_file})
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
drv._set_rw_permissions = mock.Mock()
shutil.copyfile = mock.Mock()
@ -1069,7 +1069,7 @@ class QuobyteDriverTestCase(test.TestCase):
image_utils.qemu_img_info.assert_called_once_with(snap_path,
force_share=True,
run_as_root=False)
self.assertFalse(image_utils.convert_image.called,
self.assertFalse(mock_convert.called,
("_convert_image was called but should not have been")
)
os_ac_mock.assert_called_once_with(
@ -1117,11 +1117,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
# mocking and testing starts here
image_utils.convert_image = mock.Mock()
mock_convert = self.mock_object(image_utils, 'convert_image')
drv._read_info_file = mock.Mock(return_value=
{'active': snap_file,
snapshot['id']: snap_file})
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
drv._set_rw_permissions = mock.Mock()
drv._create_overlay_volume_from_snapshot = mock.Mock()
@ -1133,7 +1133,7 @@ class QuobyteDriverTestCase(test.TestCase):
image_utils.qemu_img_info.assert_called_once_with(snap_path,
force_share=True,
run_as_root=False)
(image_utils.convert_image.
(mock_convert.
assert_called_once_with(
src_vol_path,
drv._local_volume_from_snap_cache_path(snapshot), 'qcow2',
@ -1182,13 +1182,13 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
# mocking and testing starts here
image_utils.convert_image = mock.Mock()
mock_convert = self.mock_object(image_utils, 'convert_image')
drv._read_info_file = mock.Mock(return_value=
{'active': snap_file,
snapshot['id']: snap_file})
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
drv._set_rw_permissions = mock.Mock()
shutil.copyfile = mock.Mock()
self.mock_object(shutil, 'copyfile')
drv._copy_volume_from_snapshot(snapshot, dest_volume, size)
@ -1196,7 +1196,7 @@ class QuobyteDriverTestCase(test.TestCase):
image_utils.qemu_img_info.assert_called_once_with(snap_path,
force_share=True,
run_as_root=False)
(image_utils.convert_image.
(mock_convert.
assert_called_once_with(
src_vol_path,
drv._local_volume_from_snap_cache_path(snapshot), 'raw',
@ -1259,7 +1259,7 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
drv.get_active_image_from_info = mock.Mock(return_value=volume['name'])
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
conn_info = drv.initialize_connection(volume, None)