| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 from recipe_engine import recipe_api | 6 from recipe_engine import recipe_api |
| 7 import shlex | 7 import shlex |
| 8 | 8 |
| 9 | 9 |
| 10 class SkiaSwarmingApi(recipe_api.RecipeApi): | 10 class SkiaSwarmingApi(recipe_api.RecipeApi): |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 dest = self.m.path['slave_build'].join('luci-go') | 49 dest = self.m.path['slave_build'].join('luci-go') |
| 50 self.m.file.rmtree('Go binary dir', dest) | 50 self.m.file.rmtree('Go binary dir', dest) |
| 51 self.m.file.copytree('Copy Go binary', | 51 self.m.file.copytree('Copy Go binary', |
| 52 source=luci_go_dir, | 52 source=luci_go_dir, |
| 53 dest=dest) | 53 dest=dest) |
| 54 | 54 |
| 55 def isolate_and_trigger_task(self, isolate_path, isolate_base_dir, task_name, | 55 def isolate_and_trigger_task(self, isolate_path, isolate_base_dir, task_name, |
| 56 isolate_vars, swarm_dimensions, | 56 isolate_vars, swarm_dimensions, |
| 57 isolate_blacklist=None, | 57 isolate_blacklist=None, |
| 58 extra_isolate_hashes=None, idempotent=False, | 58 extra_isolate_hashes=None, idempotent=False, |
| 59 store_output=True): | 59 store_output=True, extra_args=None): |
| 60 """Isolate inputs and trigger the task to run.""" | 60 """Isolate inputs and trigger the task to run.""" |
| 61 isolated_hash = self.isolate_task(isolate_path, isolate_base_dir, task_name, | 61 isolated_hash = self.isolate_task(isolate_path, isolate_base_dir, task_name, |
| 62 isolate_vars, blacklist=isolate_blacklist, | 62 isolate_vars, blacklist=isolate_blacklist, |
| 63 extra_hashes=extra_isolate_hashes) | 63 extra_hashes=extra_isolate_hashes) |
| 64 tasks = self.trigger_swarming_tasks([(task_name, isolated_hash)], | 64 tasks = self.trigger_swarming_tasks([(task_name, isolated_hash)], |
| 65 swarm_dimensions, | 65 swarm_dimensions, |
| 66 idempotent=idempotent, | 66 idempotent=idempotent, |
| 67 store_output=store_output) | 67 store_output=store_output, |
| 68 extra_args=extra_args) |
| 68 assert len(tasks) == 1 | 69 assert len(tasks) == 1 |
| 69 return tasks[0] | 70 return tasks[0] |
| 70 | 71 |
| 71 def isolate_task(self, isolate_path, base_dir, task_name, | 72 def isolate_task(self, isolate_path, base_dir, task_name, |
| 72 isolate_vars, blacklist=None, extra_hashes=None): | 73 isolate_vars, blacklist=None, extra_hashes=None): |
| 73 """Isolate inputs for the given task.""" | 74 """Isolate inputs for the given task.""" |
| 74 self.create_isolated_gen_json(isolate_path, base_dir, 'linux', | 75 self.create_isolated_gen_json(isolate_path, base_dir, 'linux', |
| 75 task_name, isolate_vars, | 76 task_name, isolate_vars, |
| 76 blacklist=blacklist) | 77 blacklist=blacklist) |
| 77 hashes = self.batcharchive([task_name]) | 78 hashes = self.batcharchive([task_name]) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Returns: | 146 Returns: |
| 146 Updated hash of the .isolated file. | 147 Updated hash of the .isolated file. |
| 147 """ | 148 """ |
| 148 isolated_file = self.isolated_file_path(task_name) | 149 isolated_file = self.isolated_file_path(task_name) |
| 149 self.m.python.inline('add_isolated_input', program=""" | 150 self.m.python.inline('add_isolated_input', program=""" |
| 150 import json | 151 import json |
| 151 import sys | 152 import sys |
| 152 with open(sys.argv[1]) as f: | 153 with open(sys.argv[1]) as f: |
| 153 isolated = json.load(f) | 154 isolated = json.load(f) |
| 154 for h in sys.argv[2:]: | 155 for h in sys.argv[2:]: |
| 155 isolated['includes'].append(sys.argv[2]) | 156 isolated['includes'].append(h) |
| 156 with open(sys.argv[1], 'w') as f: | 157 with open(sys.argv[1], 'w') as f: |
| 157 json.dump(isolated, f, sort_keys=True) | 158 json.dump(isolated, f, sort_keys=True) |
| 158 """, args=[isolated_file] + include_hashes) | 159 """, args=[isolated_file] + include_hashes) |
| 159 isolateserver = self.m.swarming_client.path.join('isolateserver.py') | 160 isolateserver = self.m.swarming_client.path.join('isolateserver.py') |
| 160 r = self.m.python('upload new .isolated file for %s' % task_name, | 161 r = self.m.python('upload new .isolated file for %s' % task_name, |
| 161 script=isolateserver, | 162 script=isolateserver, |
| 162 args=['archive', '--isolate-server', | 163 args=['archive', '--isolate-server', |
| 163 self.m.isolate.isolate_server, isolated_file], | 164 self.m.isolate.isolate_server, isolated_file], |
| 164 stdout=self.m.raw_io.output()) | 165 stdout=self.m.raw_io.output()) |
| 165 return shlex.split(r.stdout)[0] | 166 return shlex.split(r.stdout)[0] |
| 166 | 167 |
| 167 def trigger_swarming_tasks(self, swarm_hashes, dimensions, idempotent=False, | 168 def trigger_swarming_tasks(self, swarm_hashes, dimensions, idempotent=False, |
| 168 store_output=True): | 169 store_output=True, extra_args=None): |
| 169 """Triggers swarming tasks using swarm hashes. | 170 """Triggers swarming tasks using swarm hashes. |
| 170 | 171 |
| 171 Args: | 172 Args: |
| 172 swarm_hashes: list of str. List of swarm hashes from the isolate server. | 173 swarm_hashes: list of str. List of swarm hashes from the isolate server. |
| 173 dimensions: dict of str to str. The dimensions to run the task on. | 174 dimensions: dict of str to str. The dimensions to run the task on. |
| 174 Eg: {'os': 'Ubuntu', 'gpu': '10de', 'pool': 'Skia'} | 175 Eg: {'os': 'Ubuntu', 'gpu': '10de', 'pool': 'Skia'} |
| 175 idempotent: whether or not to de-duplicate tasks. | 176 idempotent: whether or not to de-duplicate tasks. |
| 176 Returns: | 177 Returns: |
| 177 List of swarming.SwarmingTask instances. | 178 List of swarming.SwarmingTask instances. |
| 178 """ | 179 """ |
| 179 swarming_tasks = [] | 180 swarming_tasks = [] |
| 180 for task_name, swarm_hash in swarm_hashes: | 181 for task_name, swarm_hash in swarm_hashes: |
| 181 swarming_task = self.m.swarming.task( | 182 swarming_task = self.m.swarming.task( |
| 182 title=task_name, | 183 title=task_name, |
| 183 isolated_hash=swarm_hash) | 184 isolated_hash=swarm_hash) |
| 184 if store_output: | 185 if store_output: |
| 185 swarming_task.task_output_dir = self.tasks_output_dir.join(task_name) | 186 swarming_task.task_output_dir = self.tasks_output_dir.join(task_name) |
| 186 swarming_task.dimensions = dimensions | 187 swarming_task.dimensions = dimensions |
| 187 swarming_task.idempotent = idempotent | 188 swarming_task.idempotent = idempotent |
| 188 swarming_task.priority = 90 | 189 swarming_task.priority = 90 |
| 189 swarming_task.expiration = 4*60*60 | 190 swarming_task.expiration = 4*60*60 |
| 191 if extra_args: |
| 192 swarming_task.extra_args = extra_args |
| 190 swarming_tasks.append(swarming_task) | 193 swarming_tasks.append(swarming_task) |
| 191 self.m.swarming.trigger(swarming_tasks) | 194 self.m.swarming.trigger(swarming_tasks) |
| 192 return swarming_tasks | 195 return swarming_tasks |
| 193 | 196 |
| 194 def collect_swarming_task(self, swarming_task): | 197 def collect_swarming_task(self, swarming_task): |
| 195 """Collects the specified swarming task. | 198 """Collects the specified swarming task. |
| 196 | 199 |
| 197 Args: | 200 Args: |
| 198 swarming_task: An instance of swarming.SwarmingTask. | 201 swarming_task: An instance of swarming.SwarmingTask. |
| 199 """ | 202 """ |
| 200 return self.m.swarming.collect_task(swarming_task) | 203 return self.m.swarming.collect_task(swarming_task) |
| 201 | 204 |
| 202 def collect_swarming_task_isolate_hash(self, swarming_task): | 205 def collect_swarming_task_isolate_hash(self, swarming_task): |
| 203 """Wait for the given swarming task to finish and return its output hash. | 206 """Wait for the given swarming task to finish and return its output hash. |
| 204 | 207 |
| 205 Args: | 208 Args: |
| 206 swarming_task: An instance of swarming.SwarmingTask. | 209 swarming_task: An instance of swarming.SwarmingTask. |
| 207 Returns: | 210 Returns: |
| 208 the hash of the isolate output of the task. | 211 the hash of the isolate output of the task. |
| 209 """ | 212 """ |
| 210 res = self.collect_swarming_task(swarming_task) | 213 res = self.collect_swarming_task(swarming_task) |
| 211 return res.json.output['shards'][0]['isolated_out']['isolated'] | 214 return res.json.output['shards'][0]['isolated_out']['isolated'] |
| OLD | NEW |