Added a longer timeout to host job and host stat, as they do not
inherit from atest_list.

Added a --max-query option (default 20) to limit the number of jobs displayed.

Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@1977 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/host.py b/cli/host.py
index a2de6d8..06826ed 100755
--- a/cli/host.py
+++ b/cli/host.py
@@ -27,7 +27,7 @@
 
 """
 
-import os, sys
+import os, sys, socket
 from autotest_lib.cli import topic_common, action_common
 
 
@@ -153,6 +153,7 @@
     usage_action = 'stat'
 
     def execute(self):
+        socket.setdefaulttimeout(topic_common.LIST_SOCKET_TIMEOUT)
         results = []
         # Convert wildcards into real host stats.
         existing_hosts = []
@@ -197,7 +198,23 @@
     """atest host jobs --mlist <file>|<hosts>"""
     usage_action = 'jobs'
 
+    def __init__(self):
+        super(host_jobs, self).__init__()
+        self.parser.add_option('-q', '--max-query',
+                               help='Limits the number of results '
+                               '(20 by default)',
+                               type='int', default=20)
+
+
+    def parse(self):
+        """Consume the specific options"""
+        (options, leftover) = super(host_jobs, self).parse(req_items=None)
+        self.max_queries = options.max_query
+        return (options, leftover)
+
+
     def execute(self):
+        socket.setdefaulttimeout(topic_common.LIST_SOCKET_TIMEOUT)
         results = []
         real_hosts = []
         for host in self.hosts:
@@ -213,7 +230,8 @@
 
         for host in real_hosts:
             queue_entries = self.execute_rpc('get_host_queue_entries',
-                                             host__hostname=host)
+                                             host__hostname=host,
+                                             query_limit=self.max_queries)
             queue_entries.sort(key=lambda qe: qe['job']['id'])
             queue_entries.reverse()
             jobs = []