Commit e571ee44 authored by Adeodato Simo's avatar Adeodato Simo
Browse files

ganeti.query_unittest.py: test lock fields too



Additionally, change TestQueryFields.testSomeFields() to handle lists of
fields shorter than 20 elements.
Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent b98bb41e
......@@ -1072,3 +1072,6 @@ INSTANCE_FIELDS = _BuildInstanceFields()
#: Fields available for lock queries
LOCK_FIELDS = _BuildLockFields()
#: All available field lists
ALL_FIELD_LISTS = [NODE_FIELDS, INSTANCE_FIELDS, LOCK_FIELDS]
......@@ -763,7 +763,7 @@ class TestInstanceQuery(unittest.TestCase):
class TestQueryFields(unittest.TestCase):
def testAllFields(self):
for fielddefs in [query.NODE_FIELDS, query.INSTANCE_FIELDS]:
for fielddefs in query.ALL_FIELD_LISTS:
result = query.QueryFields(fielddefs, None)
self.assert_(isinstance(result, dict))
response = objects.QueryFieldsResponse.FromDict(result)
......@@ -776,10 +776,13 @@ class TestQueryFields(unittest.TestCase):
rnd = random.Random(5357)
for _ in range(10):
for fielddefs in [query.NODE_FIELDS, query.INSTANCE_FIELDS]:
fields = [fdef
for (fdef, _, _) in rnd.sample(fielddefs.values(),
rnd.randint(5, 20))]
for fielddefs in query.ALL_FIELD_LISTS:
if len(fielddefs) > 20:
sample_size = rnd.randint(5, 20)
else:
sample_size = rnd.randint(1, max(1, len(fielddefs) - 1))
fields = [fdef for (fdef, _, _) in rnd.sample(fielddefs.values(),
sample_size)]
result = query.QueryFields(fielddefs, [fdef.name for fdef in fields])
self.assert_(isinstance(result, dict))
response = objects.QueryFieldsResponse.FromDict(result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment