webkitpy: Standardize web-server port definitions
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2017 20:07:42 +0000 (20:07 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Mar 2017 20:07:42 +0000 (20:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170144
<rdar://problem/31284026>

Reviewed by Daniel Bates.

Default web-server ports should be declared in global variables.
Add functions to web-servers which return the ports these servers
are using so that other tools can forward them.

* Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
(LayoutTestApacheHttpd.__init__): Use shared constants in http_server_base.py.
* Scripts/webkitpy/layout_tests/servers/apache_http_server_unittest.py:
(TestLayoutTestApacheHttpd.test_start_cmd): Check port_to_forward for expected values.
* Scripts/webkitpy/layout_tests/servers/http_server.py:
(Lighttpd.__init__): Use shared constants in http_server_base.py.
(Lighttpd._prepare_config): Ditto.
* Scripts/webkitpy/layout_tests/servers/http_server_base.py:
(HttpServerBase): Add default port constants.
(HttpServerBase.ports_to_forward): Add function to return ports used for http server.
* Scripts/webkitpy/layout_tests/servers/http_server_unittest.py:
(TestHttpServer.test_start_cmd): Check port_to_forward for expected values.
* Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py:
 (WebPlatformTestServer.ports_to_forward): Add function to return ports used for web-platform tests.
* Scripts/webkitpy/layout_tests/servers/websocket_server.py:
(PyWebSocket): Make default port values public.
(PyWebSocket.__init__): Use public default port.
(PyWebSocket.ports_to_forward): Return port used in an array.
* Scripts/webkitpy/port/base.py:
(Port.to.ports_to_forward): Return all ports used the various web-servers managed by the port object.
(Port.to.start_websocket_server): Use PyWebSocket port constants.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214558 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server.py
Tools/Scripts/webkitpy/layout_tests/servers/apache_http_server_unittest.py
Tools/Scripts/webkitpy/layout_tests/servers/http_server.py
Tools/Scripts/webkitpy/layout_tests/servers/http_server_base.py
Tools/Scripts/webkitpy/layout_tests/servers/http_server_unittest.py
Tools/Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py
Tools/Scripts/webkitpy/layout_tests/servers/websocket_server.py
Tools/Scripts/webkitpy/port/base.py

index db85e3e..2f06513 100644 (file)
@@ -1,3 +1,37 @@
+2017-03-29  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: Standardize web-server port definitions
+        https://bugs.webkit.org/show_bug.cgi?id=170144
+        <rdar://problem/31284026>
+
+        Reviewed by Daniel Bates.
+
+        Default web-server ports should be declared in global variables.
+        Add functions to web-servers which return the ports these servers
+        are using so that other tools can forward them.
+
+        * Scripts/webkitpy/layout_tests/servers/apache_http_server.py:
+        (LayoutTestApacheHttpd.__init__): Use shared constants in http_server_base.py.
+        * Scripts/webkitpy/layout_tests/servers/apache_http_server_unittest.py:
+        (TestLayoutTestApacheHttpd.test_start_cmd): Check port_to_forward for expected values.
+        * Scripts/webkitpy/layout_tests/servers/http_server.py:
+        (Lighttpd.__init__): Use shared constants in http_server_base.py.
+        (Lighttpd._prepare_config): Ditto.
+        * Scripts/webkitpy/layout_tests/servers/http_server_base.py:
+        (HttpServerBase): Add default port constants.
+        (HttpServerBase.ports_to_forward): Add function to return ports used for http server.
+        * Scripts/webkitpy/layout_tests/servers/http_server_unittest.py:
+        (TestHttpServer.test_start_cmd): Check port_to_forward for expected values.
+        * Scripts/webkitpy/layout_tests/servers/web_platform_test_server.py:
+         (WebPlatformTestServer.ports_to_forward): Add function to return ports used for web-platform tests.
+        * Scripts/webkitpy/layout_tests/servers/websocket_server.py:
+        (PyWebSocket): Make default port values public.
+        (PyWebSocket.__init__): Use public default port.
+        (PyWebSocket.ports_to_forward): Return port used in an array.
+        * Scripts/webkitpy/port/base.py:
+        (Port.to.ports_to_forward): Return all ports used the various web-servers managed by the port object.
+        (Port.to.start_websocket_server): Use PyWebSocket port constants.
+
 2017-03-29  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Links with empty hrefs should not be drag sources
index f3ee1e3..755cf78 100644 (file)
@@ -56,9 +56,9 @@ class LayoutTestApacheHttpd(http_server_base.HttpServerBase):
         if self._port is not None:
             self._mappings = [{'port': self._port}]
         else:
-            self._mappings = [{'port': 8000},
-                              {'port': 8080},
-                              {'port': 8443, 'sslcert': True}]
+            self._mappings = [{'port': self.HTTP_SERVER_PORT},
+                              {'port': self.ALTERNATIVE_HTTP_SERVER_PORT},
+                              {'port': self.HTTPS_SERVER_PORT, 'sslcert': True}]
         self._output_dir = output_dir
         self._filesystem.maybe_make_directory(output_dir)
 
index c4240fc..d58f77b 100644 (file)
@@ -57,6 +57,9 @@ class TestLayoutTestApacheHttpd(unittest.TestCase):
         server._check_that_all_ports_are_available = lambda: True
         server._is_server_running_on_all_ports = lambda: True
         server._wait_for_action = fake_pid
+
+        self.assertEqual(server.ports_to_forward(), [8000, 8080, 8443])
+
         oc = OutputCapture()
         try:
             oc.capture_output()
index 69202e7..e6fa940 100644 (file)
@@ -75,9 +75,9 @@ class Lighttpd(http_server_base.HttpServerBase):
         if self._webkit_tests:
             self.VIRTUALCONFIG.extend(
                # Three mappings (one with SSL) for LayoutTests http tests
-               [{'port': 8000, 'docroot': self._webkit_tests},
-                {'port': 8080, 'docroot': self._webkit_tests},
-                {'port': 8443, 'docroot': self._webkit_tests,
+               [{'port': self.HTTP_SERVER_PORT, 'docroot': self._webkit_tests},
+                {'port': self.ALTERNATIVE_HTTP_SERVER_PORT, 'docroot': self._webkit_tests},
+                {'port': self.HTTPS_SERVER_PORT, 'docroot': self._webkit_tests,
                  'sslcert': self._pem_file}])
 
     def _prepare_config(self):
@@ -143,9 +143,9 @@ class Lighttpd(http_server_base.HttpServerBase):
 
                 # default set of ports as for LayoutTests but with a
                 # specified root.
-                mappings = [{'port': 8000, 'docroot': self._root},
-                            {'port': 8080, 'docroot': self._root},
-                            {'port': 8443, 'docroot': self._root,
+                mappings = [{'port': self.HTTP_SERVER_PORT, 'docroot': self._root},
+                            {'port': self.ALTERNATIVE_HTTP_SERVER_PORT, 'docroot': self._root},
+                            {'port': self.HTTPS_SERVER_PORT, 'docroot': self._root,
                              'sslcert': self._pem_file}]
         else:
             mappings = self.VIRTUALCONFIG
index 5e78569..ee04599 100644 (file)
@@ -47,6 +47,10 @@ class ServerError(Exception):
 class HttpServerBase(object):
     """A skeleton class for starting and stopping servers used by the layout tests."""
 
+    HTTP_SERVER_PORT = 8000
+    ALTERNATIVE_HTTP_SERVER_PORT = 8080
+    HTTPS_SERVER_PORT = 8443
+
     def __init__(self, port_obj):
         self._executive = port_obj._executive
         self._filesystem = port_obj._filesystem
@@ -68,6 +72,9 @@ class HttpServerBase(object):
         self._runtime_path = self._filesystem.join(tmpdir, "WebKit")
         self._filesystem.maybe_make_directory(self._runtime_path)
 
+    def ports_to_forward(self):
+        return [mapping['port'] for mapping in self._mappings]
+
     def start(self):
         """Starts the server. It is an error to start an already started server.
 
index fd43c70..7389805 100644 (file)
@@ -56,6 +56,7 @@ class TestHttpServer(unittest.TestCase):
                               "/mock/one-additional-dir": "/mock-checkout/one-additional-dir",
                               "/mock/another-additional-dir": "/mock-checkout/one-additional-dir"})
         self.assertRaises(ServerError, server.start)
+        self.assertEqual(server.ports_to_forward(), [8000, 8080, 8443])
 
         config_file = host.filesystem.read_text_file("/mock/output_dir/lighttpd.conf")
         self.assertEqual(re.findall(r"alias.url.+", config_file), [
index a193d93..dd0ef1f 100755 (executable)
@@ -97,6 +97,9 @@ class WebPlatformTestServer(http_server_base.HttpServerBase):
                         port["sslcert"] = True
                     self._mappings.append(port)
 
+    def ports_to_forward(self):
+        return [mapping['port'] for mapping in self._mappings]
+
     def _install_modules(self):
         modules_file_path = self._filesystem.join(self._doc_root_path, "..", "resources", "web-platform-tests-modules.json")
         if not self._filesystem.isfile(modules_file_path):
index b1ec3a9..0831fd3 100644 (file)
@@ -44,12 +44,11 @@ _WS_LOG_NAME = 'pywebsocket.ws.log'
 _WSS_LOG_NAME = 'pywebsocket.wss.log'
 
 
-_DEFAULT_WS_PORT = 8880
-_DEFAULT_WSS_PORT = 9323
-
-
 class PyWebSocket(http_server.Lighttpd):
-    def __init__(self, port_obj, output_dir, port=_DEFAULT_WS_PORT,
+    DEFAULT_WS_PORT = 8880
+    DEFAULT_WSS_PORT = 9323
+
+    def __init__(self, port_obj, output_dir, port=DEFAULT_WS_PORT,
                  root=None, use_tls=False,
                  private_key=None, certificate=None, ca_certificate=None,
                  pidfile=None):
@@ -57,7 +56,7 @@ class PyWebSocket(http_server.Lighttpd):
           output_dir: the absolute path to the layout test result directory
         """
         http_server.Lighttpd.__init__(self, port_obj, output_dir,
-                                      port=_DEFAULT_WS_PORT,
+                                      port=PyWebSocket.DEFAULT_WS_PORT,
                                       root=root)
         self._output_dir = output_dir
         self._pid_file = pidfile
@@ -107,6 +106,9 @@ class PyWebSocket(http_server.Lighttpd):
         else:
             self._log_prefix = _WS_LOG_NAME
 
+    def ports_to_forward(self):
+        return [self._port]
+
     def _prepare_config(self):
         log_file_name = self._log_prefix
         # FIXME: Doesn't Executive have a devnull, so that we don't have to use os.devnull directly?
index bd6c9f6..561858e 100644 (file)
@@ -57,8 +57,7 @@ from webkitpy.port import driver
 from webkitpy.port import image_diff
 from webkitpy.port import server_process
 from webkitpy.port.factory import PortFactory
-from webkitpy.layout_tests.servers import apache_http_server
-from webkitpy.layout_tests.servers import http_server
+from webkitpy.layout_tests.servers import apache_http_server, http_server
 from webkitpy.layout_tests.servers import web_platform_test_server
 from webkitpy.layout_tests.servers import websocket_server
 
@@ -938,6 +937,18 @@ class Port(object):
         storage, it should override this method."""
         pass
 
+    def ports_to_forward(self):
+        ports = []
+        if self._http_server:
+            ports.extend(self._http_server.ports_to_forward())
+        if self._websocket_server:
+            ports.extend(self._websocket_server.ports_to_forward())
+        if self._websocket_server:
+            ports.extend(self._websocket_secure_server.ports_to_forward())
+        if self._web_platform_test_server:
+            ports.extend(self._web_platform_test_server.ports_to_forward())
+        return ports
+
     def start_http_server(self, additional_dirs=None):
         """Start a web server. Raise an error if it can't start or is already running.
 
@@ -975,7 +986,7 @@ class Port(object):
         self._websocket_server_temporary_directory = websocket_server_temporary_directory
         if self._extract_certificate_from_pem(pem_file, certificate_file) and self._extract_private_key_from_pem(pem_file, private_key_file):
             secure_server = self._websocket_secure_server = websocket_server.PyWebSocket(self, self.results_directory(),
-                                use_tls=True, port=9323, private_key=private_key_file, certificate=certificate_file)
+                                use_tls=True, port=websocket_server.PyWebSocket.DEFAULT_WSS_PORT, private_key=private_key_file, certificate=certificate_file)
             secure_server.start()
             self._websocket_secure_server = secure_server