From 3e3ddbf0b655b78812875acbcbb360bdb6fc872b Mon Sep 17 00:00:00 2001
From: Constantinos Venetsanopoulos <cven@grnet.gr>
Date: Tue, 4 Dec 2012 13:50:16 +0200
Subject: [PATCH] Remove checks wrt IDISK_PARAMS from OpCode level

Change the "--disks" option validation, to just check the format
of the dict and do not check whether the keys are included in the
IDISK_PARAMS constant at OpCode level. This allows the passing of
arbitrary parameters at the CLI, which will then be logically
checked at LU level (inside CheckArguments).

Currently, the check wrt to IDISK_PARAMS already happens in all
related LUs (InstanceSetParams, InstanceCreate, InstanceRecreateDisks),
with the use of ForceDictType(), so there is no need for additional
checking code.

Signed-off-by: Constantinos Venetsanopoulos <cven@grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
[iustin@google.com: fixed a unittest that needed adjustement]
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/opcodes.py                     | 8 +++++---
 test/ganeti.rapi.rlib2_unittest.py | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/opcodes.py b/lib/opcodes.py
index 47216ccd4..fd6163953 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -207,10 +207,12 @@ _TSetParamsResult = \
   ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
                      ht.TItems(_TSetParamsResultItemItems)))
 
-# TODO: Generate check from constants.IDISK_PARAMS_TYPES (however, not all users
-# of this check support all parameters)
+# In the disks option we can provide arbitrary parameters too, which
+# we may not be able to validate at this level, so we just check the
+# format of the dict here and the checks concerning IDISK_PARAMS will
+# happen at the LU level
 _TDiskParams = \
-  ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
+  ht.Comment("Disk parameters")(ht.TDictOf(ht.TNonEmptyString,
                                            ht.TOr(ht.TNonEmptyString, ht.TInt)))
 
 _TQueryRow = \
diff --git a/test/ganeti.rapi.rlib2_unittest.py b/test/ganeti.rapi.rlib2_unittest.py
index c26bf5d8e..0f2c735e3 100755
--- a/test/ganeti.rapi.rlib2_unittest.py
+++ b/test/ganeti.rapi.rlib2_unittest.py
@@ -1003,7 +1003,7 @@ class TestInstanceCreation(testutils.GanetiTestCase):
     # Invalid disks and nics
     for field in ["disks", "nics"]:
       invalid_values = [None, 1, "", {}, [1, 2, 3], ["hda1", "hda2"],
-                        [{"_unknown_": 999, }]]
+                        [{"_unknown_": False, }]]
 
       for invvalue in invalid_values:
         data = reqfields.copy()
-- 
GitLab