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 e92c4d01d7
)
This commit is contained in:

committed by
Elod Illes

parent
38f84a4efb
commit
263f691e4a
@@ -950,8 +950,8 @@ class QuobyteDriverTestCase(test.TestCase):
|
|||||||
|
|
||||||
img_info = imageutils.QemuImgInfo(qemu_img_info_output, format='json')
|
img_info = imageutils.QemuImgInfo(qemu_img_info_output, format='json')
|
||||||
|
|
||||||
image_utils.qemu_img_info = mock.Mock(return_value=img_info)
|
self.mock_object(image_utils, 'qemu_img_info', return_value=img_info)
|
||||||
image_utils.resize_image = mock.Mock()
|
self.mock_object(image_utils, 'resize_image')
|
||||||
|
|
||||||
mock_remote_attached.return_value = is_attached
|
mock_remote_attached.return_value = is_attached
|
||||||
|
|
||||||
@@ -998,11 +998,11 @@ class QuobyteDriverTestCase(test.TestCase):
|
|||||||
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
||||||
|
|
||||||
# mocking and testing starts here
|
# 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=
|
drv._read_info_file = mock.Mock(return_value=
|
||||||
{'active': snap_file,
|
{'active': snap_file,
|
||||||
snapshot['id']: 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._set_rw_permissions = mock.Mock()
|
||||||
|
|
||||||
drv._copy_volume_from_snapshot(snapshot, dest_volume, size)
|
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,
|
image_utils.qemu_img_info.assert_called_once_with(snap_path,
|
||||||
force_share=True,
|
force_share=True,
|
||||||
run_as_root=False)
|
run_as_root=False)
|
||||||
(image_utils.convert_image.
|
(mock_convert.
|
||||||
assert_called_once_with(src_vol_path,
|
assert_called_once_with(src_vol_path,
|
||||||
dest_vol_path,
|
dest_vol_path,
|
||||||
'raw',
|
'raw',
|
||||||
@@ -1055,11 +1055,11 @@ class QuobyteDriverTestCase(test.TestCase):
|
|||||||
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
||||||
|
|
||||||
# mocking and testing starts here
|
# 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=
|
drv._read_info_file = mock.Mock(return_value=
|
||||||
{'active': snap_file,
|
{'active': snap_file,
|
||||||
snapshot['id']: 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._set_rw_permissions = mock.Mock()
|
||||||
shutil.copyfile = 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,
|
image_utils.qemu_img_info.assert_called_once_with(snap_path,
|
||||||
force_share=True,
|
force_share=True,
|
||||||
run_as_root=False)
|
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")
|
("_convert_image was called but should not have been")
|
||||||
)
|
)
|
||||||
os_ac_mock.assert_called_once_with(
|
os_ac_mock.assert_called_once_with(
|
||||||
@@ -1117,11 +1117,11 @@ class QuobyteDriverTestCase(test.TestCase):
|
|||||||
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
||||||
|
|
||||||
# mocking and testing starts here
|
# 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=
|
drv._read_info_file = mock.Mock(return_value=
|
||||||
{'active': snap_file,
|
{'active': snap_file,
|
||||||
snapshot['id']: 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._set_rw_permissions = mock.Mock()
|
||||||
drv._create_overlay_volume_from_snapshot = 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,
|
image_utils.qemu_img_info.assert_called_once_with(snap_path,
|
||||||
force_share=True,
|
force_share=True,
|
||||||
run_as_root=False)
|
run_as_root=False)
|
||||||
(image_utils.convert_image.
|
(mock_convert.
|
||||||
assert_called_once_with(
|
assert_called_once_with(
|
||||||
src_vol_path,
|
src_vol_path,
|
||||||
drv._local_volume_from_snap_cache_path(snapshot), 'qcow2',
|
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')
|
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
||||||
|
|
||||||
# mocking and testing starts here
|
# 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=
|
drv._read_info_file = mock.Mock(return_value=
|
||||||
{'active': snap_file,
|
{'active': snap_file,
|
||||||
snapshot['id']: 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._set_rw_permissions = mock.Mock()
|
||||||
shutil.copyfile = mock.Mock()
|
self.mock_object(shutil, 'copyfile')
|
||||||
|
|
||||||
drv._copy_volume_from_snapshot(snapshot, dest_volume, size)
|
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,
|
image_utils.qemu_img_info.assert_called_once_with(snap_path,
|
||||||
force_share=True,
|
force_share=True,
|
||||||
run_as_root=False)
|
run_as_root=False)
|
||||||
(image_utils.convert_image.
|
(mock_convert.
|
||||||
assert_called_once_with(
|
assert_called_once_with(
|
||||||
src_vol_path,
|
src_vol_path,
|
||||||
drv._local_volume_from_snap_cache_path(snapshot), 'raw',
|
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')
|
img_info = imageutils.QemuImgInfo(qemu_img_output, format='json')
|
||||||
|
|
||||||
drv.get_active_image_from_info = mock.Mock(return_value=volume['name'])
|
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)
|
conn_info = drv.initialize_connection(volume, None)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user