- add the possibility to set AUTOTEST_USER to an other user than the current
one for RPC authentication. For the moment, authentication is not used but in
case of...
- When web  server responds but return an error, the command simply failed
without explicitly giving the HTTP code. With this patch, the command prints
the HTTP error and exits.

From: Jean Parpaillon <[email protected]>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2511 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/rpc.py b/cli/rpc.py
index cefe270..246074c 100755
--- a/cli/rpc.py
+++ b/cli/rpc.py
@@ -31,11 +31,14 @@
         self.web_server = get_autotest_server(web_server)
         self.proxy = self._connect(rpc_path)
 
+
     def _connect(self, rpc_path):
         # This does not fail even if the address is wrong.
         # We need to wait for an actual RPC to fail
         if self.username:
             username = self.username
+        elif 'AUTOTEST_USER' in os.environ:
+            username = os.environ['AUTOTEST_USER']
         else:
             username = getpass.getuser()
         headers = {'AUTHORIZATION' : username}
diff --git a/cli/topic_common.py b/cli/topic_common.py
index e6750db..3281ad7 100755
--- a/cli/topic_common.py
+++ b/cli/topic_common.py
@@ -398,9 +398,14 @@
             try:
                 return self.afe.run(op, **data)
             except urllib2.URLError, err:
-                if 'timed out' not in err.reason:
-                    self.invalid_syntax('Invalid server name %s: %s' %
-                                        (self.afe.web_server, err))
+                if hasattr(err, 'reason'):
+                    if 'timed out' not in err.reason:
+                        self.invalid_syntax('Invalid server name %s: %s' %
+                                            (self.afe.web_server, err))
+                if hasattr(err, 'code'):
+                    self.failure(str(err), item=item,
+                                 what_failed=("Error received from web server"))
+                    raise CliError("Error from web server")
                 if self.debug:
                     print 'retrying: %r %d' % (data, retry)
                 retry -= 1