Commit 288d6440 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Improve tests for instance/node list

- Query all known fields
- Random combinations (using a PRNG with a fixed seed) of fields
- Order of result names
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent fcdf575b
......@@ -121,6 +121,11 @@ def SetupCluster(rapi_user, rapi_secret):
RunTestIf("create-cluster", qa_cluster.TestClusterInit,
rapi_user, rapi_secret)
# Test on empty cluster
RunTestIf("node-list", qa_node.TestNodeList)
RunTestIf("instance-list", qa_instance.TestInstanceList)
RunTestIf("create-cluster", qa_node.TestNodeAddAll)
if not qa_config.TestEnabled("create-cluster"):
# consider the nodes are already there
......@@ -131,6 +136,8 @@ def SetupCluster(rapi_user, rapi_secret):
# enable the watcher (unconditionally)
RunTestIf("node-list", qa_node.TestNodeList)
RunTestIf("node-info", qa_node.TestNodeInfo)
......@@ -217,6 +224,9 @@ def RunCommonInstanceTests(instance):
RunTestIf("rapi", qa_rapi.TestInstance, instance)
# Lists instances, too
RunTestIf("node-list", qa_node.TestNodeList)
def RunCommonNodeTests():
"""Run a few common node tests.
......@@ -65,6 +65,7 @@
"group-list": true,
"group-rwops": true,
"node-list": true,
"node-info": true,
"node-volumes": true,
"node-readd": true,
......@@ -28,6 +28,7 @@ import time
from ganeti import utils
from ganeti import constants
from ganeti import query
import qa_config
import qa_utils
......@@ -209,7 +210,7 @@ def TestInstanceConvertDisk(instance, snode):
def TestInstanceList():
"""gnt-instance list"""
AssertCommand(["gnt-instance", "list"])
qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
def TestInstanceConsole(instance):
......@@ -21,6 +21,7 @@
from ganeti import utils
from ganeti import constants
from ganeti import query
import qa_config
import qa_error
......@@ -189,3 +190,8 @@ def TestNodeModify(node):
AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
"--auto-promote", node["primary"]])
def TestNodeList():
"""gnt-node list"""
qa_utils.GenericQueryTest("gnt-node", query.NODE_FIELDS.keys())
......@@ -27,8 +27,10 @@ import os
import re
import sys
import subprocess
import random
from ganeti import utils
from ganeti import compat
import qa_config
import qa_error
......@@ -284,6 +286,73 @@ def GetNodeInstances(node, secondaries=False):
return instances
def _SelectQueryFields(rnd, fields):
"""Generates a list of fields for query tests.
# Create copy for shuffling
fields = list(fields)
# Check all fields
yield fields
yield sorted(fields)
# Duplicate fields
yield fields + fields
# Check small groups of fields
while fields:
yield [fields.pop() for _ in range(rnd.randint(2, 10)) if fields]
def _List(listcmd, fields, names):
"""Runs a list command.
master = qa_config.GetMasterNode()
cmd = [listcmd, "list", "--separator=|", "--no-header",
"--output", ",".join(fields)]
if names:
return GetCommandOutput(master["primary"],
def GenericQueryTest(cmd, fields):
"""Runs a number of tests on query commands.
@param cmd: Command name
@param fields: List of field names
rnd = random.Random(hash(cmd))
randfields = list(fields)
# Test a number of field combinations
for testfields in _SelectQueryFields(rnd, fields):
AssertCommand([cmd, "list", "--output", ",".join(testfields)])
namelist_fn = compat.partial(_List, cmd, ["name"])
# When no names were requested, the list must be sorted
names = namelist_fn(None)
AssertEqual(names, utils.NiceSort(names))
# When requesting specific names, the order must be kept
revnames = list(reversed(names))
AssertEqual(namelist_fn(revnames), revnames)
randnames = list(names)
AssertEqual(namelist_fn(randnames), randnames)
def _FormatWithColor(text, seq):
if not seq:
return text
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