On Mon, Dec 13, 2010 at 4:26 PM, Michael Hanselmann <[email protected]> wrote: > --- > qa/ganeti-qa.py | 4 ++++ > qa/qa_instance.py | 5 +++++ > qa/qa_node.py | 5 +++++ > qa/qa_utils.py | 31 +++++++++++++++++++++++++++++++ > 4 files changed, 45 insertions(+), 0 deletions(-) > > diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py > index 41dc3f9..4b87db7 100755 > --- a/qa/ganeti-qa.py > +++ b/qa/ganeti-qa.py > @@ -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) > > > diff --git a/qa/qa_instance.py b/qa/qa_instance.py > index 0b27e11..cb598de 100644 > --- a/qa/qa_instance.py > +++ b/qa/qa_instance.py > @@ -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"]]) > diff --git a/qa/qa_node.py b/qa/qa_node.py > index ed7c950..6e3e0a7 100644 > --- a/qa/qa_node.py > +++ b/qa/qa_node.py > @@ -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()) > diff --git a/qa/qa_utils.py b/qa/qa_utils.py > index 112e2ce..6a8ed18 100644 > --- a/qa/qa_utils.py > +++ b/qa/qa_utils.py > @@ -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: > -- > 1.7.3.1
LGTM > >
