Revision e2d188cc test/ganeti.query_unittest.py
b/test/ganeti.query_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010 Google Inc. |
|
4 |
# Copyright (C) 2010, 2011 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
56 | 56 |
def _GetDiskSize(nr, ctx, item): |
57 | 57 |
disks = item["disks"] |
58 | 58 |
try: |
59 |
return (constants.QRFS_NORMAL, disks[nr])
|
|
59 |
return disks[nr]
|
|
60 | 60 |
except IndexError: |
61 |
return (constants.QRFS_UNAVAIL, None)
|
|
61 |
return query._FS_UNAVAIL
|
|
62 | 62 |
|
63 | 63 |
|
64 | 64 |
class TestQuery(unittest.TestCase): |
... | ... | |
67 | 67 |
|
68 | 68 |
fielddef = query._PrepareFieldList([ |
69 | 69 |
(query._MakeField("name", "Name", constants.QFT_TEXT), |
70 |
STATIC, lambda ctx, item: (constants.QRFS_NORMAL, item["name"])),
|
|
70 |
STATIC, lambda ctx, item: item["name"]),
|
|
71 | 71 |
(query._MakeField("master", "Master", constants.QFT_BOOL), |
72 |
STATIC, lambda ctx, item: (constants.QRFS_NORMAL, |
|
73 |
ctx.mastername == item["name"])), |
|
72 |
STATIC, lambda ctx, item: ctx.mastername == item["name"]), |
|
74 | 73 |
] + |
75 | 74 |
[(query._MakeField("disk%s.size" % i, "DiskSize%s" % i, |
76 | 75 |
constants.QFT_UNIT), |
... | ... | |
215 | 214 |
def testUnknown(self): |
216 | 215 |
fielddef = query._PrepareFieldList([ |
217 | 216 |
(query._MakeField("name", "Name", constants.QFT_TEXT), |
218 |
None, lambda _, item: (constants.QRFS_NORMAL, "name%s" % item)),
|
|
217 |
None, lambda _, item: "name%s" % item),
|
|
219 | 218 |
(query._MakeField("other0", "Other0", constants.QFT_TIMESTAMP), |
220 |
None, lambda *args: (constants.QRFS_NORMAL, 1234)),
|
|
219 |
None, lambda *args: 1234),
|
|
221 | 220 |
(query._MakeField("nodata", "NoData", constants.QFT_NUMBER), |
222 |
None, lambda *args: (constants.QRFS_NODATA, None)),
|
|
221 |
None, lambda *args: query._FS_NODATA ),
|
|
223 | 222 |
(query._MakeField("unavail", "Unavail", constants.QFT_BOOL), |
224 |
None, lambda *args: (constants.QRFS_UNAVAIL, None)),
|
|
223 |
None, lambda *args: query._FS_UNAVAIL),
|
|
225 | 224 |
]) |
226 | 225 |
|
227 | 226 |
for selected in [["foo"], ["Hello", "World"], |
... | ... | |
461 | 460 |
nqd = query.NodeQueryData(None, None, None, None, None, None, None, None) |
462 | 461 |
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER, |
463 | 462 |
nqd, nodes[0]), |
464 |
(constants.QRFS_NODATA, None))
|
|
463 |
query._FS_NODATA)
|
|
465 | 464 |
|
466 | 465 |
# Missing field |
467 | 466 |
ctx = _QueryData(None, curlive_data={ |
... | ... | |
470 | 469 |
}) |
471 | 470 |
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER, |
472 | 471 |
ctx, nodes[0]), |
473 |
(constants.QRFS_UNAVAIL, None))
|
|
472 |
query._FS_UNAVAIL)
|
|
474 | 473 |
|
475 | 474 |
# Wrong format/datatype |
476 | 475 |
ctx = _QueryData(None, curlive_data={ |
... | ... | |
479 | 478 |
}) |
480 | 479 |
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER, |
481 | 480 |
ctx, nodes[0]), |
482 |
(constants.QRFS_UNAVAIL, None))
|
|
481 |
query._FS_UNAVAIL)
|
|
483 | 482 |
|
484 | 483 |
# Offline node |
485 | 484 |
assert nodes[3].offline |
486 | 485 |
ctx = _QueryData(None, curlive_data={}) |
487 | 486 |
self.assertEqual(query._GetLiveNodeField("hello", constants.QFT_NUMBER, |
488 | 487 |
ctx, nodes[3]), |
489 |
(constants.QRFS_OFFLINE, None))
|
|
488 |
query._FS_OFFLINE, None)
|
|
490 | 489 |
|
491 | 490 |
# Wrong field type |
492 | 491 |
ctx = _QueryData(None, curlive_data={"hello": 123}) |
Also available in: Unified diff