Better error handling and message when the (site) authentication didn't work.

Signed-off-by: Jean-Marc Eurin <[email protected]>

--- autotest/cli/rpc.py 2010-03-10 15:23:28.000000000 -0800
+++ autotest/cli/rpc.py 2010-03-10 15:23:28.000000000 -0800
@@ -13,6 +13,10 @@
 TKO_RPC_PATH = '/new_tko/server/rpc/'
 
 
+class AuthError(Exception):
+    pass
+
+
 def get_autotest_server(web_server=None):
     if not web_server:
         if 'AUTOTEST_WEB' in os.environ:
@@ -34,7 +38,10 @@
     def __init__(self, web_server, rpc_path, username):
         self.username = username
         self.web_server = get_autotest_server(web_server)
-        self.proxy = self._connect(rpc_path)
+        try:
+            self.proxy = self._connect(rpc_path)
+        except rpc_client_lib.AuthError, s:
+            raise AuthError(s)
 
 
     def _connect(self, rpc_path):
--- autotest/cli/topic_common.py        2010-03-10 15:23:28.000000000 -0800
+++ autotest/cli/topic_common.py        2010-03-10 15:23:28.000000000 -0800
@@ -269,7 +269,7 @@
         return [item.strip() for item in parts[2].split(',') if item.strip()]
 
 
-    def failure(self, full_error, item=None, what_failed=''):
+    def failure(self, full_error, item=None, what_failed='', fatal=False):
         """If kill_on_failure, print this error and die,
         otherwise, queue the error and accumulate all the items
         that triggered the same error."""
@@ -279,7 +279,7 @@
         else:
             errmsg = str(full_error).split('Traceback')[0].rstrip('\n')
 
-        if self.kill_on_failure:
+        if self.kill_on_failure or fatal:
             print >> sys.stderr, "%s\n    %s" % (what_failed, errmsg)
             sys.exit(1)
 
@@ -428,7 +428,10 @@
 
         self.verbose = options.verbose
         self.web_server = options.web_server
-        self.afe = rpc.afe_comm(self.web_server)
+        try:
+            self.afe = rpc.afe_comm(self.web_server)
+        except rpc.AuthError, s:
+            self.failure(str(s), fatal=True)
 
         return (options, leftover)
 
--- autotest/frontend/afe/rpc_client_lib.py     2010-03-10 15:23:28.000000000 
-0800
+++ autotest/frontend/afe/rpc_client_lib.py     2010-03-10 15:23:28.000000000 
-0800
@@ -10,6 +10,10 @@
 from autotest_lib.client.common_lib import utils
 
 
+class AuthError(Exception):
+    pass
+
+
 def get_proxy(*args, **kwargs):
     """Use this to access the AFE or TKO RPC interfaces."""
     return proxy.ServiceProxy(*args, **kwargs)
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to