OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Functions that deal with local and device ports.""" | 5 """Functions that deal with local and device ports.""" |
6 | 6 |
7 import contextlib | 7 import contextlib |
8 import fcntl | 8 import fcntl |
9 import httplib | 9 import httplib |
10 import logging | 10 import logging |
11 import os | 11 import os |
12 import re | 12 import re |
13 import socket | 13 import socket |
14 import traceback | 14 import traceback |
15 | 15 |
16 import cmd_helper | 16 from pylib import cmd_helper |
17 import constants | 17 from pylib import constants |
18 | 18 |
19 | 19 |
20 # The following two methods are used to allocate the port source for various | 20 # The following two methods are used to allocate the port source for various |
21 # types of test servers. Because some net-related tests can be run on shards at | 21 # types of test servers. Because some net-related tests can be run on shards at |
22 # same time, it's important to have a mechanism to allocate the port | 22 # same time, it's important to have a mechanism to allocate the port |
23 # process-safe. In here, we implement the safe port allocation by leveraging | 23 # process-safe. In here, we implement the safe port allocation by leveraging |
24 # flock. | 24 # flock. |
25 def ResetTestServerPortAllocation(): | 25 def ResetTestServerPortAllocation(): |
26 """Resets the port allocation to start from TEST_SERVER_PORT_FIRST. | 26 """Resets the port allocation to start from TEST_SERVER_PORT_FIRST. |
27 | 27 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 client_error = ('Bad response: %s %s version %s\n ' % | 167 client_error = ('Bad response: %s %s version %s\n ' % |
168 (r.status, r.reason, r.version) + | 168 (r.status, r.reason, r.version) + |
169 '\n '.join([': '.join(h) for h in r.getheaders()])) | 169 '\n '.join([': '.join(h) for h in r.getheaders()])) |
170 except (httplib.HTTPException, socket.error) as e: | 170 except (httplib.HTTPException, socket.error) as e: |
171 # Probably too quick connecting: try again. | 171 # Probably too quick connecting: try again. |
172 exception_error_msgs = traceback.format_exception_only(type(e), e) | 172 exception_error_msgs = traceback.format_exception_only(type(e), e) |
173 if exception_error_msgs: | 173 if exception_error_msgs: |
174 client_error = ''.join(exception_error_msgs) | 174 client_error = ''.join(exception_error_msgs) |
175 # Only returns last client_error. | 175 # Only returns last client_error. |
176 return (False, client_error or 'Timeout') | 176 return (False, client_error or 'Timeout') |
OLD | NEW |