devserver: Fix linter errors

Also remove devserver_exception.py as there was no user except devserver
itself.

BUG=chromium:1003986
TEST=./devserver_integration_test.py

Change-Id: Idf5289371bbe17c57fbbdb5de445e083281bd62c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1838133
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 bb89bff..547a12a 100755
--- a/devserver.py
+++ b/devserver.py
@@ -24,7 +24,6 @@
 
 from __future__ import print_function
 
-import httplib
 import json
 import optparse  # pylint: disable=deprecated-module
 import os
@@ -39,11 +38,13 @@
 import types
 from logging import handlers
 
+from six.moves import http_client
+
+# pylint: disable=no-name-in-module, import-error
 import cherrypy
-# pylint: disable=no-name-in-module
 from cherrypy import _cplogging as cplogging
-from cherrypy.process import plugins  # pylint: disable=import-error
-# pylint: enable=no-name-in-module
+from cherrypy.process import plugins
+# pylint: enable=no-name-in-module, import-error
 
 # This must happen before any local modules get a chance to import
 # anything from chromite.  Otherwise, really bad things will happen, and
@@ -56,7 +57,6 @@
 import cherrypy_ext
 import common_util
 import devserver_constants
-import devserver_exceptions
 import downloader
 import health_checker
 import log_util
@@ -83,7 +83,7 @@
 
 try:
   import android_build
-except ImportError as e:
+except ImportError:
   # Ignore android_build import failure. This is to support devserver running
   # inside a ChromeOS device triggered by cros flash. Most ChromeOS test images
   # do not have google-api-python-client module and they don't need to support
@@ -120,6 +120,10 @@
 AUTO_UPDATE_CMD = '/usr/bin/python -u %s -d %s -b %s --static_dir %s'
 
 
+class DevServerError(Exception):
+  """Exception class used by DevServer."""
+
+
 def _canonicalize_archive_url(archive_url):
   """Canonicalizes archive_url strings.
 
@@ -128,13 +132,12 @@
   """
   if archive_url:
     if not archive_url.startswith('gs://'):
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           "Archive URL isn't from Google Storage (%s) ." % archive_url)
 
     return archive_url.rstrip('/')
   else:
-    raise devserver_exceptions.DevServerError(
-        "Must specify an archive_url in the request")
+    raise DevServerError('Must specify an archive_url in the request')
 
 
 def _canonicalize_local_path(local_path):
@@ -147,7 +150,7 @@
   # directory.
   local_path = os.path.abspath(local_path)
   if not local_path.startswith(updater.static_dir):
-    raise devserver_exceptions.DevServerError(
+    raise DevServerError(
         'Local path %s must be a subdirectory of the static'
         ' directory: %s' % (local_path, updater.static_dir))
 
@@ -163,7 +166,7 @@
   artifacts = kwargs.get('artifacts')
   files = kwargs.get('files')
   if not artifacts and not files:
-    raise devserver_exceptions.DevServerError('No artifacts specified.')
+    raise DevServerError('No artifacts specified.')
 
   # Note we NEED to coerce files to a string as we get raw unicode from
   # cherrypy and we treat files as strings elsewhere in the code.
@@ -207,10 +210,10 @@
   if not _is_android_build_request(kwargs):
     archive_url = kwargs.get('archive_url')
     if not archive_url and not local_path:
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           'Requires archive_url or local_path to be specified.')
     if archive_url and local_path:
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           'archive_url and local_path can not both be specified.')
     if not dl:
       archive_url = _canonicalize_archive_url(archive_url)
@@ -223,9 +226,8 @@
     branch = kwargs.get('branch', None)
     build_id = kwargs.get('build_id', None)
     if not target or not branch or not build_id:
-      raise devserver_exceptions.DevServerError(
-          'target, branch, build ID must all be specified for downloading '
-          'Android build.')
+      raise DevServerError('target, branch, build ID must all be specified for '
+                           'downloading Android build.')
     dl = downloader.AndroidBuildDownloader(updater.static_dir, branch, build_id,
                                            target)
 
@@ -247,7 +249,7 @@
   elif isinstance(dl, downloader.AndroidBuildDownloader):
     factory_class = build_artifact.AndroidArtifactFactory
   else:
