Bug 1230862 - remove mozhttpd dependency for Talos. r=jmaher draft
authorJulien Pagès <j.parkouss@gmail.com>
Thu, 11 Feb 2016 12:23:07 +0100
changeset 330305 fe35ae46b5376e64a7d4e64c7856357580bddddf
parent 330304 d4d72e7b30da251ad3027e234444251adad5e335
child 330306 1cee887de1184c3d43f07afe372b5bc9782123aa
push id10726
push userj.parkouss@gmail.com
push dateThu, 11 Feb 2016 11:24:35 +0000
reviewersjmaher
bugs1230862
milestone47.0a1
Bug 1230862 - remove mozhttpd dependency for Talos. r=jmaher MozReview-Commit-ID: 72hwZSWfeor
testing/talos/requirements.txt
testing/talos/talos/http_server.py
testing/talos/talos/run_tests.py
--- a/testing/talos/requirements.txt
+++ b/testing/talos/requirements.txt
@@ -1,9 +1,8 @@
 mozlog>=3.1
 mozcrash>=0.15
 mozfile>=1.2
-mozhttpd>=0.7
 mozinfo>=0.8
 mozprocess>=0.22
 mozversion>=1.3
 mozprofile>=0.25
 psutil>=3.1.1
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/http_server.py
@@ -0,0 +1,23 @@
+"""
+This is a simple web server to serve files.
+
+The key differences with using |python -m SimpleHTTPServer <PORT>| are:
+
+ - the server is required as the first parameter, so one can use localhost
+   instead of the hardcoded 0.0.0.0
+ - the server can handle multiple requests in parallel using threads
+"""
+
+import sys
+import SocketServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+
+
+class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
+    pass
+
+
+if __name__ == '__main__':
+    httpd = ThreadedTCPServer((sys.argv[1], int(sys.argv[2])),
+                              SimpleHTTPRequestHandler)
+    httpd.serve_forever()
--- a/testing/talos/talos/run_tests.py
+++ b/testing/talos/talos/run_tests.py
@@ -6,18 +6,18 @@
 
 import mozversion
 import os
 import sys
 import time
 import traceback
 import urllib
 import utils
-import mozhttpd
 
+import subprocess
 from mozlog import get_proxy_logger
 
 from talos.results import TalosResults
 from talos.ttest import TTest
 from talos.utils import TalosError, TalosRegression
 from talos.config import get_configs, ConfigurationError
 
 # directory of this file
@@ -63,21 +63,25 @@ def buildCommandLine(test):
 
     # XXX we should actually return the list but since we abuse
     # the url as a command line flag to pass to firefox all over the place
     # will just make a string for now
     return ' '.join(url)
 
 
 def setup_webserver(webserver):
-    """use mozhttpd to setup a webserver"""
+    """setup a webserver"""
     LOG.info("starting webserver on %r" % webserver)
 
     host, port = webserver.split(':')
-    return mozhttpd.MozHttpd(host=host, port=int(port), docroot=here)
+    with open(os.devnull, 'w') as null:
+        return subprocess.Popen([sys.executable,
+                                 os.path.join(here, 'http_server.py'),
+                                 host, port],
+                                cwd=here, stdout=null, stderr=null)
 
 
 def run_tests(config, browser_config):
     """Runs the talos tests on the given configuration and generates a report.
     """
     # get the test data
     tests = config['tests']
     tests = useBaseTestDefaults(config.get('basetest', {}), tests)
@@ -176,17 +180,16 @@ def run_tests(config, browser_config):
         # local mode, output to files
         results_urls = dict(
             results_urls=[os.path.abspath('local.out')],
             datazilla_urls=[os.path.abspath('local.json')]
         )
     talos_results.check_output_formats(results_urls)
 
     httpd = setup_webserver(browser_config['webserver'])
-    httpd.start()
 
     testname = None
     # run the tests
     timer = utils.Timer()
     LOG.suite_start(tests=[test['name'] for test in tests])
     try:
         for test in tests:
             testname = test['name']
@@ -209,17 +212,17 @@ def run_tests(config, browser_config):
         # problem and cannot continue
         #       this will prevent future tests from running
         LOG.test_end(testname, status='ERROR', message=unicode(exc),
                      stack=traceback.format_exc())
         # indicate a failure to buildbot, turn the job red
         return 2
     finally:
         LOG.suite_end()
-        httpd.stop()
+        httpd.kill()
 
     LOG.info("Completed test suite (%s)" % timer.elapsed())
 
     # output results
     if results_urls:
         talos_results.output(results_urls)
         if browser_config['develop']:
             print