faft: Catch the explicit error when connecting to RPC server
The original catching all exceptions may hide bugs and make us hard to find
the reason of failure. This CL is to catch the explicit errors which are
raised when RPC server does not start fast enough. It also prints the detail
error messages.
BUG=None
TEST=Run a FAFT test and pass.
Change-Id: Iaa007907a195ee414875ebef5f9d8c7827b32f4e
Reviewed-on: https://gerrit.chromium.org/gerrit/37430
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Ready: Tom Wai-Hong Tam <waihong@chromium.org>
Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
diff --git a/server/cros/servo_test.py b/server/cros/servo_test.py
index 900dde8..323d886 100644
--- a/server/cros/servo_test.py
+++ b/server/cros/servo_test.py
@@ -217,6 +217,7 @@
# Poll for client RPC server to come online.
timeout = 20
succeed = False
+ error = None
while timeout > 0 and not succeed:
time.sleep(1)
try:
@@ -224,10 +225,18 @@
polling_rpc = getattr(remote_object, info['polling_rpc'])
polling_rpc()
succeed = True
- except:
+ except (socket.error, xmlrpclib.ProtocolError) as e:
+ # The client RPC server may not come online fast enough. Retry.
timeout -= 1
+ error = e
if not succeed:
+ if isinstance(error, xmlrpclib.ProtocolError):
+ logging.info("A protocol error occurred")
+ logging.info("URL: %s", error.url)
+ logging.info("HTTP/HTTPS headers: %s", error.headers)
+ logging.info("Error code: %d", error.errcode)
+ logging.info("Error message: %s", error.errmsg)
if 'remote_log_file' in info:
p = subprocess.Popen([
'ssh -n -q %s root@%s \'cat %s\'' % (info['ssh_config'],