| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 |
| 6 from recipe_engine import recipe_api |
| 7 |
| 8 |
| 9 CT_GS_BUCKET = 'cluster-telemetry' |
| 10 |
| 11 |
| 12 class CTSwarmingApi(recipe_api.RecipeApi): |
| 13 """Provides steps to run CT tasks on swarming bots.""" |
| 14 |
| 15 @property |
| 16 def downloads_dir(self): |
| 17 """Path to where artifacts should be downloaded from Google Storage.""" |
| 18 return self.m.path['checkout'].join('content', 'test', 'ct') |
| 19 |
| 20 @property |
| 21 def swarming_temp_dir(self): |
| 22 """Path where artifacts like isolate file and json output will be stored.""" |
| 23 return self.m.path['tmp_base'].join('swarming_temp_dir') |
| 24 |
| 25 @property |
| 26 def tasks_output_dir(self): |
| 27 """Directory where the outputs of the swarming tasks will be stored.""" |
| 28 return self.swarming_temp_dir.join('outputs') |
| 29 |
| 30 def checkout_dependencies(self): |
| 31 """Checks out all repositories required for CT to run on swarming bots.""" |
| 32 # Checkout chromium and swarming. |
| 33 self.m.chromium.set_config('chromium') |
| 34 self.m.gclient.set_config('chromium') |
| 35 self.m.bot_update.ensure_checkout(force=True) |
| 36 self.m.swarming_client.checkout() |
| 37 # Ensure swarming_client is compatible with what recipes expect. |
| 38 self.m.swarming.check_client_version() |
| 39 |
| 40 def download_CT_binary(self, ct_binary_name): |
| 41 """Downloads the specified CT binary from GS into the downloads_dir.""" |
| 42 binary_dest = self.downloads_dir.join(ct_binary_name) |
| 43 self.m.gsutil.download( |
| 44 name="download %s" % ct_binary_name, |
| 45 bucket=CT_GS_BUCKET, |
| 46 source='swarming/binaries/%s' % ct_binary_name, |
| 47 dest=binary_dest) |
| 48 # Set executable bit on the binary. |
| 49 self.m.python.inline( |
| 50 name='Set executable bit on %s' % ct_binary_name, |
| 51 program=''' |
| 52 import os |
| 53 import stat |
| 54 |
| 55 os.chmod('%s', os.stat('%s').st_mode | stat.S_IEXEC) |
| 56 ''' % (str(binary_dest), str(binary_dest)) |
| 57 ) |
| 58 |
| 59 def download_page_artifacts(self, page_type, slave_num): |
| 60 """Downloads all the artifacts needed to run benchmarks on a page. |
| 61 |
| 62 The artifacts are downloaded into subdirectories in the downloads_dir. |
| 63 |
| 64 Args: |
| 65 page_type: str. The CT page type. Eg: 1k, 10k. |
| 66 slave_num: int. The number of the slave used to determine which GS |
| 67 directory to download from. Eg: for the top 1k, slave1 will |
| 68 contain webpages 1-10, slave2 will contain 11-20. |
| 69 """ |
| 70 # Download page sets. |
| 71 page_sets_dir = self.downloads_dir.join('slave%s' % slave_num, 'page_sets') |
| 72 self.m.file.makedirs('Create page_sets dir', page_sets_dir) |
| 73 self.m.gsutil.download( |
| 74 bucket=CT_GS_BUCKET, |
| 75 source='swarming/page_sets/%s/slave%s/*' % (page_type, slave_num), |
| 76 dest=page_sets_dir) |
| 77 |
| 78 # Download archives. |
| 79 wpr_dir = page_sets_dir.join('data') |
| 80 self.m.file.makedirs('Create WPR dir', wpr_dir) |
| 81 self.m.gsutil.download( |
| 82 bucket=CT_GS_BUCKET, |
| 83 source='swarming/webpage_archives/%s/slave%s/*' % (page_type, |
| 84 slave_num), |
| 85 dest=wpr_dir) |
| 86 |
| 87 def create_isolated_gen_json(self, isolate_path, base_dir, os_type, |
| 88 slave_num, extra_variables): |
| 89 """Creates an isolated.gen.json file. |
| 90 |
| 91 Args: |
| 92 isolate_path: path obj. Path to the isolate file. |
| 93 base_dir: path obj. Dir that is the base of all paths in the isolate file. |
| 94 os_type: str. The OS type to use when archiving the isolate file. |
| 95 Eg: linux. |
| 96 slave_num: int. The slave we want to create isolated.gen.json file for. |
| 97 extra_variables: dict of str to str. The extra vars to pass to isolate. |
| 98 Eg: {'SLAVE_NUM': '1', 'MASTER': 'ChromiumPerfFYI'} |
| 99 |
| 100 Returns: |
| 101 Path to the isolated.gen.json file. |
| 102 """ |
| 103 self.m.file.makedirs('Create swarming tmp dir', self.swarming_temp_dir) |
| 104 isolated_path = self.swarming_temp_dir.join( |
| 105 'ct-task-%s.isolated' % slave_num) |
| 106 isolate_args = [ |
| 107 '--isolate', isolate_path, |
| 108 '--isolated', isolated_path, |
| 109 '--config-variable', 'OS', os_type, |
| 110 ] |
| 111 for k, v in extra_variables.iteritems(): |
| 112 isolate_args.extend(['--extra-variable', k, v]) |
| 113 isolated_gen_dict = { |
| 114 'version': 1, |
| 115 'dir': base_dir, |
| 116 'args': isolate_args, |
| 117 } |
| 118 isolated_gen_json = self.swarming_temp_dir.join( |
| 119 'slave%s.isolated.gen.json' % slave_num) |
| 120 self.m.file.write( |
| 121 'Write slave%s.isolated.gen.json' % slave_num, |
| 122 isolated_gen_json, |
| 123 self.m.json.dumps(isolated_gen_dict, indent=4), |
| 124 ) |
| 125 |
| 126 def batcharchive(self, num_slaves): |
| 127 """Calls batcharchive on the specified isolated.gen.json files. |
| 128 |
| 129 Args: |
| 130 num_slaves: int. The number of slaves we will batcharchive |
| 131 isolated.gen.json files for. |
| 132 """ |
| 133 self.m.isolate.isolate_tests( |
| 134 build_dir=self.swarming_temp_dir, |
| 135 targets=['slave%s' % num for num in range(1, num_slaves+1)]) |
| 136 |
| 137 def trigger_swarming_tasks(self, swarm_hashes, task_name_prefix, dimensions): |
| 138 """Triggers swarming tasks using swarm hashes. |
| 139 |
| 140 Args: |
| 141 swarm_hashes: list of str. List of swarm hashes from the isolate server. |
| 142 task_name_prefix: The prefix to use when creating task_name. |
| 143 dimensions: dict of str to str. The dimensions to run the task on. |
| 144 Eg: {'os': 'Ubuntu', 'gpu': '10de'} |
| 145 Returns: |
| 146 List of swarming.SwarmingTask instances. |
| 147 """ |
| 148 swarming_tasks = [] |
| 149 for task_num, swarm_hash in enumerate(swarm_hashes): |
| 150 swarming_task = self.m.swarming.task( |
| 151 title='%s-%s' % (task_name_prefix, task_num+1), |
| 152 isolated_hash=swarm_hash, |
| 153 task_output_dir=self.tasks_output_dir.join('slave%s' % (task_num+1))) |
| 154 swarming_task.dimensions = dimensions |
| 155 swarming_task.priority = 90 |
| 156 swarming_tasks.append(swarming_task) |
| 157 self.m.swarming.trigger(swarming_tasks) |
| 158 return swarming_tasks |
| 159 |
| 160 def collect_swarming_tasks(self, swarming_tasks): |
| 161 """Collects all swarming tasks triggered by this recipe. |
| 162 |
| 163 Args: |
| 164 swarming_tasks: list of swarming.SwarmingTask instances. |
| 165 """ |
| 166 return self.m.swarming.collect(swarming_tasks) |
| OLD | NEW |