From patchwork Wed Oct 9 08:46:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 281750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B47F62C0084 for ; Wed, 9 Oct 2013 19:49:43 +1100 (EST) Received: from localhost ([::1]:40734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTpSf-00051F-SO for incoming@patchwork.ozlabs.org; Wed, 09 Oct 2013 04:49:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTpPj-0000g4-K3 for qemu-devel@nongnu.org; Wed, 09 Oct 2013 04:46:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTpPf-0000Ff-0J for qemu-devel@nongnu.org; Wed, 09 Oct 2013 04:46:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTpPe-0000FS-NC for qemu-devel@nongnu.org; Wed, 09 Oct 2013 04:46:34 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r998kXoJ010069 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Oct 2013 04:46:33 -0400 Received: from localhost (dhcp-200-247.str.redhat.com [10.33.200.247]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r998kWN8005142 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 9 Oct 2013 04:46:33 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 9 Oct 2013 10:46:20 +0200 Message-Id: <1381308380-23517-7-git-send-email-mreitz@redhat.com> In-Reply-To: <1381308380-23517-1-git-send-email-mreitz@redhat.com> References: <1381308380-23517-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v8 6/6] qemu-iotests: Additional info from qemu-img info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a test for the additional information now provided by qemu-img info when used on qcow2 images. It also tests the qemu QMP output from the query-block command when running qemu with different runtime options than specified in the image (ImageInfoSpecific should always refer to the image). Signed-off-by: Max Reitz --- tests/qemu-iotests/065 | 125 ++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/065.out | 5 ++ tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 4 ++ 4 files changed, 135 insertions(+) create mode 100755 tests/qemu-iotests/065 create mode 100644 tests/qemu-iotests/065.out diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065 new file mode 100755 index 0000000..a4db717 --- /dev/null +++ b/tests/qemu-iotests/065 @@ -0,0 +1,125 @@ +#!/usr/bin/env python2 +# +# Test for additional information emitted by qemu-img info on qcow2 +# images +# +# Copyright (C) 2013 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import re +import json +import iotests +from iotests import qemu_img, qemu_img_pipe +import unittest + +test_img = os.path.join(iotests.test_dir, 'test.img') + +class TestImageInfoSpecific(iotests.QMPTestCase): + '''Abstract base class for ImageInfoSpecific tests''' + + def setUp(self): + if self.img_options is None: + self.skipTest('Skipping abstract test class') + qemu_img('create', '-f', iotests.imgfmt, '-o', self.img_options, + test_img, '128K') + + def tearDown(self): + os.remove(test_img) + +class TestQemuImgInfo(TestImageInfoSpecific): + '''Abstract base class for qemu-img info tests''' + + img_options = None + json_compare = None + human_compare = None + + def test_json(self): + data = json.loads(qemu_img_pipe('info', '--output=json', test_img)) + data = data['format-specific'] + self.assertEqual(data['type'], iotests.imgfmt) + self.assertEqual(data['data'], self.json_compare) + + def test_human(self): + data = qemu_img_pipe('info', '--output=human', test_img).split('\n') + data = data[(data.index('Format specific information:') + 1) + :data.index('')] + for field in data: + self.assertTrue(re.match('^ {4}[^ ]', field) is not None) + data = map(lambda line: line.strip(), data) + self.assertEqual(data, self.human_compare) + +class TestQMP(TestImageInfoSpecific): + '''Abstract base class for qemu QMP tests''' + + img_options = None + qemu_options = '' + + def setUp(self): + TestImageInfoSpecific.setUp(self) + self.vm = iotests.VM().add_drive(test_img, self.qemu_options) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + TestImageInfoSpecific.tearDown(self) + + def test_qmp(self): + result = self.vm.qmp('query-block')['return'] + drive = filter(lambda drive: drive['device'] == 'drive0', result)[0] + data = drive['inserted']['image']['format-specific'] + self.assertEqual(data['type'], iotests.imgfmt) + self.assertEqual(data['data'], self.compare) + +@unittest.skipIf(iotests.imgfmt != 'qcow2', 'This test is qcow2-specific') +class TestQCow2(TestQemuImgInfo): + '''Testing a qcow2 version 2 image''' + img_options = 'compat=0.10' + json_compare = { 'compat': '0.10' } + human_compare = [ 'compat: 0.10' ] + +@unittest.skipIf(iotests.imgfmt != 'qcow2', 'This test is qcow2-specific') +class TestQCow3NotLazy(TestQemuImgInfo): + '''Testing a qcow2 version 3 image with lazy refcounts disabled''' + img_options = 'compat=1.1,lazy_refcounts=off' + json_compare = { 'compat': '1.1', 'lazy-refcounts': False } + human_compare = [ 'compat: 1.1', 'lazy refcounts: false' ] + +@unittest.skipIf(iotests.imgfmt != 'qcow2', 'This test is qcow2-specific') +class TestQCow3Lazy(TestQemuImgInfo): + '''Testing a qcow2 version 3 image with lazy refcounts enabled''' + img_options = 'compat=1.1,lazy_refcounts=on' + json_compare = { 'compat': '1.1', 'lazy-refcounts': True } + human_compare = [ 'compat: 1.1', 'lazy refcounts: true' ] + +@unittest.skipIf(iotests.imgfmt != 'qcow2', 'This test is qcow2-specific') +class TestQCow3NotLazyQMP(TestQMP): + '''Testing a qcow2 version 3 image with lazy refcounts disabled, opening + with lazy refcounts enabled''' + img_options = 'compat=1.1,lazy_refcounts=off' + qemu_options = 'lazy-refcounts=on' + compare = { 'compat': '1.1', 'lazy-refcounts': False } + +@unittest.skipIf(iotests.imgfmt != 'qcow2', 'This test is qcow2-specific') +class TestQCow3LazyQMP(TestQMP): + '''Testing a qcow2 version 3 image with lazy refcounts enabled, opening + with lazy refcounts disabled''' + img_options = 'compat=1.1,lazy_refcounts=on' + qemu_options = 'lazy-refcounts=off' + compare = { 'compat': '1.1', 'lazy-refcounts': True } + +if __name__ == '__main__': + iotests.main(supported_fmts=['qcow2']) diff --git a/tests/qemu-iotests/065.out b/tests/qemu-iotests/065.out new file mode 100644 index 0000000..1351234 --- /dev/null +++ b/tests/qemu-iotests/065.out @@ -0,0 +1,5 @@ +........sss +---------------------------------------------------------------------- +Ran 11 tests + +OK (skipped=3) diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1ad02e5..f1a68b0 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -69,3 +69,4 @@ 061 rw auto 062 rw auto 063 rw auto +065 rw auto diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 376d6e8..fb10ff4 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -49,6 +49,10 @@ def qemu_img_verbose(*args): '''Run qemu-img without suppressing its output and return the exit code''' return subprocess.call(qemu_img_args + list(args)) +def qemu_img_pipe(*args): + '''Run qemu-img and return its output''' + return subprocess.Popen(qemu_img_args + list(args), stdout=subprocess.PIPE).communicate()[0] + def qemu_io(*args): '''Run qemu-io and return the stdout data''' args = qemu_io_args + list(args)