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

Unified Diff: scripts/slave/run_slavelastic.py

Issue 10035003: Split up Each Swarm Test into Two Steps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Adding tests to presubmit Created 8 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 side-by-side diff with in-line comments
Download patch
Index: scripts/slave/run_slavelastic.py
diff --git a/scripts/slave/run_slavelastic.py b/scripts/slave/run_slavelastic.py
index 0497b74a5ff545736220b156ddfc29f9a5816542..108e92745e46860d44456ac92486c618f595e414 100755
--- a/scripts/slave/run_slavelastic.py
+++ b/scripts/slave/run_slavelastic.py
@@ -5,7 +5,7 @@
# run_slavelastic.py: Runs a test based off of a slavelastic manifest file.
from __future__ import with_statement
-import json # pylint: disable=F0401
+import json
import optparse
import os
import platform
@@ -47,7 +47,7 @@ class Manifest(object):
'num_shards': switches.num_shards,
'os_image': current_platform,
}
- self.name = filename
+ self.manifest_name = filename
self.g_shards = switches.num_shards
# Random name for the output zip file
@@ -57,6 +57,7 @@ class Manifest(object):
self.current_platform = current_platform
self.target_platform = switches_dict['os_image']
self.working_dir = switches.working_dir
+ self.test_name = switches.test_name
def add_task(self, task_name, actions):
"""Appends a new task to the swarm manifest file."""
@@ -70,7 +71,7 @@ class Manifest(object):
start_time = time.time()
zip_file = zipfile.ZipFile(self.zipfile_name, 'w')
- zip_file.write(self.name)
+ zip_file.write(self.manifest_name)
zip_file.write(self.run_test_path)
zip_file.close()
@@ -88,7 +89,7 @@ class Manifest(object):
url = 'http://%s/hashtable/' % hostname
self.add_task(
'Run Test',
- ['python', self.run_test_path, '-m', self.name, '-r', url])
+ ['python', self.run_test_path, '-m', self.manifest_name, '-r', url])
# Clean up
if self.current_platform == 'Linux' or self.current_platform == 'Mac':
@@ -104,7 +105,7 @@ class Manifest(object):
# Construct test case
test_case = {
- 'test_case_name': self.name,
+ 'test_case_name': self.test_name,
'data': [
'http://%s/%s' % (hostname, filepath),
],
@@ -130,83 +131,6 @@ class Manifest(object):
return json.dumps(test_case)
-def _get_first_number(line):
- for part in line.split():
- if part.isdigit():
- return int(part)
-
- print 'No number in :'
- print line
- return 0
-
-
-class TestSummary(object):
- def __init__(self):
- self.test_passed_count = 0
- self.failed_tests = []
- self.disabled_test_count = 0
- self.ignored_test_count = 0
-
- def AddSummaryData(self, buf):
- lines = buf.splitlines()
-
- for line in lines:
- if '[ PASSED ]' in line:
- self.test_passed_count += _get_first_number(line)
- elif '[ FAILED ]' in line:
- if ', listed below' not in line:
- self.failed_tests.append(line)
- elif 'DISABLED' in line:
- self.disabled_test_count += _get_first_number(line)
- elif 'failures' in line:
- self.ignored_test_count += _get_first_number(line)
-
- def Output(self):
- output = []
-
- output.append('[ PASSED ] %i tests.' % self.test_passed_count)
- if self.failed_tests:
- output.append('[ FAILED ] failed tests listed below:')
- output.extend(self.failed_tests)
- output.append('%i FAILED TESTS' % len(self.failed_tests))
-
- if self.disabled_test_count:
- output.append('%i DISABLED TESTS' % self.disabled_test_count)
-
- if self.ignored_test_count:
- output.append('%i tests with ignored failures (FAILS prefix)' %
- self.ignored_test_count)
-
- return output
-
- def exit_code(self):
- return int(bool(self.failed_tests))
-
-
-# TODO(csharp) The sharing_supervisor.py also has test parsing code, they should
-# be shared.
-def TestRunOutput(output):
- """Go through the given output and only return the output from the Test Run
- Step.
- """
- test_run_output = []
-
- in_step = False
- step_name = ''
- for line in output.splitlines():
- if in_step:
- if '[ OK ] ' + step_name in line:
- break
- else:
- test_run_output.append(line)
- elif '[ RUN ] ' in line and 'Run Test' in line:
- in_step = True
- i = len('[ RUN ] ')
- step_name = line[i:]
-
- return '\n'.join(test_run_output)
-
-
def main():
"""Packages up a Slavelastic test and send it to swarm. Receive output from
all shards and print it to stdout.
@@ -231,12 +155,15 @@ def main():
parser.add_option('-o', '--os_image',
help='Swarm OS image to request. Defaults to the '
'current platform.')
- parser.add_option('-n', '--hostname', default='localhost',
- help='Specify the hostname of the Swarm server. '
+ parser.add_option('-u', '--url', default='http://localhost',
+ help='Specify the url of the Swarm server. '
'Defaults to %default')
parser.add_option('-p', '--port', type='int', default=8080,
M-A Ruel 2012/04/19 19:07:19 Eventually should die too.
csharp 2012/04/19 19:23:22 Removed (might as well keep the two swarm communic
help='Specify the port of the Swarm server. '
'Defaults to %default')
+ parser.add_option('-t', '--test_name',
+ help='Specify the name to give the swarm test request. '
+ 'Defaults to the given filename')
parser.add_option('-v', '--verbose', action='store_true',
help='Print verbose logging')
(options, args) = parser.parse_args()
@@ -247,6 +174,8 @@ def main():
filename = args[0]
if not options.os_image:
options.os_image = '%s %d' % (platform.uname()[0], 32)
+ if not options.test_name:
+ options.test_name = filename
# Parses manifest file
print "Parsing file %s..." % filename
@@ -258,71 +187,21 @@ def main():
# Send test requests off to swarm.
print 'Sending test requests to swarm'
- base_url = 'http://%s:%d' % (options.hostname, options.port)
+ base_url = '%s:%d' % (options.hostname, options.port)
test_url = base_url + '/test'
manifest_text = manifest.to_json()
result = urllib2.urlopen(test_url, manifest_text).read()
# Check that we can read the output as a JSON string
try:
- test_keys = json.loads(result)
+ json.loads(result)
except (ValueError, TypeError), e:
print 'Request failed:'
print result
+ print e
return 1
- running_test_keys = test_keys['test_keys']
-
- # TODO(csharp) Get hostnames from key through swarm
- hostnames = ['localhost' for i in range(options.num_shards)]
-
- # TODO(csharp) Get exit codes from key through swarm
- exit_codes = [0 for i in range(options.num_shards)]
-
- # Listen to output_destination
- summary_total = TestSummary()
- for index in range(options.num_shards):
- print
- print '===================================================================='
- print 'Begin output from shard index %d (%s)' % (index, hostnames[i])
- print '===================================================================='
- print
- while True:
- try:
- key_url = '%s/get_result?r=%s' % (base_url,
- running_test_keys[index]['test_key'])
- output = urllib2.urlopen(key_url).read()
-
- if output:
- cleaned_output = TestRunOutput(output)
- summary_index = cleaned_output.rfind('[ PASSED ]')
- summary_total.AddSummaryData(cleaned_output[summary_index:])
- sys.stdout.write(cleaned_output[:summary_index - 1])
- break
- else:
- # Test is not yet done, wait a bit before checking again.
- time.sleep(0.5)
- except urllib2.HTTPError, e:
- print 'Calling %s threw %s' % (key_url, e)
- print
- print '===================================================================='
- print 'End output from shard index %d (%s). Return %d' % (index,
- hostnames[i], exit_codes[i])
- print '===================================================================='
- print
- manifest.cleanup() # Delete temp zip file
-
- print '\n'.join(summary_total.Output())
- print
-
- if options.verbose:
- print 'All tests completed:'
- for i in range(options.num_shards):
- print 'Shard index %d (%s): Exit code: %d' % (i,
- hostnames[i], exit_codes[i])
-
- # TODO(csharp) replace with max exit code once exit_codes gets real values
- return summary_total.exit_code()
+ return 0
if __name__ == '__main__':
sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698