Commit 3fd9ba25 authored by Takuto Ikuta's avatar Takuto Ikuta Committed by Chromium LUCI CQ

trigger_scripts: support go client in chromeos_device_trigger

This scripts needs json conversion similar to
https://source.chromium.org/chromium/chromium/src/+/master:testing/trigger_scripts/base_test_triggerer.py;l=316-334;drc=e4b6e9349b783a53e3efcc45e54e6632f874ca62
when using go client.

This is fix for breakage like
https://ci.chromium.org/p/chrome/builders/ci/chromeos-eve-chrome/12159

Cq-Include-Trybots: luci.chromium.try:chromeos-kevin-rel
Cq-Include-Trybots: luci.chrome.try:chromeos-eve-chrome
Bug: 1127205
Change-Id: Ibf980d44b4b30855ed61e3d487bd683adf948003
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2635275Reviewed-by: default avatarBen Pastene <bpastene@chromium.org>
Reviewed-by: default avatarWenbin Zhang <wenbinzhang@google.com>
Commit-Queue: Takuto Ikuta <tikuta@chromium.org>
Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844979}
parent a31e3d6f
......@@ -239,10 +239,30 @@ class BaseTestTriggerer(object):
logging.info('Running Swarming with args: %s', args)
return subprocess.call([sys.executable, SWARMING_PY] + args)
def run_swarming_go(self, args, verbose):
def run_swarming_go(self, args, verbose, json_path, merged_json=None):
if verbose:
logging.info('Running Go `swarming` with args: %s', args)
return subprocess.call([SWARMING_GO] + _convert_to_go_swarming_args(args))
ret = subprocess.call([SWARMING_GO] + _convert_to_go_swarming_args(args))
result_json = self.read_json_from_temp_file(json_path)
if not merged_json:
# Copy the entire JSON -- in particular, the "request"
# dictionary -- from the first shard. "swarming.py collect" uses
# some keys from this dictionary, in particular related to
# expiration. It also contains useful debugging information.
merged_json = copy.deepcopy(result_json)
# However, reset the "tasks" entry to an empty dictionary,
# which will be handled specially.
merged_json['tasks'] = {}
tasks = {
task['request']['task_id']: task['request']
for task in result_json['tasks']
}
for k, v in tasks.items():
v['shard_index'] = shard_index
merged_json['tasks'][k + ':%d:%d' % (shard_index, args.shards)] = v
self.write_json_to_file(merged_json, json_path)
return ret
def prune_test_specific_configs(self, args, verbose):
# Ability for base class to further prune configs to
......@@ -307,12 +327,18 @@ class BaseTestTriggerer(object):
args_to_pass = self.modify_args(filtered_remaining_args, bot_index,
shard_index, args.shards, json_temp)
if args.use_swarming_go:
ret = self.run_swarming_go(args_to_pass, verbose)
ret = self.run_swarming_go(
args_to_pass, verbose, json_temp, merged_json)
else:
ret = self.run_swarming(args_to_pass, verbose)
if ret:
sys.stderr.write('Failed to trigger a task, aborting\n')
return ret
if args.use_swarming_go:
continue
# TODO(crbug.com/1127205): remove belows in this block.
result_json = self.read_json_from_temp_file(json_temp)
if not merged_json:
# Copy the entire JSON -- in particular, the "request"
......@@ -324,11 +350,6 @@ class BaseTestTriggerer(object):
# which will be handled specially.
merged_json['tasks'] = {}
tasks = result_json['tasks']
if args.use_swarming_go:
# TODO(crbug.com/1127205): remove this
tasks = {
task['request']['task_id']: task['request'] for task in tasks
}
for k, v in tasks.items():
v['shard_index'] = shard_index
merged_json['tasks'][k + ':%d:%d' % (shard_index, args.shards)] = v
......
......@@ -65,18 +65,10 @@ def parse_args(triggerer):
dest='optional_dimensions',
help='Optional dimensions which will result in additional task slices. '
'Duplicated from the `swarming.py trigger` command.')
# BaseTestTriggerer's setup_parser_contract() takes care of adding needed
# swarming.py args if they're not already present. But only do this if
# '--shard-index' is passed in. (The exact usage of trigger scripts are
# currently changing. See crbug.com/926987 for more info.)
if '--shard-index' in sys.argv:
base_test_triggerer.BaseTestTriggerer.setup_parser_contract(parser)
args, additional_args = parser.parse_known_args()
additional_args = triggerer.modify_args(
additional_args, 0, args.shard_index, args.shards, args.dump_json)
else:
base_test_triggerer.BaseTestTriggerer.add_use_swarming_go_arg(parser)
args, additional_args = parser.parse_known_args()
base_test_triggerer.BaseTestTriggerer.setup_parser_contract(parser)
args, additional_args = parser.parse_known_args()
additional_args = triggerer.modify_args(
additional_args, 0, args.shard_index, args.shards, args.dump_json)
if additional_args[0] != 'trigger':
parser.error(
......@@ -130,7 +122,8 @@ def main():
new_args += additional_args[1:]
if args.use_swarming_go:
return triggerer.run_swarming_go(new_args, True)
return triggerer.run_swarming_go(new_args, True, args.dump_json)
return triggerer.run_swarming(new_args, True)
......
......@@ -53,7 +53,7 @@ class FakeTriggerer(perf_device_trigger.PerfDeviceTriggerer):
del verbose #unused
self._swarming_runs.append(args)
def run_swarming_go(self, args, verbose):
def run_swarming_go(self, args, verbose, _json_path, _merged_json=None):
self._triggered_with_swarming_go += 1
self.run_swarming(args, verbose)
......
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