-    raise devserver_exceptions.DevServerError(
+    raise DevServerError(
         'Unrecognized value for downloader type: %s' % type(dl))
 
   factory = factory_class(dl.GetBuildDir(), artifacts, files, dl.GetBuild())
@@ -450,11 +452,11 @@
     DevServerHTTPError if required parameters don't exist in kwargs.
   """
   if 'host_name' not in kwargs:
-    raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+    raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                          KEY_ERROR_MSG % 'host_name')
 
   if 'build_name' not in kwargs:
-    raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+    raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                          KEY_ERROR_MSG % 'build_name')
 
 
@@ -478,7 +480,7 @@
       return False
     else:
       raise common_util.DevServerHTTPError(
-          httplib.INTERNAL_SERVER_ERROR,
+          http_client.INTERNAL_SERVER_ERROR,
           'The value for key %s is not boolean.' % key)
   else:
     return False
@@ -580,13 +582,12 @@
     """
     file_path = os.path.join(updater.static_dir, *args)
     if not os.path.exists(file_path):
-      raise devserver_exceptions.DevServerError(
-          'file not found: %s' % file_path)
+      raise DevServerError('file not found: %s' % file_path)
     try:
       file_size = os.path.getsize(file_path)
       file_sha256 = common_util.GetFileSha256(file_path)
     except os.error, e:
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           'failed to get info for file %s: %s' % (file_path, e))
 
     return json.dumps({
@@ -876,11 +877,11 @@
               string otherwise.
     """
     if 'host_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'host_name')
 
     if 'pid' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'pid')
 
     host_name = kwargs['host_name']
@@ -926,11 +927,11 @@
         pid: the background process id of cros-update.
     """
     if 'host_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'host_name')
 
     if 'pid' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'pid')
 
     host_name = kwargs['host_name']
@@ -953,11 +954,11 @@
         pid: the background process id of cros-update.
     """
     if 'host_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'host_name')
 
     if 'pid' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'pid')
 
     host_name = kwargs['host_name']
@@ -977,7 +978,7 @@
       True if all processes are killed properly.
     """
     if 'host_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'host_name')
 
     cur_pid = kwargs.get('pid')
@@ -1010,11 +1011,11 @@
       A dictionary containing the execute log file and any hostlog files.
     """
     if 'host_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'host_name')
 
     if 'pid' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            KEY_ERROR_MSG % 'pid')
 
     host_name = kwargs['host_name']
@@ -1049,7 +1050,7 @@
       file_name = kwargs['file_name']
       artifacts = kwargs['artifacts']
     except KeyError:
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           '`file_name` and `artifacts` are required to search '
           'for a file in build artifacts.')
     build_path = dl.GetBuildDir()
@@ -1062,7 +1063,7 @@
       for root, _, filenames in os.walk(artifact_path):
         if file_name in set([f for f in filenames]):
           return os.path.relpath(os.path.join(root, file_name), build_path)
-    raise devserver_exceptions.DevServerError(
+    raise DevServerError(
         'File `%s` can not be found in artifacts: %s' % (file_name, artifacts))
 
   @cherrypy.expose
@@ -1102,7 +1103,7 @@
           common_util.ExtractTarball(dep_path, telemetry_path)
         except common_util.CommonUtilError as e:
           shutil.rmtree(telemetry_path)
-          raise devserver_exceptions.DevServerError(str(e))
+          raise DevServerError(str(e))
 
       # By default all the tarballs extract to test_src but some parts of
       # the telemetry code specifically hardcoded to exist inside of 'src'.
@@ -1112,7 +1113,7 @@
       except shutil.Error:
         # This can occur if src_folder already exists. Remove and retry move.
         shutil.rmtree(src_folder)
-        raise devserver_exceptions.DevServerError(
+        raise DevServerError(
             'Failure in telemetry setup for build %s. Appears that the '
             'test_src to src move failed.' % dl.GetBuild())
 
@@ -1143,7 +1144,7 @@
       except build_artifact.ArtifactDownloadError:
         continue
     else:
-      raise devserver_exceptions.DevServerError(
+      raise DevServerError(
           'Failed to stage symbols for %s' % dl.DescribeSource())
 
     to_return = ''
@@ -1165,7 +1166,7 @@
 
       to_return, error_text = stackwalk.communicate()
       if stackwalk.returncode != 0:
-        raise devserver_exceptions.DevServerError(
+        raise DevServerError(
             "Can't generate stack trace: %s (rc=%d)" % (error_text,
                                                         stackwalk.returncode))
 
@@ -1190,16 +1191,15 @@
       return _PrintDocStringAsHTML(self.latestbuild)
 
     if 'target' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            'Error: target= is required!')
 
     if _is_android_build_request(kwargs):
       branch = kwargs.get('branch', None)
       target = kwargs.get('target', None)
       if not target or not branch:
-        raise devserver_exceptions.DevServerError(
-            'Both target and branch must be specified to query for the latest '
-            'Android build.')
+        raise DevServerError('Both target and branch must be specified to query'
+                             ' for the latest Android build.')
       return android_build.BuildAccessor.GetLatestBuildID(target, branch)
 
     try:
@@ -1207,7 +1207,7 @@
           updater.static_dir, kwargs['target'],
           milestone=kwargs.get('milestone'))
     except common_util.CommonUtilError as errmsg:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            str(errmsg))
 
   @cherrypy.expose
@@ -1230,11 +1230,11 @@
       return _PrintDocStringAsHTML(self.controlfiles)
 
     if 'build' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            'Error: build= is required!')
 
     if 'suite_name' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            'Error: suite_name= is required!')
 
     control_file_list = [
@@ -1279,7 +1279,7 @@
       return _PrintDocStringAsHTML(self.controlfiles)
 
     if 'build' not in kwargs:
-      raise common_util.DevServerHTTPError(httplib.INTERNAL_SERVER_ERROR,
+      raise common_util.DevServerHTTPError(http_client.INTERNAL_SERVER_ERROR,
                                            'Error: build= is required!')
 
     if 'control_path' not in kwargs:
@@ -1374,7 +1374,7 @@
 
     if return_dir and relative_path:
       raise common_util.DevServerHTTPError(
-          httplib.INTERNAL_SERVER_ERROR,
+          http_client.INTERNAL_SERVER_ERROR,
           'Cannot specify both return_dir and relative_path')
 
     # For updates, we optimize downloading of test images.
@@ -1457,11 +1457,9 @@
     name = '/'.join(args)
     method = _GetExposedMethod(name)
     if not method:
-      raise devserver_exceptions.DevServerError(
-          "No exposed method named `%s'" % name)
+      raise DevServerError("No exposed method named `%s'" % name)
     if not method.__doc__:
-      raise devserver_exceptions.DevServerError(
-          "No documentation for exposed method `%s'" % name)
+      raise DevServerError("No documentation for exposed method `%s'" % name)
     return '<pre>\n%s</pre>' % method.__doc__
 
   @cherrypy.expose
@@ -1581,7 +1579,7 @@
   group.add_option('--clear_cache',
                    action='store_true', default=False,
                    help='At startup, removes all cached entries from the'
-                   'devserver\'s cache.')
+                   "devserver's cache.")
   group.add_option('--logfile',
                    metavar='PATH',
                    help='log output to this file instead of stdout')