From 7cc057646357e6bd045c0860d59b4bc71d7a5b4f Mon Sep 17 00:00:00 2001 From: int32bit Date: Mon, 19 Dec 2016 22:54:32 +0800 Subject: [PATCH] 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 --- nova/tests/unit/virt/libvirt/test_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_utils.py b/nova/tests/unit/virt/libvirt/test_utils.py index b954e23d7252..7612d8b4dc60 100644 --- a/nova/tests/unit/virt/libvirt/test_utils.py +++ b/nova/tests/unit/virt/libvirt/test_utils.py @@ -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,