OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Start and stop tsproxy.""" | 5 """Start and stop tsproxy.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
| 12 import tempfile |
12 | 13 |
13 from py_utils import atexit_with_log | 14 from py_utils import atexit_with_log |
14 from telemetry.core import util | 15 from telemetry.core import util |
15 | 16 |
16 import py_utils | 17 import py_utils |
17 | 18 |
18 | 19 |
19 _TSPROXY_PATH = os.path.join( | 20 _TSPROXY_PATH = os.path.join( |
20 util.GetTelemetryThirdPartyDir(), 'tsproxy', 'tsproxy.py') | 21 util.GetTelemetryThirdPartyDir(), 'tsproxy', 'tsproxy.py') |
21 | 22 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 """Start TsProxy server and verify that it started. | 58 """Start TsProxy server and verify that it started. |
58 """ | 59 """ |
59 cmd_line = [sys.executable, _TSPROXY_PATH] | 60 cmd_line = [sys.executable, _TSPROXY_PATH] |
60 cmd_line.extend([ | 61 cmd_line.extend([ |
61 '--port=0']) # Use port 0 so tsproxy picks a random available port. | 62 '--port=0']) # Use port 0 so tsproxy picks a random available port. |
62 if self._host_ip: | 63 if self._host_ip: |
63 cmd_line.append('--desthost=%s' % self._host_ip) | 64 cmd_line.append('--desthost=%s' % self._host_ip) |
64 if self._http_port: | 65 if self._http_port: |
65 cmd_line.append( | 66 cmd_line.append( |
66 '--mapports=443:%s,*:%s' % (self._https_port, self._http_port)) | 67 '--mapports=443:%s,*:%s' % (self._https_port, self._http_port)) |
| 68 |
| 69 tf = tempfile.NamedTemporaryFile(delete=False) |
| 70 tf.close() |
| 71 temp_path = tf.name |
| 72 print 'Pipe tsproxy log to %s' % temp_path |
| 73 cmd_line.append('--logfile=%s' % temp_path) |
| 74 cmd_line.append('-vvv') |
67 logging.info('Tsproxy commandline: %r' % cmd_line) | 75 logging.info('Tsproxy commandline: %r' % cmd_line) |
68 self._proc = subprocess.Popen( | 76 self._proc = subprocess.Popen( |
69 cmd_line, stdout=subprocess.PIPE, stdin=subprocess.PIPE, | 77 cmd_line, stdout=subprocess.PIPE, stdin=subprocess.PIPE, |
70 stderr=subprocess.PIPE, bufsize=1) | 78 stderr=subprocess.PIPE, bufsize=1) |
71 atexit_with_log.Register(self.StopServer) | 79 atexit_with_log.Register(self.StopServer) |
72 try: | 80 try: |
73 py_utils.WaitFor(self._IsStarted, timeout) | 81 py_utils.WaitFor(self._IsStarted, timeout) |
74 logging.info('TsProxy port: %s', self._port) | 82 logging.info('TsProxy port: %s', self._port) |
75 self._is_running = True | 83 self._is_running = True |
76 except py_utils.TimeoutException: | 84 except py_utils.TimeoutException: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return err | 144 return err |
137 | 145 |
138 def __enter__(self): | 146 def __enter__(self): |
139 """Add support for with-statement.""" | 147 """Add support for with-statement.""" |
140 self.StartServer() | 148 self.StartServer() |
141 return self | 149 return self |
142 | 150 |
143 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 151 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
144 """Add support for with-statement.""" | 152 """Add support for with-statement.""" |
145 self.StopServer() | 153 self.StopServer() |
OLD | NEW |