| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 """A class to start/stop the apache http server used by layout tests.""" | 29 """A class to start/stop the Apache HTTP server used by layout tests.""" |
| 30 | 30 |
| 31 | 31 |
| 32 import logging | 32 import logging |
| 33 import os | 33 import os |
| 34 import re | 34 import re |
| 35 import socket | 35 import socket |
| 36 import sys | 36 import sys |
| 37 | 37 |
| 38 from webkitpy.layout_tests.servers import http_server_base | 38 from webkitpy.layout_tests.servers import server_base |
| 39 | 39 |
| 40 | 40 |
| 41 _log = logging.getLogger(__name__) | 41 _log = logging.getLogger(__name__) |
| 42 | 42 |
| 43 | 43 |
| 44 class LayoutTestApacheHttpd(http_server_base.HttpServerBase): | 44 class ApacheHTTP(server_base.ServerBase): |
| 45 def __init__(self, port_obj, output_dir, additional_dirs=None, number_of_ser
vers=None): | 45 def __init__(self, port_obj, output_dir, additional_dirs=None, number_of_ser
vers=None): |
| 46 """Args: | 46 """Args: |
| 47 port_obj: handle to the platform-specific routines | 47 port_obj: handle to the platform-specific routines |
| 48 output_dir: the absolute path to the layout test result directory | 48 output_dir: the absolute path to the layout test result directory |
| 49 """ | 49 """ |
| 50 http_server_base.HttpServerBase.__init__(self, port_obj, number_of_serve
rs) | 50 super(ApacheHTTP, self).__init__(port_obj, number_of_servers) |
| 51 # We use the name "httpd" instead of "apache" to make our paths (e.g. th
e pid file: /tmp/WebKit/httpd.pid) | 51 # We use the name "httpd" instead of "apache" to make our paths (e.g. th
e pid file: /tmp/WebKit/httpd.pid) |
| 52 # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63
956 | 52 # match old-run-webkit-tests: https://bugs.webkit.org/show_bug.cgi?id=63
956 |
| 53 self._name = 'httpd' | 53 self._name = 'httpd' |
| 54 self._mappings = [{'port': 8000}, | 54 self._mappings = [{'port': 8000}, |
| 55 {'port': 8080}, | 55 {'port': 8080}, |
| 56 {'port': 8443, 'sslcert': True}] | 56 {'port': 8443, 'sslcert': True}] |
| 57 self._output_dir = output_dir | 57 self._output_dir = output_dir |
| 58 self._filesystem.maybe_make_directory(output_dir) | 58 self._filesystem.maybe_make_directory(output_dir) |
| 59 | 59 |
| 60 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) | 60 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % se
lf._name) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 # can use the same code. Otherwise, we could remove the single | 129 # can use the same code. Otherwise, we could remove the single |
| 130 # quotes above and keep cmd as a sequence. | 130 # quotes above and keep cmd as a sequence. |
| 131 # FIXME: It's unclear if this is still needed. | 131 # FIXME: It's unclear if this is still needed. |
| 132 self._start_cmd = " ".join(start_cmd) | 132 self._start_cmd = " ".join(start_cmd) |
| 133 self._stop_cmd = " ".join(stop_cmd) | 133 self._stop_cmd = " ".join(stop_cmd) |
| 134 | 134 |
| 135 def _spawn_process(self): | 135 def _spawn_process(self): |
| 136 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) | 136 _log.debug('Starting %s server, cmd="%s"' % (self._name, str(self._start
_cmd))) |
| 137 retval, err = self._run(self._start_cmd) | 137 retval, err = self._run(self._start_cmd) |
| 138 if retval or len(err): | 138 if retval or len(err): |
| 139 raise http_server_base.ServerError('Failed to start %s: %s' % (self.
_name, err)) | 139 raise server_base.ServerError('Failed to start %s: %s' % (self._name
, err)) |
| 140 | 140 |
| 141 # For some reason apache isn't guaranteed to have created the pid file b
efore | 141 # For some reason apache isn't guaranteed to have created the pid file b
efore |
| 142 # the process exits, so we wait a little while longer. | 142 # the process exits, so we wait a little while longer. |
| 143 if not self._wait_for_action(lambda: self._filesystem.exists(self._pid_f
ile)): | 143 if not self._wait_for_action(lambda: self._filesystem.exists(self._pid_f
ile)): |
| 144 raise http_server_base.ServerError('Failed to start %s: no pid file
found' % self._name) | 144 raise server_base.ServerError('Failed to start %s: no pid file found
' % self._name) |
| 145 | 145 |
| 146 return int(self._filesystem.read_text_file(self._pid_file)) | 146 return int(self._filesystem.read_text_file(self._pid_file)) |
| 147 | 147 |
| 148 def _stop_running_server(self): | 148 def _stop_running_server(self): |
| 149 # If apache was forcefully killed, the pid file will not have been delet
ed, so check | 149 # If apache was forcefully killed, the pid file will not have been delet
ed, so check |
| 150 # that the process specified by the pid_file no longer exists before del
eting the file. | 150 # that the process specified by the pid_file no longer exists before del
eting the file. |
| 151 if self._pid and not self._executive.check_running_pid(self._pid): | 151 if self._pid and not self._executive.check_running_pid(self._pid): |
| 152 self._filesystem.remove(self._pid_file) | 152 self._filesystem.remove(self._pid_file) |
| 153 return | 153 return |
| 154 | 154 |
| 155 retval, err = self._run(self._stop_cmd) | 155 retval, err = self._run(self._stop_cmd) |
| 156 if retval or len(err): | 156 if retval or len(err): |
| 157 raise http_server_base.ServerError('Failed to stop %s: %s' % (self._
name, err)) | 157 raise server_base.ServerError('Failed to stop %s: %s' % (self._name,
err)) |
| 158 | 158 |
| 159 # For some reason apache isn't guaranteed to have actually stopped after | 159 # For some reason apache isn't guaranteed to have actually stopped after |
| 160 # the stop command returns, so we wait a little while longer for the | 160 # the stop command returns, so we wait a little while longer for the |
| 161 # pid file to be removed. | 161 # pid file to be removed. |
| 162 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): | 162 if not self._wait_for_action(lambda: not self._filesystem.exists(self._p
id_file)): |
| 163 raise http_server_base.ServerError('Failed to stop %s: pid file stil
l exists' % self._name) | 163 raise server_base.ServerError('Failed to stop %s: pid file still exi
sts' % self._name) |
| 164 | 164 |
| 165 def _run(self, cmd): | 165 def _run(self, cmd): |
| 166 # Use shell=True because we join the arguments into a string for | 166 # Use shell=True because we join the arguments into a string for |
| 167 # the sake of Window/Cygwin and it needs quoting that breaks | 167 # the sake of Window/Cygwin and it needs quoting that breaks |
| 168 # shell=False. | 168 # shell=False. |
| 169 # FIXME: We should not need to be joining shell arguments into strings. | 169 # FIXME: We should not need to be joining shell arguments into strings. |
| 170 # shell=True is a trail of tears. | 170 # shell=True is a trail of tears. |
| 171 # Note: Not thread safe: http://bugs.python.org/issue2320 | 171 # Note: Not thread safe: http://bugs.python.org/issue2320 |
| 172 process = self._executive.popen(cmd, shell=True, stderr=self._executive.
PIPE) | 172 process = self._executive.popen(cmd, shell=True, stderr=self._executive.
PIPE) |
| 173 process.wait() | 173 process.wait() |
| 174 retval = process.returncode | 174 retval = process.returncode |
| 175 err = process.stderr.read() | 175 err = process.stderr.read() |
| 176 return (retval, err) | 176 return (retval, err) |
| OLD | NEW |