From patchwork Tue May 31 09:15:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9144083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19E1460757 for ; Tue, 31 May 2016 09:37:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A73327D17 for ; Tue, 31 May 2016 09:37:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F212827E72; Tue, 31 May 2016 09:37:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D0BC27D17 for ; Tue, 31 May 2016 09:37:57 +0000 (UTC) Received: from localhost ([::1]:35465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7g7Y-0000Fh-0Z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 31 May 2016 05:37:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7fmX-0006RS-18 for qemu-devel@nongnu.org; Tue, 31 May 2016 05:16:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7fmR-0005Yk-Hz for qemu-devel@nongnu.org; Tue, 31 May 2016 05:16:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:38406 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7fmQ-0005YQ-Sw for qemu-devel@nongnu.org; Tue, 31 May 2016 05:16:07 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u4V9FUaQ003235; Tue, 31 May 2016 12:15:54 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Tue, 31 May 2016 12:15:29 +0300 Message-Id: <1464686130-12265-11-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464686130-12265-1-git-send-email-den@openvz.org> References: <1464686130-12265-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 10/11] qemu-iotests: test backup compression in 055 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Pavel Butsykin , Jeff Cody , Markus Armbruster , Stefan Hajnoczi , den@openvz.org, John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Butsykin Added cases to check the backup compression out of qcow2, raw in qcow2 on drive-backup and blockdev-backup. Signed-off-by: Pavel Butsykin Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Markus Armbruster CC: Eric Blake CC: John Snow CC: Stefan Hajnoczi CC: Kevin Wolf --- tests/qemu-iotests/055 | 97 +++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/055.out | 4 +- tests/qemu-iotests/iotests.py | 10 ++--- 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055 index c8e3578..3ac6894 100755 --- a/tests/qemu-iotests/055 +++ b/tests/qemu-iotests/055 @@ -451,5 +451,102 @@ class TestSingleTransaction(iotests.QMPTestCase): self.assert_qmp(result, 'error/class', 'GenericError') self.assert_no_active_block_jobs() + +class TestDriveCompression(iotests.QMPTestCase): + image_len = 64 * 1024 * 1024 # MB + outfmt = 'qcow2' + + def setUp(self): + # Write data to the image so we can compare later + qemu_img('create', '-f', iotests.imgfmt, test_img, str(TestDriveCompression.image_len)) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x11 0 64k', test_img) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x00 64k 128k', test_img) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x22 162k 32k', test_img) + qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x33 67043328 64k', test_img) + + qemu_img('create', '-f', TestDriveCompression.outfmt, blockdev_target_img, + str(TestDriveCompression.image_len)) + self.vm = iotests.VM().add_drive(test_img).add_drive(blockdev_target_img, + format=TestDriveCompression.outfmt) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + os.remove(blockdev_target_img) + try: + os.remove(target_img) + except OSError: + pass + + def do_test_compress_complete(self, cmd, **args): + self.assert_no_active_block_jobs() + + result = self.vm.qmp(cmd, device='drive0', sync='full', compress=True, **args) + self.assert_qmp(result, 'return', {}) + + self.wait_until_completed() + + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, blockdev_target_img, + iotests.imgfmt, TestDriveCompression.outfmt), + 'target image does not match source after backup') + + def test_complete_compress_drive_bakup(self): + self.do_test_compress_complete('drive-backup', target=blockdev_target_img, mode='existing') + + def test_complete_compress_blockdev_backup(self): + self.do_test_compress_complete('blockdev-backup', target='drive1') + + def do_test_compress_cancel(self, cmd, **args): + self.assert_no_active_block_jobs() + + result = self.vm.qmp(cmd, device='drive0', sync='full', compress=True, **args) + self.assert_qmp(result, 'return', {}) + + event = self.cancel_and_wait() + self.assert_qmp(event, 'data/type', 'backup') + + def test_compress_cancel_drive_bakup(self): + self.do_test_compress_cancel('drive-backup', target=blockdev_target_img, mode='existing') + + def test_compress_cancel_blockdev_backup(self): + self.do_test_compress_cancel('blockdev-backup', target='drive1') + + def do_test_compress_pause(self, cmd, **args): + self.assert_no_active_block_jobs() + + self.vm.pause_drive('drive0') + result = self.vm.qmp(cmd, device='drive0', sync='full', compress=True, **args) + self.assert_qmp(result, 'return', {}) + + result = self.vm.qmp('block-job-pause', device='drive0') + self.assert_qmp(result, 'return', {}) + + self.vm.resume_drive('drive0') + time.sleep(1) + result = self.vm.qmp('query-block-jobs') + offset = self.dictpath(result, 'return[0]/offset') + + time.sleep(1) + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/offset', offset) + + result = self.vm.qmp('block-job-resume', device='drive0') + self.assert_qmp(result, 'return', {}) + + self.wait_until_completed() + + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, blockdev_target_img, + iotests.imgfmt, TestDriveCompression.outfmt), + 'target image does not match source after backup') + + def test_compress_pause_drive_bakup(self): + self.do_test_compress_pause('drive-backup', target=blockdev_target_img, mode='existing') + + def test_compress_pause_blockdev_backup(self): + self.do_test_compress_pause('blockdev-backup', target='drive1') + if __name__ == '__main__': iotests.main(supported_fmts=['raw', 'qcow2']) diff --git a/tests/qemu-iotests/055.out b/tests/qemu-iotests/055.out index 42314e9..5ce2f9a 100644 --- a/tests/qemu-iotests/055.out +++ b/tests/qemu-iotests/055.out @@ -1,5 +1,5 @@ -........................ +.............................. ---------------------------------------------------------------------- -Ran 24 tests +Ran 30 tests OK diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 1687c33..68830a42 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -89,10 +89,10 @@ def qemu_io(*args): sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, ' '.join(args))) return subp.communicate()[0] -def compare_images(img1, img2): +def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt): '''Return True if two image files are identical''' - return qemu_img('compare', '-f', imgfmt, - '-F', imgfmt, img1, img2) == 0 + return qemu_img('compare', '-f', fmt1, + '-F', fmt2, img1, img2) == 0 def create_image(name, size): '''Create a fully-allocated raw image with sector markers''' @@ -175,14 +175,14 @@ class VM(object): self._args.append(opts) return self - def add_drive(self, path, opts='', interface='virtio'): + def add_drive(self, path, opts='', interface='virtio', format=imgfmt): '''Add a virtio-blk drive to the VM''' options = ['if=%s' % interface, 'id=drive%d' % self._num_drives] if path is not None: options.append('file=%s' % path) - options.append('format=%s' % imgfmt) + options.append('format=%s' % format) options.append('cache=%s' % cachemode) if opts: