Change in vdsm[master]: qemuimg.py: Don't check compat support

amureini at redhat.com amureini at redhat.com
Sun Apr 10 22:14:12 UTC 2016


Allon Mureinik has uploaded a new change for review.

Change subject: qemuimg.py: Don't check compat support
......................................................................

qemuimg.py: Don't check compat support

Modern qemu-img versions allow different QCOW2 formats - 0.10 and 1.1,
although we force the use of 0.10 in order to be backwards compatible
with old hupervisors that may still need to connect to a V3 domain.

Sufficiently old qemu-img versions, though, don't even support the
compat argument, requiring VDSM to query its existence with the "-o ?"
flag before deciding whether to use it. As EL6 support was dropped and
VDSM requires qemu-img>=2.3.0, this check is now redundant, and can
safely be removed, thus cleaning up the code, and saving some CPU
cycles.

As part of this patch, the tests were also cleaned up to match the
code. Tests for qemu-img that does not support the compat argument
were removed, and the the remaining tests were renamed to better
remove the notion that having this argument is something special.

Change-Id: Ie141ac33f60b340b7f12832e4fb6b92ea6a68289
Signed-off-by: Allon Mureinik <amureini at redhat.com>
---
M lib/vdsm/qemuimg.py
M tests/qemuimgTests.py
2 files changed, 10 insertions(+), 103 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/25/55925/1

diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 769b93d..e298b24 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -127,7 +127,7 @@
 
     if format:
         cmd.extend(("-f", format))
-        if format == FORMAT.QCOW2 and _supports_qcow2_compat('create'):
+        if format == FORMAT.QCOW2:
             cmd.extend(('-o', 'compat=' + QCOW2_COMPAT))
 
     if backing:
@@ -192,7 +192,7 @@
 
     if dstFormat:
         cmd.extend(("-O", dstFormat))
-        if dstFormat == FORMAT.QCOW2 and _supports_qcow2_compat('convert'):
+        if dstFormat == FORMAT.QCOW2:
             options.append('compat=' + QCOW2_COMPAT)
 
     if backing:
@@ -331,36 +331,6 @@
 
 
 # Testing capabilities
-
-def _supports_qcow2_compat(command):
-    """
-    qemu-img "create" and "convert" commands support a "compat" option in
-    recent versions. This will run the specified command using the "-o ?"
-    option to find if "compat" option is available.
-
-    Raises KeyError if called with another command.
-
-    TODO: Remove this when qemu versions providing the "compat" option are
-    available on all platforms.
-    """
-    # Older qemu-img requires all filenames although unneeded
-    args = {"create": ("-f", ("/dev/null",)),
-            "convert": ("-O", ("/dev/null", "/dev/null"))}
-    flag, dummy_files = args[command]
-
-    cmd = [_qemuimg.cmd, command, flag, FORMAT.QCOW2, "-o", "?"]
-    cmd.extend(dummy_files)
-
-    rc, out, err = commands.execCmd(cmd, raw=True)
-
-    if rc != 0:
-        raise QImgError(rc, out, err)
-
-    # Supported options:
-    # compat           Compatibility level (0.10 or 1.1)
-
-    return '\ncompat ' in out
-
 
 @utils.memoized
 def _supports_src_cache(command):
diff --git a/tests/qemuimgTests.py b/tests/qemuimgTests.py
index 8e0c37b..687133f 100644
--- a/tests/qemuimgTests.py
+++ b/tests/qemuimgTests.py
@@ -129,18 +129,7 @@
         with MonkeyPatchScope([(commands, "execCmd", create)]):
             qemuimg.create('image', size=0)
 
-    def test_qcow2_compat_unsupported(self):
-        def create(cmd, **kw):
-            expected = [QEMU_IMG, 'create', '-f', 'qcow2', 'image']
-            self.assertEqual(cmd, expected)
-            return 0, '', ''
-
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('create', False)),
-                               (commands, 'execCmd', create)]):
-            qemuimg.create('image', format='qcow2')
-
-    def test_qcow2_compat_supported(self):
+    def test_qcow2_compat(self):
 
         def create(cmd, **kw):
             expected = [QEMU_IMG, 'create', '-f', 'qcow2', '-o', 'compat=0.10',
@@ -148,9 +137,7 @@
             self.assertEqual(cmd, expected)
             return 0, '', ''
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('create', True)),
-                               (commands, 'execCmd', create)]):
+        with MonkeyPatchScope([(commands, 'execCmd', create)]):
             qemuimg.create('image', format='qcow2')
 
 
