summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2012-05-25 11:52:33 (GMT)
committerGerrit <chrome-bot@google.com>2012-05-28 05:16:49 (GMT)
commitcbb0df82e535c672dedf34ff19f2fb08a20842b2 (patch)
tree4f614302d429083b5f6ffbdeb2498d91d5e0c261
parentdff537d7d7a63b2c5df073bdd2abbf9fd890bcef (diff)
downloadautotest-cbb0df82e535c672dedf34ff19f2fb08a20842b2.tar.gz
autotest-cbb0df82e535c672dedf34ff19f2fb08a20842b2.tar.xz
factory: Improve shopfloor server error message.
Autotest seems not able to pickle xmlrpclib.Fault properly and will generate unexpected error messages, so we need to always catch and re-interprete shopfloor server error. BUG=none TEST=Manually input invalid serial number and run factory_HWID, seeing proper error messages. Change-Id: I6d5bdf17a17ed3d337acdb04d5a524f7c8eff7fd Reviewed-on: https://gerrit.chromium.org/gerrit/23638 Commit-Ready: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org> Tested-by: Hung-Te Lin <hungte@chromium.org>
-rw-r--r--client/cros/factory/shopfloor.py31
-rwxr-xr-xclient/site_tests/factory_Start/factory_Start.py6
2 files changed, 33 insertions, 4 deletions
diff --git a/client/cros/factory/shopfloor.py b/client/cros/factory/shopfloor.py
index bb68ade..4657c35 100644
--- a/client/cros/factory/shopfloor.py
+++ b/client/cros/factory/shopfloor.py
@@ -20,6 +20,7 @@ For the protocol details, check:
src/platform/factory-utils/factory_setup/shopfloor_server.
"""
+import logging
import os
import urlparse
import xmlrpclib
@@ -50,6 +51,28 @@ _DEFAULT_SERVER_PORT = 8082
SHOPFLOOR_SERVER_ENV_VAR_NAME = 'CROS_SHOPFLOOR_SERVER_URL'
# ----------------------------------------------------------------------------
+# Exception Types
+
+class ServerFault(Exception):
+ pass
+
+
+def _server_api(call):
+ """Decorator of calls to remote server.
+
+ Converts xmlrpclib.Fault generated during remote procedural call to better
+ and simplified form (shopfloor.ServerFault).
+ """
+ def wrapped_call(*args, **kargs):
+ try:
+ return call(*args, **kargs)
+ except xmlrpclib.Fault as e:
+ logging.exception('Shopfloor server:')
+ raise ServerFault(e.faultString.partition(':')[2])
+ wrapped_call.__name__ = call.__name__
+ return wrapped_call
+
+# ----------------------------------------------------------------------------
# Utility Functions
def _fetch_current_session():
@@ -144,6 +167,7 @@ def get_instance(url=None):
return xmlrpclib.ServerProxy(url, allow_none=True, verbose=False)
+@_server_api
def check_server_status(instance=None):
"""Checks if the given instance is successfully connected.
@@ -165,32 +189,38 @@ def check_server_status(instance=None):
# floor system (see src/platform/factory-utils/factory_setup/shopfloor/*).
+@_server_api
def set_serial_number(serial_number):
"""Sets a serial number as pinned in factory shared data."""
_set_session(SESSION_SERIAL_NUMBER, serial_number)
+@_server_api
def get_serial_number():
"""Gets current pinned serial number from factory shared data."""
return _get_session(SESSION_SERIAL_NUMBER)
+@_server_api
def check_serial_number(serial_number):
"""Checks if given serial number is valid."""
# Use GetHWID to check serial number.
return get_instance().GetHWID(serial_number)
+@_server_api
def get_hwid():
"""Gets HWID associated with current pinned serial number."""
return get_instance().GetHWID(get_serial_number())
+@_server_api
def get_vpd():
"""Gets VPD associated with current pinned serial number."""
return get_instance().GetVPD(get_serial_number())
+@_server_api
def upload_report(blob, name=None):
"""Uploads a report (generated by gooftool) to shop floor server.
@@ -202,6 +232,7 @@ def upload_report(blob, name=None):
get_instance().UploadReport(get_serial_number(), Binary(blob), name)
+@_server_api
def finalize():
"""Notifies shop floor server this DUT has finished testing."""
get_instance().Finalize(get_serial_number())
diff --git a/client/site_tests/factory_Start/factory_Start.py b/client/site_tests/factory_Start/factory_Start.py
index 250cfa9..ce7291a 100755
--- a/client/site_tests/factory_Start/factory_Start.py
+++ b/client/site_tests/factory_Start/factory_Start.py
@@ -145,10 +145,8 @@ class ShopFloorTask(task.FactoryTask):
# All exceptions
shopfloor.check_serial_number(serial.strip())
return True
- except shopfloor.Fault as e:
- logging.exception("ServerFault:")
- raise ui.InputError("Server error:\n%s" %
- e.faultString.partition(':')[2])
+ except shopfloor.ServerFault as e:
+ raise ui.InputError("Server error:\n%s" % e)
except ValueError as e:
logging.exception("ValueError:")
raise ui.InputError(e.message)