yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-iotests-Additional-info-from-qemu-img-info.patch

9ae3a8
From 9769e7ac9ff2005316a655365c72c12a40579195 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Wed, 6 Nov 2013 16:53:39 +0100
9ae3a8
Subject: [PATCH 82/87] qemu-iotests: Additional info from qemu-img info
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383756824-6921-17-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55571
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 16/21] qemu-iotests: Additional info from qemu-img info
9ae3a8
Bugzilla: 980771
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
9ae3a8
BZ: 980771
9ae3a8
9ae3a8
Add a test for the additional information now provided by qemu-img info
9ae3a8
when used on qcow2 images. It also tests the qemu QMP output from the
9ae3a8
query-block command when running qemu with different runtime options
9ae3a8
than specified in the image (ImageInfoSpecific should always refer to
9ae3a8
the image).
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 3677e6f6252542cbab85674d97d051d95e91693b)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/065        | 125 ++++++++++++++++++++++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/065.out    |   5 ++
9ae3a8
 tests/qemu-iotests/group      |   1 +
9ae3a8
 tests/qemu-iotests/iotests.py |   4 ++
9ae3a8
 4 files changed, 135 insertions(+)
9ae3a8
 create mode 100755 tests/qemu-iotests/065
9ae3a8
 create mode 100644 tests/qemu-iotests/065.out
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/065        |  125 +++++++++++++++++++++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/065.out    |    5 ++
9ae3a8
 tests/qemu-iotests/group      |    1 +
9ae3a8
 tests/qemu-iotests/iotests.py |    4 +
9ae3a8
 4 files changed, 135 insertions(+), 0 deletions(-)
9ae3a8
 create mode 100755 tests/qemu-iotests/065
