Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 02 Dec 2016 19:44:28 +0000
changeset 352878 2d97d7cba0082545068a43c4a0e73cf574bc4c64
parent 352877 469464ff01564cf915217b6f80d755e43e8e12da
child 352879 bf608ff5e3c8c7004b8c862d8e2d57cd3e776d57
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo, test-only
Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo a=test-only Allows HTTPDs to be started on a custom networking interface (host) by using the `host` keyword argument. This may be passed to `serve.http_server`, `serve.https_server`, `serve.start_servers`, and `serve.start`. This also changes the default host to, which is a loopback device. MozReview-Commit-ID: 3QeMx3zqPyW
--- a/testing/marionette/harness/marionette/runner/serve.py
+++ b/testing/marionette/harness/marionette/runner/serve.py
@@ -10,18 +10,16 @@ processes.
 import argparse
 import multiprocessing
 import os
 import sys
 from collections import defaultdict
-import moznetwork
 import httpd
 __all__ = ["default_doc_root",
@@ -132,25 +130,26 @@ class ServerProc(BlockingChannel):
     def is_alive(self):
         if self.proc is not None:
             return self.proc.is_alive()
         return False
-def http_server(doc_root, ssl_config, **kwargs):
-    return httpd.FixtureServer(doc_root, url="http://%s:0/" % moznetwork.get_ip())
+def http_server(doc_root, ssl_config, host="", **kwargs):
+    return httpd.FixtureServer(doc_root, url="http://{}:0/".format(host), **kwargs)
-def https_server(doc_root, ssl_config, **kwargs):
+def https_server(doc_root, ssl_config, host="", **kwargs):
     return httpd.FixtureServer(doc_root,
-                               url="https://%s:0/" % moznetwork.get_ip(),
+                               url="https://{}:0/".format(host),
-                               ssl_cert=ssl_config["cert_path"])
+                               ssl_cert=ssl_config["cert_path"],
+                               **kwargs)
 def start_servers(doc_root, ssl_config, **kwargs):
     servers = defaultdict()
     for schema, builder_fn in registered_servers:
         proc = ServerProc(builder_fn)
         proc.start(doc_root, ssl_config, **kwargs)
         servers[schema] = (proc.get_url("/"), proc)
@@ -168,17 +167,16 @@ def start(doc_root=None, **kwargs):
     doc_root = doc_root or default_doc_root
     ssl_config = {"cert_path": httpd.default_ssl_cert,
                   "key_path": httpd.default_ssl_key}
     global servers
     servers = start_servers(doc_root, ssl_config, **kwargs)
     return servers
 def where_is(uri, on="http"):
     """Returns the full URL, including scheme, hostname, and port, for
     a fixture resource from the server associated with the ``on`` key.
     It will by default look for the resource in the "http" server.
@@ -207,17 +205,17 @@ def main(args):
     parser = argparse.ArgumentParser()
     parser.add_argument("-r", dest="doc_root",
                         help="Path to document root.  Overrides default.")
     args = parser.parse_args()
     servers = start(args.doc_root)
     for url in iter_url(servers):
-        print >>sys.stderr, "%s: listening on %s" % (sys.argv[0], url)
+        print >>sys.stderr, "{}: listening on {}".format(sys.argv[0], url)
         while any(proc.is_alive for proc in iter_proc(servers)):
             for proc in iter_proc(servers):
     except KeyboardInterrupt:
         for proc in iter_proc(servers):