@@ -166,28 +153,13 @@
                                 self.supported('convert', False))]):
             qemuimg.convert('src', 'dst')
 
-    def test_qcow2_compat_unsupported(self):
-        def convert(cmd, **kw):
-            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', 'src', '-O',
-                        'qcow2', 'dst']
-            self.assertEqual(cmd, expected)
-
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', False)),
-                               (qemuimg, '_supports_src_cache',
-                                self.supported('convert', False)),
-                               (qemuimg, 'QemuImgOperation', convert)]):
-            qemuimg.convert('src', 'dst', dstFormat='qcow2')
-
-    def test_qcow2_compat_supported(self):
+    def test_qcow2_compat(self):
         def convert(cmd, **kw):
             expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', 'src', '-O',
                         'qcow2', '-o', 'compat=0.10', 'dst']
             self.assertEqual(cmd, expected)
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', True)),
-                               (qemuimg, '_supports_src_cache',
+        with MonkeyPatchScope([(qemuimg, '_supports_src_cache',
                                 self.supported('convert', False)),
                                (qemuimg, 'QemuImgOperation', convert)]):
             qemuimg.convert('src', 'dst', dstFormat='qcow2')
@@ -198,9 +170,7 @@
                         '-O', 'qcow2', '-o', 'compat=0.10', 'dst']
             self.assertEqual(cmd, expected)
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', True)),
-                               (qemuimg, '_supports_src_cache',
+        with MonkeyPatchScope([(qemuimg, '_supports_src_cache',
                                 self.supported('convert', False)),
                                (qemuimg, 'QemuImgOperation', convert)]):
             qemuimg.convert('src', 'dst', dstFormat='qcow2')
@@ -212,9 +182,7 @@
                         'dst']
             self.assertEqual(cmd, expected)
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', True)),
-                               (qemuimg, '_supports_src_cache',
+        with MonkeyPatchScope([(qemuimg, '_supports_src_cache',
                                 self.supported('convert', False)),
                                (qemuimg, 'QemuImgOperation', convert)]):
             qemuimg.convert('src', 'dst', dstFormat='qcow2',
@@ -226,9 +194,7 @@
                         '-O', 'qcow2', '-o', 'compat=0.10', 'dst']
             self.assertEqual(cmd, expected)
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', True)),
-                               (qemuimg, '_supports_src_cache',
+        with MonkeyPatchScope([(qemuimg, '_supports_src_cache',
                                 self.supported('convert', False)),
                                (qemuimg, 'QemuImgOperation', convert)]):
             qemuimg.convert('src', 'dst', dstFormat='qcow2',
@@ -241,40 +207,11 @@
                         'backing_fmt=qcow2', 'dst']
             self.assertEqual(cmd, expected)
 
-        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
-                                self.supported('convert', True)),
-                               (qemuimg, '_supports_src_cache',
+        with MonkeyPatchScope([(qemuimg, '_supports_src_cache',
                                 self.supported('convert', False)),
                                (qemuimg, 'QemuImgOperation', convert)]):
             qemuimg.convert('src', 'dst', dstFormat='qcow2',
                             backing='bak', backingFormat='qcow2')
-
-
-def qcow2_compat_supported(cmd, **kw):
-    return 0, 'Supported options:\ncompat ...\n', ''
-
-
-def qcow2_compat_unsupported(cmd, **kw):
-    return 0, 'Supported options:\nsize ...\n', ''
-
-
-class SupportsQcow2ComaptTests(TestCaseBase):
-
-    @MonkeyPatch(commands, 'execCmd', qcow2_compat_supported)
-    def test_create_supported(self, **kw):
-        self.assertTrue(qemuimg._supports_qcow2_compat('create'))
-
-    @MonkeyPatch(commands, 'execCmd', qcow2_compat_unsupported)
-    def test_create_unsupported(self, **kw):
-        self.assertFalse(qemuimg._supports_qcow2_compat('create'))
-
-    @MonkeyPatch(commands, 'execCmd', qcow2_compat_supported)
-    def test_convert_supported(self, **kw):
-        self.assertTrue(qemuimg._supports_qcow2_compat('convert'))
-
-    @MonkeyPatch(commands, 'execCmd', qcow2_compat_unsupported)
-    def test_convert_unsupported(self, **kw):
-        self.assertFalse(qemuimg._supports_qcow2_compat('convert'))
 
 
 def src_cache_supported(cmd, **kw):


-- 
To view, visit https://gerrit.ovirt.org/55925
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie141ac33f60b340b7f12832e4fb6b92ea6a68289
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <amureini at redhat.com>


More information about the vdsm-patches mailing list