Revision 7eed4433
b/lib/constants.py | ||
---|---|---|
352 | 352 |
VALUE_NONE = "none" |
353 | 353 |
VALUE_TRUE = "true" |
354 | 354 |
VALUE_FALSE = "false" |
355 |
VALUE_HS_NOTHING = {"Nothing": None} |
|
356 |
|
|
355 | 357 |
|
356 | 358 |
# External script validation mask |
357 | 359 |
EXT_PLUGIN_MASK = re.compile("^[a-zA-Z0-9_-]+$") |
b/lib/utils/__init__.py | ||
---|---|---|
98 | 98 |
|
99 | 99 |
if ktype in (constants.VTYPE_STRING, constants.VTYPE_MAYBE_STRING): |
100 | 100 |
if target[key] is None and ktype == constants.VTYPE_MAYBE_STRING: |
101 |
msg = "'None' is not a valid Maybe value. Use 'VALUE_HS_NOTHING'" |
|
102 |
raise errors.TypeEnforcementError(msg) |
|
103 |
elif (target[key] == constants.VALUE_HS_NOTHING |
|
104 |
and ktype == constants.VTYPE_MAYBE_STRING): |
|
101 | 105 |
pass |
102 | 106 |
elif not isinstance(target[key], basestring): |
103 | 107 |
if isinstance(target[key], bool) and not target[key]: |
b/test/py/ganeti.utils_unittest.py | ||
---|---|---|
192 | 192 |
self.assertEqual(self._fdt({"b": "True"}), {"b": True}) |
193 | 193 |
self.assertEqual(self._fdt({"d": "4"}), {"d": 4}) |
194 | 194 |
self.assertEqual(self._fdt({"d": "4M"}), {"d": 4}) |
195 |
self.assertEqual(self._fdt({"e": None, }), {"e": None, }) |
|
195 |
self.assertEqual(self._fdt({"e": constants.VALUE_HS_NOTHING, }), {"e": |
|
196 |
constants.VALUE_HS_NOTHING, }) |
|
196 | 197 |
self.assertEqual(self._fdt({"e": "Hello World", }), {"e": "Hello World", }) |
197 | 198 |
self.assertEqual(self._fdt({"e": False, }), {"e": "", }) |
198 | 199 |
self.assertEqual(self._fdt({"b": "hello", }, ["hello"]), {"b": "hello"}) |
Also available in: Unified diff