| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Swarming Authors. All rights reserved. | 2 # Copyright 2014 The Swarming Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Tools to control application running via dev_appserver.py. | 6 """Tools to control application running via dev_appserver.py. |
| 7 | 7 |
| 8 Useful for smoke and integration tests. | 8 Useful for smoke and integration tests. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import collections | 11 import collections |
| 12 import cookielib | 12 import cookielib |
| 13 import ctypes | 13 import ctypes |
| 14 import json | 14 import json |
| 15 import logging | 15 import logging |
| 16 import os | 16 import os |
| 17 import shutil | 17 import shutil |
| 18 import socket | 18 import socket |
| 19 import subprocess | 19 import subprocess |
| 20 import sys | 20 import sys |
| 21 import tempfile | 21 import tempfile |
| 22 import time | 22 import time |
| 23 import urllib2 | 23 import urllib2 |
| 24 | 24 |
| 25 from . import gae_sdk_utils | 25 from . import gae_sdk_utils |
| 26 | 26 |
| 27 from utils import file_path |
| 28 |
| 27 | 29 |
| 28 def terminate_with_parent(): | 30 def terminate_with_parent(): |
| 29 """Sets up current process to receive SIGTERM when its parent dies. | 31 """Sets up current process to receive SIGTERM when its parent dies. |
| 30 | 32 |
| 31 Works on Linux only. On Win and Mac it's noop. | 33 Works on Linux only. On Win and Mac it's noop. |
| 32 """ | 34 """ |
| 33 try: | 35 try: |
| 34 libc = ctypes.CDLL('libc.so.6') | 36 libc = ctypes.CDLL('libc.so.6') |
| 35 except OSError: | 37 except OSError: |
| 36 return | 38 return |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 while self._proc.poll() is None and time.time() < deadline: | 203 while self._proc.poll() is None and time.time() < deadline: |
| 202 time.sleep(0.05) | 204 time.sleep(0.05) |
| 203 exit_code = self._proc.poll() | 205 exit_code = self._proc.poll() |
| 204 if exit_code is None: | 206 if exit_code is None: |
| 205 logging.error('Leaking PID %d', self._proc.pid) | 207 logging.error('Leaking PID %d', self._proc.pid) |
| 206 finally: | 208 finally: |
| 207 with open(os.path.join(self._temp_root, 'dev_appserver.log'), 'r') as f: | 209 with open(os.path.join(self._temp_root, 'dev_appserver.log'), 'r') as f: |
| 208 self._log = f.read() | 210 self._log = f.read() |
| 209 if not leak: | 211 if not leak: |
| 210 try: | 212 try: |
| 211 shutil.rmtree(self._temp_root) | 213 file_path.rmtree(self._temp_root) |
| 212 except OSError as e: | 214 except OSError as e: |
| 213 # Log but ignore it to not mask other errors. | 215 # Log but ignore it to not mask other errors. |
| 214 print >> sys.stderr, str(e) | 216 print >> sys.stderr, str(e) |
| 215 self._client = None | 217 self._client = None |
| 216 self._port = None | 218 self._port = None |
| 217 self._proc = None | 219 self._proc = None |
| 218 self._serving = False | 220 self._serving = False |
| 219 self._temp_root = None | 221 self._temp_root = None |
| 220 return exit_code | 222 return exit_code |
| 221 | 223 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 295 |
| 294 It only works with apps that use 'auth' component. | 296 It only works with apps that use 'auth' component. |
| 295 """ | 297 """ |
| 296 if self._xsrf_token is None: | 298 if self._xsrf_token is None: |
| 297 resp = self.json_request( | 299 resp = self.json_request( |
| 298 '/auth/api/v1/accounts/self/xsrf_token', | 300 '/auth/api/v1/accounts/self/xsrf_token', |
| 299 body={}, | 301 body={}, |
| 300 headers={'X-XSRF-Token-Request': '1'}) | 302 headers={'X-XSRF-Token-Request': '1'}) |
| 301 self._xsrf_token = resp.body['xsrf_token'].encode('ascii') | 303 self._xsrf_token = resp.body['xsrf_token'].encode('ascii') |
| 302 return self._xsrf_token | 304 return self._xsrf_token |
| OLD | NEW |