9ae3a8
 create mode 100644 tests/qemu-iotests/065.out
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065
9ae3a8
new file mode 100755
9ae3a8
index 0000000..ab5445f
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/065
9ae3a8
@@ -0,0 +1,125 @@
9ae3a8
+#!/usr/bin/env python2
9ae3a8
+#
9ae3a8
+# Test for additional information emitted by qemu-img info on qcow2
9ae3a8
+# images
9ae3a8
+#
9ae3a8
+# Copyright (C) 2013 Red Hat, Inc.
9ae3a8
+#
9ae3a8
+# This program is free software; you can redistribute it and/or modify
9ae3a8
+# it under the terms of the GNU General Public License as published by
9ae3a8
+# the Free Software Foundation; either version 2 of the License, or
9ae3a8
+# (at your option) any later version.
9ae3a8
+#
9ae3a8
+# This program is distributed in the hope that it will be useful,
9ae3a8
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
9ae3a8
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9ae3a8
+# GNU General Public License for more details.
9ae3a8
+#
9ae3a8
+# You should have received a copy of the GNU General Public License
9ae3a8
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9ae3a8
+#
9ae3a8
+
9ae3a8
+import os
9ae3a8
+import re
9ae3a8
+import json
9ae3a8
+import iotests
9ae3a8
+from iotests import qemu_img, qemu_img_pipe
9ae3a8
+import unittest
9ae3a8
+
9ae3a8
+test_img = os.path.join(iotests.test_dir, 'test.img')
9ae3a8
+
9ae3a8
+class TestImageInfoSpecific(iotests.QMPTestCase):
9ae3a8
+    '''Abstract base class for ImageInfoSpecific tests'''
9ae3a8
+
9ae3a8
+    def setUp(self):
9ae3a8
+        if self.img_options is None:
9ae3a8
+            self.skipTest('Skipping abstract test class')
9ae3a8
+        qemu_img('create', '-f', iotests.imgfmt, '-o', self.img_options,
9ae3a8
+                 test_img, '128K')
9ae3a8
+
9ae3a8
+    def tearDown(self):
9ae3a8
+        os.remove(test_img)
9ae3a8
+
9ae3a8
+class TestQemuImgInfo(TestImageInfoSpecific):
9ae3a8
+    '''Abstract base class for qemu-img info tests'''
9ae3a8
+
9ae3a8
+    img_options = None
9ae3a8
+    json_compare = None
9ae3a8
+    human_compare = None
9ae3a8
+
9ae3a8
+    def test_json(self):
9ae3a8
+        data = json.loads(qemu_img_pipe('info', '--output=json', test_img))
9ae3a8
+        data = data['format-specific']
9ae3a8
+        self.assertEqual(data['type'], iotests.imgfmt)
9ae3a8
+        self.assertEqual(data['data'], self.json_compare)
9ae3a8
+
9ae3a8
+    def test_human(self):
9ae3a8
+        data = qemu_img_pipe('info', '--output=human', test_img).split('\n')
9ae3a8
+        data = data[(data.index('Format specific information:') + 1)
9ae3a8
+                    :data.index('')]
9ae3a8
+        for field in data:
9ae3a8
+            self.assertTrue(re.match('^ {4}[^ ]', field) is not None)
9ae3a8
+        data = map(lambda line: line.strip(), data)
9ae3a8
+        self.assertEqual(data, self.human_compare)
9ae3a8
+
9ae3a8
+class TestQMP(TestImageInfoSpecific):
9ae3a8
+    '''Abstract base class for qemu QMP tests'''
9ae3a8
+
9ae3a8
+    img_options = None
9ae3a8
+    qemu_options = ''
9ae3a8
+    TestImageInfoSpecific = TestImageInfoSpecific
9ae3a8
+
9ae3a8
+    def setUp(self):
9ae3a8
+        self.TestImageInfoSpecific.setUp(self)
9ae3a8
+        self.vm = iotests.VM().add_drive(test_img, self.qemu_options)
9ae3a8
+        self.vm.launch()
9ae3a8
+
9ae3a8
+    def tearDown(self):
9ae3a8
+        self.vm.shutdown()
9ae3a8
+        self.TestImageInfoSpecific.tearDown(self)
9ae3a8
+
9ae3a8
+    def test_qmp(self):
9ae3a8
+        result = self.vm.qmp('query-block')['return']
9ae3a8
+        drive = filter(lambda drive: drive['device'] == 'drive0', result)[0]
9ae3a8
+        data = drive['inserted']['image']['format-specific']
9ae3a8
+        self.assertEqual(data['type'], iotests.imgfmt)
9ae3a8
+        self.assertEqual(data['data'], self.compare)
9ae3a8
+
9ae3a8
+class TestQCow2(TestQemuImgInfo):
9ae3a8
+    '''Testing a qcow2 version 2 image'''
9ae3a8
+    img_options = 'compat=0.10'
9ae3a8
+    json_compare = { 'compat': '0.10' }
9ae3a8
+    human_compare = [ 'compat: 0.10' ]
9ae3a8
+
9ae3a8
+class TestQCow3NotLazy(TestQemuImgInfo):
9ae3a8
+    '''Testing a qcow2 version 3 image with lazy refcounts disabled'''
9ae3a8
+    img_options = 'compat=1.1,lazy_refcounts=off'
9ae3a8
+    json_compare = { 'compat': '1.1', 'lazy-refcounts': False }
9ae3a8
+    human_compare = [ 'compat: 1.1', 'lazy refcounts: false' ]
9ae3a8
+
9ae3a8
+class TestQCow3Lazy(TestQemuImgInfo):
9ae3a8
+    '''Testing a qcow2 version 3 image with lazy refcounts enabled'''
9ae3a8
+    img_options = 'compat=1.1,lazy_refcounts=on'
9ae3a8
+    json_compare = { 'compat': '1.1', 'lazy-refcounts': True }
9ae3a8
+    human_compare = [ 'compat: 1.1', 'lazy refcounts: true' ]
9ae3a8
+
9ae3a8
+class TestQCow3NotLazyQMP(TestQMP):
9ae3a8
+    '''Testing a qcow2 version 3 image with lazy refcounts disabled, opening
9ae3a8
+       with lazy refcounts enabled'''
9ae3a8
+    img_options = 'compat=1.1,lazy_refcounts=off'
9ae3a8
+    qemu_options = 'lazy-refcounts=on'
9ae3a8
+    compare = { 'compat': '1.1', 'lazy-refcounts': False }
9ae3a8
+
9ae3a8
+class TestQCow3LazyQMP(TestQMP):
9ae3a8
+    '''Testing a qcow2 version 3 image with lazy refcounts enabled, opening
9ae3a8
+       with lazy refcounts disabled'''
9ae3a8
+    img_options = 'compat=1.1,lazy_refcounts=on'
9ae3a8
+    qemu_options = 'lazy-refcounts=off'
9ae3a8
+    compare = { 'compat': '1.1', 'lazy-refcounts': True }
9ae3a8
+
9ae3a8
+TestImageInfoSpecific = None
9ae3a8
+TestQemuImgInfo = None
9ae3a8
+TestQMP = None
9ae3a8
+
9ae3a8
+if __name__ == '__main__':
9ae3a8
+    iotests.main(supported_fmts=['qcow2'])
9ae3a8
diff --git a/tests/qemu-iotests/065.out b/tests/qemu-iotests/065.out
9ae3a8
new file mode 100644
9ae3a8
index 0000000..594c16f
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/065.out
9ae3a8
@@ -0,0 +1,5 @@
9ae3a8
+........
9ae3a8
+----------------------------------------------------------------------
9ae3a8
+Ran 8 tests
9ae3a8
+
9ae3a8
+OK
9ae3a8
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
9ae3a8
index d02ee96..68c056b 100644
9ae3a8
--- a/tests/qemu-iotests/group
9ae3a8
+++ b/tests/qemu-iotests/group
9ae3a8
@@ -64,5 +64,6 @@
9ae3a8
 059 rw auto
9ae3a8
 060 rw auto
9ae3a8
 063 rw auto
9ae3a8
+065 rw auto
9ae3a8
 067 rw auto
9ae3a8
 068 rw auto
9ae3a8
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
9ae3a8
index 569ca3d..5cbac82 100644
9ae3a8
--- a/tests/qemu-iotests/iotests.py
9ae3a8
+++ b/tests/qemu-iotests/iotests.py
9ae3a8
@@ -46,6 +46,10 @@ def qemu_img_verbose(*args):
9ae3a8
     '''Run qemu-img without suppressing its output and return the exit code'''
9ae3a8
     return subprocess.call(qemu_img_args + list(args))
9ae3a8
 
9ae3a8
+def qemu_img_pipe(*args):
9ae3a8
+    '''Run qemu-img and return its output'''
9ae3a8
+    return subprocess.Popen(qemu_img_args + list(args), stdout=subprocess.PIPE).communicate()[0]
9ae3a8
+
9ae3a8
 def qemu_io(*args):
9ae3a8
     '''Run qemu-io and return the stdout data'''
9ae3a8
     args = qemu_io_args + list(args)
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8