Commit 24129ebc authored by maruel@chromium.org's avatar maruel@chromium.org

Fix presubmit check compatibility with GAE SDK 1.7.6 (bis).

Improve temporary storage management.

Print the error message on local GAE instance failure.

Useful to debug when a new version of the GAE SDK breaks something.

TBR=iannucci@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/13997004

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@194131 0039d316-1c4b-4281-b951-d872f2087c98
parent 5f17da32
...@@ -10,11 +10,13 @@ It makes sure Google AppEngine SDK is found, download Rietveld and Django code ...@@ -10,11 +10,13 @@ It makes sure Google AppEngine SDK is found, download Rietveld and Django code
if necessary and starts the server on a free inbound TCP port. if necessary and starts the server on a free inbound TCP port.
""" """
import logging
import optparse import optparse
import os import os
import shutil import shutil
import socket import socket
import sys import sys
import tempfile
import time import time
try: try:
...@@ -61,6 +63,7 @@ class LocalRietveld(object): ...@@ -61,6 +63,7 @@ class LocalRietveld(object):
self.rietveld = os.path.join(self.base_dir, '_rietveld') self.rietveld = os.path.join(self.base_dir, '_rietveld')
self.test_server = None self.test_server = None
self.port = None self.port = None
self.tempdir = None
# Find the GAE SDK # Find the GAE SDK
previous_dir = '' previous_dir = ''
...@@ -105,19 +108,23 @@ class LocalRietveld(object): ...@@ -105,19 +108,23 @@ class LocalRietveld(object):
def start_server(self, verbose=False): def start_server(self, verbose=False):
self.install_prerequisites() self.install_prerequisites()
assert not self.tempdir
self.tempdir = tempfile.mkdtemp(prefix='rietveld_test')
self.port = find_free_port() self.port = find_free_port()
if verbose: if verbose:
pipe = None stdout = stderr = None
else: else:
pipe = subprocess2.VOID stdout = subprocess2.PIPE
stderr = subprocess2.STDOUT
cmd = [ cmd = [
sys.executable, sys.executable,
self.dev_app, self.dev_app,
'--skip_sdk_update_check',
'.', '.',
'--port=%d' % self.port, '--port', str(self.port),
'--datastore_path=' + os.path.join(self.rietveld, 'tmp.db'), '--storage', self.tempdir,
'-c'] '--clear_search_indexes',
'--skip_sdk_update_check',
]
# CHEAP TRICK # CHEAP TRICK
# By default you only want to bind on loopback but I'm testing over a # By default you only want to bind on loopback but I'm testing over a
...@@ -125,16 +132,20 @@ class LocalRietveld(object): ...@@ -125,16 +132,20 @@ class LocalRietveld(object):
# remotely. # remotely.
if os.environ.get('GAE_LISTEN_ALL', '') == 'true': if os.environ.get('GAE_LISTEN_ALL', '') == 'true':
cmd.extend(('-a', '0.0.0.0')) cmd.extend(('-a', '0.0.0.0'))
logging.info(' '.join(cmd))
self.test_server = subprocess2.Popen( self.test_server = subprocess2.Popen(
cmd, stdout=pipe, stderr=pipe, cwd=self.rietveld) cmd, stdout=stdout, stderr=stderr, cwd=self.rietveld)
# Loop until port 127.0.0.1:port opens or the process dies. # Loop until port 127.0.0.1:port opens or the process dies.
while not test_port(self.port): while not test_port(self.port):
self.test_server.poll() self.test_server.poll()
if self.test_server.returncode is not None: if self.test_server.returncode is not None:
if not verbose:
out = self.test_server.communicate()[0]
shutil.rmtree(self.tempdir)
self.tempdir = None
raise Failure( raise Failure(
'Test rietveld instance failed early on port %s' % 'Test rietveld instance failed early on port %s\n%s' %
self.port) (self.port, out))
time.sleep(0.01) time.sleep(0.01)
def stop_server(self): def stop_server(self):
...@@ -146,6 +157,9 @@ class LocalRietveld(object): ...@@ -146,6 +157,9 @@ class LocalRietveld(object):
self.test_server.wait() self.test_server.wait()
self.test_server = None self.test_server = None
self.port = None self.port = None
if self.tempdir:
shutil.rmtree(self.tempdir)
self.tempdir = None
def main(): def main():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment