Revert "devserver: Stop patching devserver internals for port=0"

This reverts commit 0ee73f408b6fa66b1f7defadb1073ff051567010.

In addition, this makes hacking --port=0 on cherrypy conditional on the
version of the cherrypy. The reason we need this is that our devservers
run on older linux and their cherrypy can't be upreved easily. But for
Chrome OS we have already upreved cherrypy and we don't need this
hacking.

There are also other pylint errors fixed.

BUG=chromium:1018237
TEST=devserver_integration_test

Change-Id: If65b75deb565ca78353803c8eab3f7cfc3851e5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1914538
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/cherrypy_ext_unittest.py b/cherrypy_ext_unittest.py
index 12d0fce..ce36f7e 100755
--- a/cherrypy_ext_unittest.py
+++ b/cherrypy_ext_unittest.py
@@ -6,11 +6,13 @@
 
 """Unit tests for cherrypy_ext."""
 
-import cherrypy
+from __future__ import print_function
+
 import tempfile
 import unittest
 
-import mox
+import mox  # pylint: disable=import-error
+import cherrypy  # pylint: disable=import-error
 
 import cherrypy_ext
 
@@ -46,5 +48,32 @@
 
     self.mox.VerifyAll()
 
+  def testZeroPortPatcherSuccess(self):
+    """Make sure that ZeroPatcher successfully patches CherryPy.
+
+    This merely ensures that the patcher applies cleanly to the CherryPy
+    version available to the test environment, giving us some assurance that
+    it's still compatible with the range of versions that we might be using it
+    with.  The actual testing of the arbitrary port binding feature is covered
+    by integration tests.
+    """
+    self.assertIsNone(cherrypy_ext.ZeroPortPatcher.DoPatch(cherrypy))
+
+  def testZeroPortPatcherFailure(self):
+    """Make sure that ZeroPatcher fails with an incompatible CherryPy.
+
+    This ensures that the patcher fails when applied to a CherryPy version that
+    does not have the desired properties.
+    """
+    module = cherrypy.process.servers
+    func_name = 'wait_for_free_port'
+    orig_func = getattr(module, func_name, None)
+    self.assertTrue(orig_func)
+    delattr(module, func_name)
+    self.assertRaises(AttributeError, cherrypy_ext.ZeroPortPatcher.DoPatch,
+                      cherrypy)
+    setattr(module, func_name, orig_func)
+
+
 if __name__ == '__main__':
   unittest.main()