Add unit test for extract_snapshot with compression enabled

Add a unit test for the libvirt.utils.extract_snapshot which sets
snapshot_compression option to True and verifies that qemu-img convert
is called with the -c option.

Closes-Bug: #1650770

Change-Id: I4d89e596ae79a329718bc22a774384ae723decb9
This commit is contained in:
int32bit 2016-12-19 22:54:32 +08:00
parent d0df4333a8
commit 7cc0576463

View File

@ -494,9 +494,12 @@ disk size: 4.4M
dest_format='raw', out_format='raw'):
libvirt_utils.extract_snapshot('/path/to/disk/image', src_format,
'/extracted/snap', dest_format)
mock_execute.assert_called_once_with(
'qemu-img', 'convert', '-f', src_format, '-O', out_format,
'/path/to/disk/image', '/extracted/snap')
qemu_img_cmd = ('qemu-img', 'convert', '-f',
src_format, '-O', out_format)
if CONF.libvirt.snapshot_compression and dest_format == "qcow2":
qemu_img_cmd += ('-c',)
qemu_img_cmd += ('/path/to/disk/image', '/extracted/snap')
mock_execute.assert_called_once_with(*qemu_img_cmd)
@mock.patch.object(utils, 'execute')
def test_extract_snapshot_raw(self, mock_execute):
@ -511,6 +514,12 @@ disk size: 4.4M
self._do_test_extract_snapshot(mock_execute,
dest_format='qcow2', out_format='qcow2')
@mock.patch.object(utils, 'execute')
def test_extract_snapshot_qcow2_and_compression(self, mock_execute):
self.flags(snapshot_compression=True, group='libvirt')
self._do_test_extract_snapshot(mock_execute,
dest_format='qcow2', out_format='qcow2')
@mock.patch.object(utils, 'execute')
def test_extract_snapshot_parallels(self, mock_execute):
self._do_test_extract_snapshot(mock_execute,