Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/servers/pywebsocket.py

Issue 159723008: Refactor webkitpy.layout_tests.servers.server_base. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 15 matching lines...) Expand all
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 help start/stop the PyWebSocket server used by layout tests.""" 29 """A class to help start/stop the PyWebSocket server used by layout tests."""
30 30
31 import logging 31 import logging
32 import os 32 import os
33 import sys 33 import sys
34 import time 34 import time
35 35
36 from webkitpy.layout_tests.servers import lighttpd
37 from webkitpy.layout_tests.servers import server_base 36 from webkitpy.layout_tests.servers import server_base
38 37
39 _log = logging.getLogger(__name__) 38 _log = logging.getLogger(__name__)
40 39
41 40
42 _WS_LOG_PREFIX = 'pywebsocket.ws.log-' 41 _WS_LOG_PREFIX = 'pywebsocket.ws.log-'
43 _WSS_LOG_PREFIX = 'pywebsocket.wss.log-' 42 _WSS_LOG_PREFIX = 'pywebsocket.wss.log-'
44 43
45 44
46 _DEFAULT_WS_PORT = 8880 45 _DEFAULT_WS_PORT = 8880
47 _DEFAULT_WSS_PORT = 9323 46 _DEFAULT_WSS_PORT = 9323
48 47
49 48
50 class PyWebSocket(lighttpd.Lighttpd): 49 class PyWebSocket(server_base.ServerBase):
51 def __init__(self, port_obj, output_dir, port=_DEFAULT_WS_PORT, 50 def __init__(self, port_obj, output_dir, port=_DEFAULT_WS_PORT,
52 root=None, use_tls=False, 51 root=None, use_tls=False,
53 private_key=None, certificate=None, ca_certificate=None, 52 private_key=None, certificate=None, ca_certificate=None,
54 pidfile=None): 53 pidfile=None):
55 """Args: 54 """Args:
56 output_dir: the absolute path to the layout test result directory 55 output_dir: the absolute path to the layout test result directory
57 """ 56 """
58 super(PyWebSocket, self).__init__(port_obj, output_dir, 57 super(PyWebSocket, self).__init__(port_obj, output_dir)
59 port=_DEFAULT_WS_PORT,
60 root=root)
61 self._output_dir = output_dir
62 self._pid_file = pidfile 58 self._pid_file = pidfile
63 self._process = None 59 self._process = None
64 60
65 self._port = port 61 self._port = port
66 self._root = root 62 self._root = root
67 self._use_tls = use_tls 63 self._use_tls = use_tls
68 64
69 self._name = 'pywebsocket' 65 self._name = 'pywebsocket'
66 self._log_prefixes = (_WS_LOG_PREFIX,)
70 if self._use_tls: 67 if self._use_tls:
71 self._name = 'pywebsocket_secure' 68 self._name = 'pywebsocket_secure'
69 self._log_prefixes = (_WSS_LOG_PREFIX,)
70
71 # Self generated certificate for SSL server (for client cert get
72 # <base-path>\chrome\test\data\ssl\certs\root_ca_cert.crt)
73 self._pem_file = os.path.join(
74 os.path.dirname(os.path.abspath(__file__)), 'httpd2.pem')
72 75
73 if private_key: 76 if private_key:
74 self._private_key = private_key 77 self._private_key = private_key
75 else: 78 else:
76 self._private_key = self._pem_file 79 self._private_key = self._pem_file
77 if certificate: 80 if certificate:
78 self._certificate = certificate 81 self._certificate = certificate
79 else: 82 else:
80 self._certificate = self._pem_file 83 self._certificate = self._pem_file
81 self._ca_certificate = ca_certificate 84 self._ca_certificate = ca_certificate
82 if self._port: 85 if self._port:
83 self._port = int(self._port) 86 self._port = int(self._port)
84 self._wsin = None
85 self._wsout = None
86 self._mappings = [{'port': self._port}] 87 self._mappings = [{'port': self._port}]
87 88
88 if not self._pid_file: 89 if not self._pid_file:
89 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % self._name) 90 self._pid_file = self._filesystem.join(self._runtime_path, '%s.pid' % self._name)
90 91
91 # Webkit tests 92 # Webkit tests
92 # FIXME: This is the wrong way to detect if we're in Chrome vs. WebKit! 93 # FIXME: This is the wrong way to detect if we're in Chrome vs. WebKit!
93 # The port objects are supposed to abstract this. 94 # The port objects are supposed to abstract this.
94 if self._root: 95 if self._root:
95 self._layout_tests = self._filesystem.abspath(self._root) 96 self._layout_tests = self._filesystem.abspath(self._root)
96 self._web_socket_tests = self._filesystem.abspath(self._filesystem.j oin(self._root, 'http', 'tests', 'websocket')) 97 self._web_socket_tests = self._filesystem.abspath(self._filesystem.j oin(self._root, 'http', 'tests', 'websocket'))
97 else: 98 else:
98 try: 99 try:
99 self._layout_tests = self._port_obj.layout_tests_dir() 100 self._layout_tests = self._port_obj.layout_tests_dir()
100 self._web_socket_tests = self._filesystem.join(self._layout_test s, 'http', 'tests', 'websocket') 101 self._web_socket_tests = self._filesystem.join(self._layout_test s, 'http', 'tests', 'websocket')
101 except: 102 except:
102 self._web_socket_tests = None 103 self._web_socket_tests = None
103 104
104 if self._use_tls: 105 if self._use_tls:
105 self._log_prefix = _WSS_LOG_PREFIX 106 self._log_prefix = _WSS_LOG_PREFIX
106 else: 107 else:
107 self._log_prefix = _WS_LOG_PREFIX 108 self._log_prefix = _WS_LOG_PREFIX
108 109
109 def _prepare_config(self): 110 def _prepare_config(self):
110 time_str = time.strftime('%d%b%Y-%H%M%S') 111 time_str = time.strftime('%d%b%Y-%H%M%S')
111 log_file_name = self._log_prefix + time_str 112 log_file_name = self._log_prefix + time_str
112 # FIXME: Doesn't Executive have a devnull, so that we don't have to use os.devnull directly? 113 # FIXME: Doesn't Executive have a devnull, so that we don't have to use os.devnull directly?
scottmg 2014/02/11 22:21:54 remove comment
Dirk Pranke 2014/02/12 21:03:41 That gets removed in https://codereview.chromium.o
113 self._wsin = open(os.devnull, 'r')
114 114
115 error_log = self._filesystem.join(self._output_dir, log_file_name + "-er r.txt") 115 error_log = self._filesystem.join(self._output_dir, log_file_name + "-er r.txt")
116 output_log = self._filesystem.join(self._output_dir, log_file_name + "-o ut.txt")
117 self._wsout = self._filesystem.open_text_file_for_writing(output_log)
118 116
119 from webkitpy.thirdparty import mod_pywebsocket 117 from webkitpy.thirdparty import mod_pywebsocket
120 python_interp = sys.executable 118 python_interp = sys.executable
121 # FIXME: Use self._filesystem.path_to_module(self.__module__) instead of __file__ 119 # FIXME: Use self._filesystem.path_to_module(self.__module__) instead of __file__
122 # I think this is trying to get the chrome directory? Doesn't the port object know that? 120 # I think this is trying to get the chrome directory? Doesn't the port object know that?
123 pywebsocket_base = self._filesystem.join(self._filesystem.dirname(self._ filesystem.dirname(self._filesystem.dirname(self._filesystem.abspath(__file__))) ), 'thirdparty') 121 pywebsocket_base = self._filesystem.join(self._filesystem.dirname(self._ filesystem.dirname(self._filesystem.dirname(self._filesystem.abspath(__file__))) ), 'thirdparty')
124 pywebsocket_script = self._filesystem.join(pywebsocket_base, 'mod_pywebs ocket', 'standalone.py') 122 pywebsocket_script = self._filesystem.join(pywebsocket_base, 'mod_pywebs ocket', 'standalone.py')
125 start_cmd = [ 123 start_cmd = [
126 python_interp, '-u', pywebsocket_script, 124 python_interp, '-u', pywebsocket_script,
127 '--server-host', 'localhost', 125 '--server-host', 'localhost',
(...skipping 16 matching lines...) Expand all
144 start_cmd.extend(['-t', '-k', self._private_key, 142 start_cmd.extend(['-t', '-k', self._private_key,
145 '-c', self._certificate]) 143 '-c', self._certificate])
146 if self._ca_certificate: 144 if self._ca_certificate:
147 start_cmd.append('--ca-certificate') 145 start_cmd.append('--ca-certificate')
148 start_cmd.append(self._ca_certificate) 146 start_cmd.append(self._ca_certificate)
149 147
150 self._start_cmd = start_cmd 148 self._start_cmd = start_cmd
151 server_name = self._filesystem.basename(pywebsocket_script) 149 server_name = self._filesystem.basename(pywebsocket_script)
152 self._env = self._port_obj.setup_environ_for_server(server_name) 150 self._env = self._port_obj.setup_environ_for_server(server_name)
153 self._env['PYTHONPATH'] = (pywebsocket_base + os.path.pathsep + self._en v.get('PYTHONPATH', '')) 151 self._env['PYTHONPATH'] = (pywebsocket_base + os.path.pathsep + self._en v.get('PYTHONPATH', ''))
154
155 def _remove_stale_logs(self):
156 try:
157 self._remove_log_files(self._output_dir, self._log_prefix)
158 except OSError, e:
159 _log.warning('Failed to remove stale %s log files: %s' % (self._name , str(e)))
160
161 def _spawn_process(self):
162 _log.debug('Starting %s server, cmd="%s"' % (self._name, self._start_cmd ))
163 self._process = self._executive.popen(self._start_cmd, env=self._env, sh ell=False, stdin=self._wsin, stdout=self._wsout, stderr=self._executive.STDOUT)
164 self._filesystem.write_text_file(self._pid_file, str(self._process.pid))
165 return self._process.pid
166
167 def _stop_running_server(self):
168 super(PyWebSocket, self)._stop_running_server()
169
170 if self._wsin:
171 self._wsin.close()
172 self._wsin = None
173 if self._wsout:
174 self._wsout.close()
175 self._wsout = None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698