Fix mb.py swarming retcode
Fixes mb.py always exiting with 0 when running tests on swarming even if the task failed. This was caused by the switch to the Go version of the swarming tools, which no longer exit with the task's exit code. Instead, we need to tell the swarming tool to output JSON and extract the exit code from that. Change-Id: If47cbee20e6abf5a1328eb6af1080475fd1d897e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2649346 Commit-Queue: Brian Sheedy <bsheedy@chromium.org> Commit-Queue: Ben Pastene <bpastene@chromium.org> Reviewed-by: Ben Pastene <bpastene@chromium.org> Auto-Submit: Brian Sheedy <bsheedy@chromium.org> Cr-Commit-Position: refs/heads/master@{#847288}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
59b52468f8
commit
f74debdff1
tools/mb
@ -694,18 +694,26 @@ class MetaBuildWrapper(object):
|
||||
return ret
|
||||
task_json = self.ReadFile(json_file)
|
||||
task_id = json.loads(task_json)["tasks"][0]['task_id']
|
||||
collect_output = self.PathJoin(json_dir, 'collect_output.json')
|
||||
cmd = [
|
||||
self.PathJoin('tools', 'luci-go', 'swarming'),
|
||||
'collect',
|
||||
'-server',
|
||||
swarming_server,
|
||||
'-task-output-stdout=console',
|
||||
'-task-summary-json',
|
||||
collect_output,
|
||||
task_id,
|
||||
]
|
||||
ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
|
||||
if ret != 0:
|
||||
return ret
|
||||
collect_json = json.loads(self.ReadFile(collect_output))
|
||||
# The exit_code field is not included if the task was successful.
|
||||
ret = collect_json.get(task_id, {}).get('results', {}).get('exit_code', 0)
|
||||
finally:
|
||||
if json_dir:
|
||||
self.RemoveDirectory(json_dir)
|
||||
cmd = [
|
||||
self.PathJoin('tools', 'luci-go', 'swarming'),
|
||||
'collect',
|
||||
'-server',
|
||||
swarming_server,
|
||||
'-task-output-stdout=console',
|
||||
task_id,
|
||||
]
|
||||
ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
|
||||
return ret
|
||||
|
||||
def _RunLocallyIsolated(self, build_dir, target):
|
||||
|
@ -724,9 +724,11 @@ class UnitTest(unittest.TestCase):
|
||||
}
|
||||
|
||||
task_json = json.dumps({'tasks': [{'task_id': '00000'}]})
|
||||
collect_json = json.dumps({'00000': {'results': {}}})
|
||||
|
||||
mbw = self.fake_mbw(files=files)
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json
|
||||
original_impl = mbw.ToSrcRelPath
|
||||
|
||||
def to_src_rel_path_stub(path):
|
||||
@ -740,10 +742,57 @@ class UnitTest(unittest.TestCase):
|
||||
'base_unittests'], mbw=mbw, ret=0)
|
||||
mbw = self.fake_mbw(files=files)
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json
|
||||
mbw.ToSrcRelPath = to_src_rel_path_stub
|
||||
self.check(['run', '-s', '-c', 'debug_goma', '-d', 'os', 'Win7',
|
||||
'//out/Default', 'base_unittests'], mbw=mbw, ret=0)
|
||||
|
||||
def test_run_swarmed_task_failure(self):
|
||||
files = {
|
||||
'/fake_src/testing/buildbot/gn_isolate_map.pyl':
|
||||
("{'base_unittests': {"
|
||||
" 'label': '//base:base_unittests',"
|
||||
" 'type': 'console_test_launcher',"
|
||||
"}}\n"),
|
||||
'/fake_src/out/Default/base_unittests.runtime_deps':
|
||||
("base_unittests\n"),
|
||||
'/fake_src/out/Default/base_unittests.archive.json':
|
||||
("{\"base_unittests\":\"fake_hash\"}"),
|
||||
'/fake_src/third_party/depot_tools/cipd_manifest.txt':
|
||||
("# vpython\n"
|
||||
"/some/vpython/pkg git_revision:deadbeef\n"),
|
||||
}
|
||||
|
||||
task_json = json.dumps({'tasks': [{'task_id': '00000'}]})
|
||||
collect_json = json.dumps({'00000': {'results': {'exit_code': 1}}})
|
||||
|
||||
mbw = self.fake_mbw(files=files)
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json
|
||||
original_impl = mbw.ToSrcRelPath
|
||||
|
||||
def to_src_rel_path_stub(path):
|
||||
if path.endswith('base_unittests.archive.json'):
|
||||
return 'base_unittests.archive.json'
|
||||
return original_impl(path)
|
||||
|
||||
mbw.ToSrcRelPath = to_src_rel_path_stub
|
||||
|
||||
self.check(
|
||||
['run', '-s', '-c', 'debug_goma', '//out/Default', 'base_unittests'],
|
||||
mbw=mbw,
|
||||
ret=1)
|
||||
mbw = self.fake_mbw(files=files)
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'task.json')] = task_json
|
||||
mbw.files[mbw.PathJoin(mbw.TempDir(), 'collect_output.json')] = collect_json
|
||||
mbw.ToSrcRelPath = to_src_rel_path_stub
|
||||
self.check([
|
||||
'run', '-s', '-c', 'debug_goma', '-d', 'os', 'Win7', '//out/Default',
|
||||
'base_unittests'
|
||||
],
|
||||
mbw=mbw,
|
||||
ret=1)
|
||||
|
||||
def test_lookup(self):
|
||||
self.check(['lookup', '-c', 'debug_goma'], ret=0,
|
||||
out=('\n'
|
||||
|
Reference in New Issue
Block a user