Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 02 Dec 2016 19:44:28 +0000
changeset 325328 d237751e0dea92a3b033a7b44855238c12c9ce86
parent 325327 d4657cdb08125a7daab950a72066df1332f25f21
child 325329 dc7d74a8a4bad3ca3beca17491775bd3e19b829d
push id31051
push usercbook@mozilla.com
push dateThu, 08 Dec 2016 15:15:04 +0000
treeherdermozilla-central@64e024fe4471 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1320643
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1320643 - Let HTTPDs bind to custom interface; r=whimboo 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 127.0.0.1, which is a loopback device. MozReview-Commit-ID: 3QeMx3zqPyW
testing/marionette/harness/marionette/runner/serve.py
--- 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",
            "iter_proc",
            "iter_url",
            "registered_servers",
            "servers",
            "start",
@@ -132,25 +130,26 @@ class ServerProc(BlockingChannel):
 
     @property
     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="127.0.0.1", **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="127.0.0.1", **kwargs):
     return httpd.FixtureServer(doc_root,
-                               url="https://%s:0/" % moznetwork.get_ip(),
+                               url="https://{}:0/".format(host),
                                ssl_key=ssl_config["key_path"],
-                               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)
 
     try:
         while any(proc.is_alive for proc in iter_proc(servers)):
             for proc in iter_proc(servers):
                 proc.proc.join(1)
     except KeyboardInterrupt:
         for proc in iter_proc(servers):
             proc.kill()