Commit 2214cf14 authored by Michael Hanselmann's avatar Michael Hanselmann

QA: Extend unittests for query operations, add tests for list-fields

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent d7a08491
......@@ -138,6 +138,10 @@ def SetupCluster(rapi_user, rapi_secret):
RunTestIf("node-list", qa_node.TestNodeList)
# Test listing fields
RunTestIf("node-list", qa_node.TestNodeListFields)
RunTestIf("instance-list", qa_instance.TestInstanceListFields)
RunTestIf("node-info", qa_node.TestNodeInfo)
......
......@@ -213,6 +213,11 @@ def TestInstanceList():
qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
def TestInstanceListFields():
"""gnt-instance list-fields"""
qa_utils.GenericQueryFieldsTest("gnt-instance", query.INSTANCE_FIELDS.keys())
def TestInstanceConsole(instance):
"""gnt-instance console"""
AssertCommand(["gnt-instance", "console", "--show-cmd", instance["name"]])
......
......@@ -195,3 +195,8 @@ def TestNodeModify(node):
def TestNodeList():
"""gnt-node list"""
qa_utils.GenericQueryTest("gnt-node", query.NODE_FIELDS.keys())
def TestNodeListFields():
"""gnt-node list-fields"""
qa_utils.GenericQueryFieldsTest("gnt-node", query.NODE_FIELDS.keys())
......@@ -31,6 +31,7 @@ import random
from ganeti import utils
from ganeti import compat
from ganeti import constants
import qa_config
import qa_error
......@@ -139,6 +140,8 @@ def AssertCommand(cmd, fail=False, node=None):
raise qa_error.Error("Command '%s' on node %s failed, exit code %s" %
(cmdstr, nodename, rcode))
return rcode
def GetSSHCommand(node, cmd, strict=True):
"""Builds SSH command to be executed.
......@@ -352,6 +355,34 @@ def GenericQueryTest(cmd, fields):
rnd.shuffle(randnames)
AssertEqual(namelist_fn(randnames), randnames)
# Listing unknown items must fail
AssertCommand([cmd, "list", "this.name.certainly.does.not.exist"], fail=True)
# Check exit code for listing unknown field
AssertEqual(AssertCommand([cmd, "list", "--output=field/does/not/exist"],
fail=True),
constants.EXIT_UNKNOWN_FIELD)
def GenericQueryFieldsTest(cmd, fields):
master = qa_config.GetMasterNode()
# Listing fields
AssertCommand([cmd, "list-fields"])
AssertCommand([cmd, "list-fields"] + fields)
# Check listed fields (all, must be sorted)
realcmd = [cmd, "list-fields", "--separator=|", "--no-headers"]
output = GetCommandOutput(master["primary"],
utils.ShellQuoteArgs(realcmd)).splitlines()
AssertEqual([line.split("|", 1)[0] for line in output],
sorted(fields))
# Check exit code for listing unknown field
AssertEqual(AssertCommand([cmd, "list-fields", "field/does/not/exist"],
fail=True),
constants.EXIT_UNKNOWN_FIELD)
def _FormatWithColor(text, seq):
if not seq:
......
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