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
This commit is contained in:
Gorka Eguileor
2022-08-19 16:04:40 +02:00
parent b50847a0cb
commit e92c4d01d7

View File

@@ -949,8 +949,8 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_info_output)
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
@@ -996,11 +996,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output)
# 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)
@@ -1009,7 +1009,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',
@@ -1052,11 +1052,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output)
# 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()
@@ -1066,7 +1066,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(
@@ -1113,11 +1113,11 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output)
# 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()
@@ -1129,7 +1129,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',
@@ -1177,13 +1177,13 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output)
# 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)
@@ -1191,7 +1191,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',
@@ -1253,7 +1253,7 @@ class QuobyteDriverTestCase(test.TestCase):
img_info = imageutils.QemuImgInfo(qemu_img_output)
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)