devserver.py: Move DevServerHTTPError from common_util to devserver.py
There is no other use case for this error class except in devserver.py
itself. This is causing some issues with importing cherrypy, etc. in
chromite. So its better to be here.
BUG=chromium:1025057
TEST=devserver_integration_test.py
Change-Id: Icf08ac60e2a78dacf54cac808abdcdebdc4aa675
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1919646
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/devserver.py b/devserver.py
index 8478a44..dd54308 100755
--- a/devserver.py
+++ b/devserver.py
@@ -101,6 +101,19 @@
"""Exception class used by DevServer."""
+class DevServerHTTPError(cherrypy.HTTPError):
+ """Exception class to log the HTTPResponse before routing it to cherrypy."""
+ def __init__(self, status, message):
+ """CherryPy error with logging.
+
+ Args:
+ status: HTTPResponse status.
+ message: Message associated with the response.
+ """
+ cherrypy.HTTPError.__init__(self, status, message)
+ _Log('HTTPError status: %s message: %s', status, message)
+
+
def _canonicalize_archive_url(archive_url):
"""Canonicalizes archive_url strings.
@@ -429,12 +442,12 @@
DevServerHTTPError if required parameters don't exist in kwargs.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
if 'build_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'build_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'build_name')
def _parse_boolean_arg(kwargs, key):
@@ -456,9 +469,8 @@
elif kwargs[key] == 'False':
return False
else:
- raise common_util.DevServerHTTPError(
- http_client.INTERNAL_SERVER_ERROR,
- 'The value for key %s is not boolean.' % key)
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ 'The value for key %s is not boolean.' % key)
else:
return False
@@ -860,12 +872,12 @@
string otherwise.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
if 'pid' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'pid')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'pid')
host_name = kwargs['host_name']
pid = kwargs['pid']
@@ -910,12 +922,12 @@
pid: the background process id of cros-update.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
if 'pid' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'pid')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'pid')
host_name = kwargs['host_name']
pid = kwargs['pid']
@@ -937,12 +949,12 @@
pid: the background process id of cros-update.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
if 'pid' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'pid')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'pid')
host_name = kwargs['host_name']
pid = kwargs['pid']
@@ -961,8 +973,8 @@
True if all processes are killed properly.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
cur_pid = kwargs.get('pid')
@@ -994,12 +1006,12 @@
A dictionary containing the execute log file and any hostlog files.
"""
if 'host_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'host_name')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'host_name')
if 'pid' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- KEY_ERROR_MSG % 'pid')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ KEY_ERROR_MSG % 'pid')
host_name = kwargs['host_name']
pid = kwargs['pid']
@@ -1174,8 +1186,8 @@
return _PrintDocStringAsHTML(self.latestbuild)
if 'target' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- 'Error: target= is required!')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ 'Error: target= is required!')
if _is_android_build_request(kwargs):
branch = kwargs.get('branch', None)
@@ -1190,8 +1202,8 @@
updater.static_dir, kwargs['target'],
milestone=kwargs.get('milestone'))
except common_util.CommonUtilError as errmsg:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- str(errmsg))
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ str(errmsg))
@cherrypy.expose
def list_suite_controls(self, **kwargs):
@@ -1213,12 +1225,12 @@
return _PrintDocStringAsHTML(self.controlfiles)
if 'build' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- 'Error: build= is required!')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ 'Error: build= is required!')
if 'suite_name' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- 'Error: suite_name= is required!')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ 'Error: suite_name= is required!')
control_file_list = [
line.rstrip() for line in common_util.GetControlFileListForSuite(
@@ -1262,8 +1274,8 @@
return _PrintDocStringAsHTML(self.controlfiles)
if 'build' not in kwargs:
- raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
- 'Error: build= is required!')
+ raise DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
+ 'Error: build= is required!')
if 'control_path' not in kwargs:
if 'suite_name' in kwargs and kwargs['suite_name']:
@@ -1356,7 +1368,7 @@
relative_path = xbuddy.XBuddy.ParseBoolean(boolean_string)
if return_dir and relative_path:
- raise common_util.DevServerHTTPError(
+ raise DevServerHTTPError(
http_client.INTERNAL_SERVER_ERROR,
'Cannot specify both return_dir and relative_path')