yeahuh / rpms / qemu-kvm

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