Bug 1446374 - Make wptserve work from outside repo root, r=gsnedders draft
authorJames Graham <james@hoppipolla.co.uk>
Fri, 16 Mar 2018 13:25:58 +0000
changeset 769289 8cab872d81cebffd5dc09a444a497a41d80634c6
parent 768523 47e1787284fbfad3d32eb7081ffdda58d2b086de
child 769290 9036d6ea683792d84833f82bc8e74deed880a5de
push id103092
push userbmo:james@hoppipolla.co.uk
push dateMon, 19 Mar 2018 10:50:07 +0000
reviewersgsnedders
bugs1446374
milestone61.0a1
Bug 1446374 - Make wptserve work from outside repo root, r=gsnedders Previously it was assumed that the paths in config files were relative to the current working directory, which only works if the current working directory happens to be the repo root. With this change we make them paths relative to some base path. We typically expect this to be set to the path of the config file, but for the default case we also know that the config files are in the repo root, so we can use that. MozReview-Commit-ID: 8pR8VGmB81d
testing/web-platform/tests/tools/serve/serve.py
--- a/testing/web-platform/tests/tools/serve/serve.py
+++ b/testing/web-platform/tests/tools/serve/serve.py
@@ -12,17 +12,17 @@ import sys
 import threading
 import time
 import traceback
 import urllib2
 import uuid
 from collections import defaultdict, OrderedDict
 from multiprocessing import Process, Event
 
-from ..localpaths import repo_root
+from localpaths import repo_root
 
 import sslutils
 from manifest.sourcefile import read_script_metadata, js_meta_re
 from wptserve import server as wptserve, handlers
 from wptserve import stash
 from wptserve.logger import set_logger
 from wptserve.handlers import filesystem_path, wrap_pipeline
 from mod_pywebsocket import standalone as pywebsocket
@@ -617,18 +617,17 @@ def get_ports(config, ssl_environment):
             if port == "auto":
                 port = get_port()
             else:
                 port = port
             rv[scheme].append(port)
     return rv
 
 
-
-def normalise_config(config, ports):
+def normalise_config(config, ports, base_path=repo_root):
     host = config["external_host"] if config["external_host"] else config["host"]
     domains = get_subdomains(host)
     ports_ = {}
     for scheme, ports_used in ports.iteritems():
         ports_[scheme] = ports_used
 
     for key, value in domains.iteritems():
         domains[key] = ".".join(value)
@@ -640,31 +639,46 @@ def normalise_config(config, ports):
         ports_[scheme] = ports_used
 
     # make a (shallow) copy of the config and update that, so that the
     # normalized config can be used in place of the original one.
     config_ = config.copy()
     config_["host"] = host
     config_["domains"] = domains
     config_["ports"] = ports_
+
+    path_properties = ["doc_root",
+                       "ws_doc_root",
+                       ("ssl", "openssl", "base_path"),
+                       ("ssl", "pregenerated", "host_key_path"),
+                       ("ssl", "pregenerated", "host_cert_path")]
+    for key in path_properties:
+        target = config_
+        if not isinstance(key, (str, unicode)):
+            for key_part in key[:-1]:
+                target = target[key_part]
+            key = key[-1]
+        target[key] = os.path.join(base_path, target[key])
+
     return config_
 
 
 def get_paths(config):
     return {"doc_root": config["doc_root"],
             "ws_doc_root": config["ws_doc_root"]}
 
 
-def get_ssl_config(config, ssl_environment):
+def get_ssl_config(config, ssl_environment, base_path=repo_root):
     external_domains = config["domains"].values()
     key_path, cert_path = ssl_environment.host_cert_path(external_domains)
-    return {"key_path": key_path,
-            "cert_path": cert_path,
+    return {"key_path": os.path.join(base_path, key_path),
+            "cert_path": os.path.join(base_path, cert_path),
             "encrypt_after_connect": config["ssl"]["encrypt_after_connect"]}
 
+
 def start(config, ssl_environment, routes, **kwargs):
     host = config["host"]
     ports = get_ports(config, ssl_environment)
     paths = get_paths(config)
     bind_hostname = config["bind_hostname"]
     ssl_config = get_ssl_config(config, ssl_environment)
 
     servers = start_servers(host, ports, paths, routes, bind_hostname, config,
@@ -778,17 +792,17 @@ def run(**kwargs):
     config = load_config(os.path.join(repo_root, "config.default.json"),
                          os.path.join(repo_root, "config.json"),
                          **kwargs)
 
     setup_logger(config["log_level"])
 
     with get_ssl_environment(config) as ssl_env:
         ports = get_ports(config, ssl_env)
-        config = normalise_config(config, ports)
+        config = normalise_config(config, ports, repo_root)
         host = config["host"]
         bind_hostname = config["bind_hostname"]
 
         if config["check_subdomains"]:
             paths = get_paths(config)
             ssl_config = get_ssl_config(config, ssl_env)
             check_subdomains(host, paths, bind_hostname, ssl_config, config["aliases"])