Nir Soffer has uploaded a new change for review.

Change subject: qemuimg: Validate qcow2_compat configuration
......................................................................

qemuimg: Validate qcow2_compat configuration

Validate new qcow2_compat option against a list of approved values, and
raise (new) InvalidConfiguration error if the value is not supported:

   InvalidConfiguration: Invalid configuration value: ("Unsupported value
   for irs:qcow2_compat: '1.2'",)

This document the ones we accept and help to diagnose configuration
mistakes. We need to maintain this list over time, but it's good for us
to check new compat versions to see if we're ready to allow them to be
used in vdsm storage.

Change-Id: I8e217ec42a803d53403947a5fb140cb51202fbfa
Bug-Url: https://bugzilla.redhat.com/1317850
Signed-off-by: Nir Soffer <[email protected]>
---
M lib/vdsm/exception.py
M lib/vdsm/qemuimg.py
M tests/qemuimgTests.py
3 files changed, 22 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/56110/1

diff --git a/lib/vdsm/exception.py b/lib/vdsm/exception.py
index 1c4dcb5..40d13f5 100644
--- a/lib/vdsm/exception.py
+++ b/lib/vdsm/exception.py
@@ -363,6 +363,11 @@
         return "%s: %s" % (self.message, repr(self.value))
 
 
+class InvalidConfiguration(GeneralException):
+    code = 101
+    message = "Invalid configuration value"
+
+
 class ActionStopped(GeneralException):
     code = 443
     message = "Action was stopped"
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 08c854e..a5402a5 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -44,6 +44,8 @@
     RAW = "raw"
     VMDK = "vmdk"
 
+_QCOW2_COMPAT_SUPPORTED = ["0.10", "1.1"]
+
 __iregex = {
     'format': re.compile("^file format: (?P<value>\w+)$"),
     'virtualsize': re.compile("^virtual size: "
@@ -123,7 +125,11 @@
     if format:
         cmd.extend(("-f", format))
         if format == FORMAT.QCOW2 and _supports_qcow2_compat('create'):
-            cmd.extend(('-o', 'compat=' + config.get('irs', 'qcow2_compat')))
+            value = config.get('irs', 'qcow2_compat')
+            if value not in _QCOW2_COMPAT_SUPPORTED:
+                raise exception.InvalidConfiguration(
+                    "Unsupported value for irs:qcow2_compat: %r" % value)
+            cmd.extend(('-o', 'compat=' + value))
 
     if backing:
         if not os.path.isabs(backing):
diff --git a/tests/qemuimgTests.py b/tests/qemuimgTests.py
index 8e0c37b..ffc9428 100644
--- a/tests/qemuimgTests.py
+++ b/tests/qemuimgTests.py
@@ -21,8 +21,10 @@
 from monkeypatch import MonkeyPatch, MonkeyPatchScope
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import permutations, expandPermutations
+from testlib import make_config
 from vdsm import qemuimg
 from vdsm import commands
+from vdsm import exception
 
 QEMU_IMG = qemuimg._qemuimg.cmd
 
@@ -153,6 +155,14 @@
                                (commands, 'execCmd', create)]):
             qemuimg.create('image', format='qcow2')
 
+    def test_invalid_config(self):
+        config = make_config([('irs', 'qcow2_compat', '1.2')])
+        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
+                                self.supported('create', True)),
+                               (qemuimg, 'config', config)]):
+            with self.assertRaises(exception.InvalidConfiguration):
+                qemuimg.create('image', format='qcow2')
+
 
 class ConvertTests(CommandTests):
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e217ec42a803d53403947a5fb140cb51202fbfa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to