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

Side by Side Diff: testing_support/local_rietveld.py

Issue 13997004: Fix presubmit check compatibility with GAE SDK 1.7.6 (bis). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Setups a local Rietveld instance to test against a live server for 6 """Setups a local Rietveld instance to test against a live server for
7 integration tests. 7 integration tests.
8 8
9 It makes sure Google AppEngine SDK is found, download Rietveld and Django code 9 It makes sure Google AppEngine SDK is found, download Rietveld and Django code
10 if necessary and starts the server on a free inbound TCP port. 10 if necessary and starts the server on a free inbound TCP port.
11 """ 11 """
12 12
13 import logging
13 import optparse 14 import optparse
14 import os 15 import os
15 import shutil 16 import shutil
16 import socket 17 import socket
17 import sys 18 import sys
19 import tempfile
18 import time 20 import time
19 21
20 try: 22 try:
21 import subprocess2 23 import subprocess2
22 except ImportError: 24 except ImportError:
23 sys.path.append( 25 sys.path.append(
24 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) 26 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
25 import subprocess2 27 import subprocess2
26 28
27 29
(...skipping 26 matching lines...) Expand all
54 def __init__(self, base_dir=None): 56 def __init__(self, base_dir=None):
55 # Paths 57 # Paths
56 self.base_dir = base_dir 58 self.base_dir = base_dir
57 if not self.base_dir: 59 if not self.base_dir:
58 self.base_dir = os.path.dirname(os.path.abspath(__file__)) 60 self.base_dir = os.path.dirname(os.path.abspath(__file__))
59 # TODO(maruel): This should be in /tmp but that would mean having to fetch 61 # TODO(maruel): This should be in /tmp but that would mean having to fetch
60 # everytime. This test is already annoyingly slow. 62 # everytime. This test is already annoyingly slow.
61 self.rietveld = os.path.join(self.base_dir, '_rietveld') 63 self.rietveld = os.path.join(self.base_dir, '_rietveld')
62 self.test_server = None 64 self.test_server = None
63 self.port = None 65 self.port = None
66 self.tempdir = None
64 67
65 # Find the GAE SDK 68 # Find the GAE SDK
66 previous_dir = '' 69 previous_dir = ''
67 self.sdk_path = '' 70 self.sdk_path = ''
68 base_dir = self.base_dir 71 base_dir = self.base_dir
69 while base_dir != previous_dir: 72 while base_dir != previous_dir:
70 previous_dir = base_dir 73 previous_dir = base_dir
71 self.sdk_path = os.path.join(base_dir, 'google_appengine') 74 self.sdk_path = os.path.join(base_dir, 'google_appengine')
72 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): 75 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')):
73 base_dir = os.path.dirname(base_dir) 76 base_dir = os.path.dirname(base_dir)
(...skipping 24 matching lines...) Expand all
98 else: 101 else:
99 print('Syncing rietveld...') 102 print('Syncing rietveld...')
100 try: 103 try:
101 subprocess2.check_call( 104 subprocess2.check_call(
102 ['hg', 'co', '-q', '-C', rev], cwd=self.rietveld) 105 ['hg', 'co', '-q', '-C', rev], cwd=self.rietveld)
103 except (OSError, subprocess2.CalledProcessError), e: 106 except (OSError, subprocess2.CalledProcessError), e:
104 raise Failure('Failed to sync rietveld\n%s' % e) 107 raise Failure('Failed to sync rietveld\n%s' % e)
105 108
106 def start_server(self, verbose=False): 109 def start_server(self, verbose=False):
107 self.install_prerequisites() 110 self.install_prerequisites()
111 assert not self.tempdir
112 self.tempdir = tempfile.mkdtemp(prefix='rietveld_test')
108 self.port = find_free_port() 113 self.port = find_free_port()
109 if verbose: 114 if verbose:
110 pipe = None 115 stdout = stderr = None
111 else: 116 else:
112 pipe = subprocess2.VOID 117 stdout = subprocess2.PIPE
118 stderr = subprocess2.STDOUT
113 cmd = [ 119 cmd = [
114 sys.executable, 120 sys.executable,
115 self.dev_app, 121 self.dev_app,
122 '.',
123 '--port', str(self.port),
124 '--storage', self.tempdir,
125 '--clear_search_indexes',
116 '--skip_sdk_update_check', 126 '--skip_sdk_update_check',
117 '.', 127 ]
118 '--port=%d' % self.port,
119 '--datastore_path=' + os.path.join(self.rietveld, 'tmp.db'),
120 '-c']
121 128
122 # CHEAP TRICK 129 # CHEAP TRICK
123 # By default you only want to bind on loopback but I'm testing over a 130 # By default you only want to bind on loopback but I'm testing over a
124 # headless computer so it's useful to be able to access the test instance 131 # headless computer so it's useful to be able to access the test instance
125 # remotely. 132 # remotely.
126 if os.environ.get('GAE_LISTEN_ALL', '') == 'true': 133 if os.environ.get('GAE_LISTEN_ALL', '') == 'true':
127 cmd.extend(('-a', '0.0.0.0')) 134 cmd.extend(('-a', '0.0.0.0'))
128 135 logging.info(' '.join(cmd))
129 self.test_server = subprocess2.Popen( 136 self.test_server = subprocess2.Popen(
130 cmd, stdout=pipe, stderr=pipe, cwd=self.rietveld) 137 cmd, stdout=stdout, stderr=stderr, cwd=self.rietveld)
131 # Loop until port 127.0.0.1:port opens or the process dies. 138 # Loop until port 127.0.0.1:port opens or the process dies.
132 while not test_port(self.port): 139 while not test_port(self.port):
133 self.test_server.poll() 140 self.test_server.poll()
134 if self.test_server.returncode is not None: 141 if self.test_server.returncode is not None:
142 if not verbose:
143 out = self.test_server.communicate()[0]
144 shutil.rmtree(self.tempdir)
145 self.tempdir = None
135 raise Failure( 146 raise Failure(
136 'Test rietveld instance failed early on port %s' % 147 'Test rietveld instance failed early on port %s\n%s' %
137 self.port) 148 (self.port, out))
138 time.sleep(0.01) 149 time.sleep(0.01)
139 150
140 def stop_server(self): 151 def stop_server(self):
141 if self.test_server: 152 if self.test_server:
142 try: 153 try:
143 self.test_server.kill() 154 self.test_server.kill()
144 except OSError: 155 except OSError:
145 pass 156 pass
146 self.test_server.wait() 157 self.test_server.wait()
147 self.test_server = None 158 self.test_server = None
148 self.port = None 159 self.port = None
160 if self.tempdir:
161 shutil.rmtree(self.tempdir)
162 self.tempdir = None
149 163
150 164
151 def main(): 165 def main():
152 parser = optparse.OptionParser() 166 parser = optparse.OptionParser()
153 parser.add_option('-v', '--verbose', action='store_true') 167 parser.add_option('-v', '--verbose', action='store_true')
154 options, args = parser.parse_args() 168 options, args = parser.parse_args()
155 if args: 169 if args:
156 parser.error('Unknown arguments: %s' % ' '.join(args)) 170 parser.error('Unknown arguments: %s' % ' '.join(args))
157 instance = LocalRietveld() 171 instance = LocalRietveld()
158 try: 172 try:
159 instance.start_server(verbose=options.verbose) 173 instance.start_server(verbose=options.verbose)
160 print 'Local rietveld instance started on port %d' % instance.port 174 print 'Local rietveld instance started on port %d' % instance.port
161 while True: 175 while True:
162 time.sleep(0.1) 176 time.sleep(0.1)
163 finally: 177 finally:
164 instance.stop_server() 178 instance.stop_server()
165 179
166 180
167 if __name__ == '__main__': 181 if __name__ == '__main__':
168 main() 182 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698