summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorjadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4>2008-12-16 20:56:53 +0000
committerjadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4>2008-12-16 20:56:53 +0000
commit6df17b200ad08cb19873b01f281661d1e6362d7d (patch)
tree77bf1ef0d3446f266a20b5550166a48dc239c39c /cli
parent7383f0c4bef946dd0acb00f971cc73cf2dc48e1e (diff)
Add a query_keyvals script to the CLI to allow command-line queries of
test keyval data. Risk: Medium Visibility: Should not affect any other interfaces, add a new cli/query_keyvals script. Signed-off-by: John Admanski <jadmanski@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@2571 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'cli')
-rw-r--r--cli/query_keyvals74
1 files changed, 74 insertions, 0 deletions
diff --git a/cli/query_keyvals b/cli/query_keyvals
new file mode 100644
index 00000000..25f34640
--- /dev/null
+++ b/cli/query_keyvals
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+import sys, optparse
+import common
+from autotest_lib.cli import rpc
+
+
+def parse_options():
+ usage = "usage: %prog [options] job_id"
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option("-m", "--machine", dest="machine")
+ parser.add_option("-t", "--test", dest="test")
+ parser.add_option("-T", "--type", dest="type", type="choice",
+ choices=["all", "test", "iteration", "attr", "perf"])
+ parser.add_option("-k", "--key", dest="key")
+ parser.set_defaults(type="all")
+ options, args = parser.parse_args()
+ options.show_test_keyvals = options.type in ("all", "test")
+ options.show_attr_keyvals = options.type in ("all", "iteration", "attr")
+ options.show_perf_keyvals = options.type in ("all", "iteration", "perf")
+ options.show_iter_keyvals = (
+ options.show_perf_keyvals or options.show_attr_keyvals)
+ return parser, options, args
+
+
+def print_keyvals(keyval, format_string, options):
+ for key, value in keyval.iteritems():
+ if not options.key or key == options.key:
+ print format_string % (key, value)
+
+
+def print_views(test_views, options):
+ for view in test_views:
+ if not options.machine:
+ print "Machine: %s" % view["hostname"]
+ if not options.test:
+ print "Test: %s" % view["test_name"]
+ if options.show_test_keyvals:
+ print "Test Attributes:"
+ print_keyvals(view["attributes"], "\t%s = %s", options)
+ if options.show_iter_keyvals:
+ print "Iteration Attributes:"
+ for i, iteration in enumerate(view["iterations"]):
+ print "\tIteration #%d:" % (i + 1)
+ if options.show_attr_keyvals:
+ print_keyvals(iteration["attr"], "\t\t%s(attr) = %s",
+ options)
+ if options.show_perf_keyvals:
+ print_keyvals(iteration["perf"], "\t\t%s(perf) = %s",
+ options)
+ print
+
+
+def main():
+ parser, options, args = parse_options()
+ if len(args) != 1:
+ print "Invalid number of arguments"
+ print
+ parser.print_help()
+ sys.exit(1)
+
+ query_filter = {"job_tag__startswith": "%s-" % args[0]}
+ if options.machine:
+ query_filter["hostname"] = options.machine
+ if options.test:
+ query_filter["test_name"] = options.test
+
+ comm = rpc.tko_comm("dunsel")
+ test_views = comm.run("get_detailed_test_views", **query_filter)
+ print_views(test_views, options)
+
+
+if __name__ == "__main__":
+ main()