Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 3 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
Kuang-che Wu | 68db08a | 2018-03-30 11:50:34 +0800 | [diff] [blame] | 6 | """Helper script to manipulate chromeos DUT or query info.""" |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 7 | from __future__ import print_function |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 8 | import asyncio |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 9 | import argparse |
| 10 | import json |
| 11 | import logging |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 12 | import random |
| 13 | import time |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 14 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 15 | from bisect_kit import cli |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 16 | from bisect_kit import common |
Kuang-che Wu | c45cfa4 | 2019-01-15 00:15:01 +0800 | [diff] [blame] | 17 | from bisect_kit import cros_lab_util |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 18 | from bisect_kit import cros_util |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 19 | from bisect_kit import errors |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 20 | |
Zheng-Jie Chang | 17f36c8 | 2020-06-16 05:21:59 +0800 | [diff] [blame] | 21 | DEFAULT_DUT_POOL = 'DUT_POOL_QUOTA' |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 22 | logger = logging.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | def cmd_version_info(opts): |
| 26 | info = cros_util.version_info(opts.board, opts.version) |
| 27 | if opts.name: |
| 28 | if opts.name not in info: |
| 29 | logger.error('unknown name=%s', opts.name) |
| 30 | print(info[opts.name]) |
| 31 | else: |
| 32 | print(json.dumps(info, sort_keys=True, indent=4)) |
| 33 | |
| 34 | |
| 35 | def cmd_query_dut_board(opts): |
| 36 | assert cros_util.is_dut(opts.dut) |
| 37 | print(cros_util.query_dut_board(opts.dut)) |
| 38 | |
| 39 | |
| 40 | def cmd_reboot(opts): |
| 41 | assert cros_util.is_dut(opts.dut) |
Kuang-che Wu | 2ac9a92 | 2020-09-03 16:50:12 +0800 | [diff] [blame] | 42 | cros_util.reboot( |
| 43 | opts.dut, force_reboot_callback=cros_lab_util.reboot_via_servo) |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 44 | |
| 45 | |
Kuang-che Wu | c45cfa4 | 2019-01-15 00:15:01 +0800 | [diff] [blame] | 46 | def _get_label_by_prefix(info, prefix): |
| 47 | for label in info['Labels']: |
| 48 | if label.startswith(prefix + ':'): |
| 49 | return label |
| 50 | return None |
| 51 | |
| 52 | |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 53 | def cmd_lease_dut(opts): |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 54 | if opts.duration is not None and opts.duration < 60: |
| 55 | raise errors.ArgumentError('--duration', 'must be at least 60 seconds') |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 56 | host = cros_lab_util.dut_host_name(opts.dut) |
Kuang-che Wu | 220cc16 | 2019-10-31 00:29:37 +0800 | [diff] [blame] | 57 | logger.info('trying to lease %s', host) |
| 58 | if cros_lab_util.skylab_lease_dut(host, opts.duration): |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 59 | logger.info('leased %s', host) |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 60 | else: |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 61 | raise Exception('unable to lease %s' % host) |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 62 | |
| 63 | |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 64 | def cmd_release_dut(opts): |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 65 | host = cros_lab_util.dut_host_name(opts.dut) |
Kuang-che Wu | 220cc16 | 2019-10-31 00:29:37 +0800 | [diff] [blame] | 66 | cros_lab_util.skylab_release_dut(host) |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 67 | logger.info('%s released', host) |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 68 | |
| 69 | |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 70 | def verify_dimensions_by_lab(dimensions): |
| 71 | result = [] |
| 72 | bots_dimensions = cros_lab_util.swarming_bots_dimensions() |
| 73 | for dimension in dimensions: |
| 74 | key, value = dimension.split(':', 1) |
| 75 | if value in bots_dimensions.get(key, []): |
| 76 | result.append(dimension) |
| 77 | else: |
| 78 | logger.warning('dimension=%s is unknown in the lab, typo? ignored', |
| 79 | dimension) |
| 80 | return result |
| 81 | |
| 82 | |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 83 | def select_available_bots_randomly(dimensions, variants, num=1, is_busy=None): |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 84 | bots = [] |
| 85 | for variant in variants: |
| 86 | # There might be thousand bots available, set 'limit' to reduce swarming |
| 87 | # API cost. This is not uniform random, but should be good enough. |
| 88 | bots += cros_lab_util.swarming_bots_list( |
| 89 | dimensions + [variant], is_busy=is_busy, limit=10) |
| 90 | if not bots: |
| 91 | return None |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 92 | return random.sample(bots, min(num, len(bots))) |
| 93 | |
| 94 | |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 95 | def filter_dimensions_by_board(boards_with_prebuilt, dimensions): |
| 96 | result = [] |
| 97 | for dimension in dimensions: |
| 98 | bots = cros_lab_util.swarming_bots_list([dimension], is_busy=None, limit=1) |
| 99 | if not bots: |
| 100 | continue |
| 101 | board = bots[0]['dimensions']['label-board'][0] |
| 102 | if board not in boards_with_prebuilt: |
| 103 | logger.warning( |
| 104 | 'dimension=%s (board=%s) does not have corresponding ' |
| 105 | 'prebuilt image, ignore', dimension, board) |
| 106 | continue |
| 107 | result.append(dimension) |
| 108 | return result |
| 109 | |
| 110 | |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 111 | async def lease_dut_parallelly(duration, bots, timeout=None): |
| 112 | tasks = [] |
| 113 | hosts = [] |
| 114 | for bot in bots: |
| 115 | host = bot['dimensions']['dut_name'][0] |
| 116 | hosts.append(host) |
| 117 | tasks.append( |
| 118 | asyncio.create_task(cros_lab_util.async_lease(host, duration=duration))) |
| 119 | |
| 120 | try: |
| 121 | logger.info('trying to lease %d DUTs: %s', len(hosts), hosts) |
| 122 | for coro in asyncio.as_completed(tasks, timeout=timeout): |
| 123 | host = await coro |
| 124 | if host: |
| 125 | logger.info('leased %s', host) |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 126 | # Unfinished lease tasks will be cancelled when asyncio.run is |
| 127 | # finishing. |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 128 | return host |
| 129 | return None |
| 130 | except asyncio.TimeoutError: |
| 131 | return None |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 132 | |
| 133 | |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 134 | def do_allocate_dut(opts): |
| 135 | """Helper of cmd_allocate_dut. |
| 136 | |
| 137 | Returns: |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 138 | (todo, host, board_to_build) |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 139 | todo: 'ready' or 'wait' |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 140 | host: leased host name |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 141 | board_to_build: board name for building image |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 142 | """ |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 143 | if not opts.dut_name and not opts.pool: |
| 144 | raise errors.ArgumentError('--pool', |
| 145 | 'need to be specified if not --dut_name') |
Kuang-che Wu | 7e8abe6 | 2020-07-02 09:42:27 +0800 | [diff] [blame] | 146 | if opts.version_hint: |
| 147 | for v in opts.version_hint.split(','): |
| 148 | if cros_util.is_cros_version(v) or cros_util.is_cros_snapshot_version(v): |
| 149 | continue |
| 150 | raise errors.ArgumentError( |
| 151 | '--version_hint', |
| 152 | 'should be Chrome OS version numbers, separated by comma') |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 153 | if opts.duration is not None and opts.duration < 60: |
| 154 | raise errors.ArgumentError('--duration', 'must be at least 60 seconds') |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 155 | |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 156 | t0 = time.time() |
Zheng-Jie Chang | 17f36c8 | 2020-06-16 05:21:59 +0800 | [diff] [blame] | 157 | dimensions = ['dut_state:ready'] |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 158 | if not opts.dut_name: |
Zheng-Jie Chang | 17f36c8 | 2020-06-16 05:21:59 +0800 | [diff] [blame] | 159 | dimensions.append('label-pool:' + opts.pool) |
| 160 | |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 161 | variants = [] |
| 162 | if opts.board: |
| 163 | for board in opts.board.split(','): |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 164 | variants.append('label-board:' + |
| 165 | cros_lab_util.normalize_board_name(board)) |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 166 | if opts.model: |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 167 | for model in opts.model.split(','): |
| 168 | variants.append('label-model:' + model) |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 169 | if opts.sku: |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 170 | for sku in opts.sku.split(','): |
| 171 | variants.append('label-hwid_sku:' + cros_lab_util.normalize_sku_name(sku)) |
| 172 | if opts.dut_name: |
| 173 | for dut_name in opts.dut_name.split(','): |
| 174 | variants.append('dut_name:' + dut_name) |
| 175 | |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 176 | variants = verify_dimensions_by_lab(variants) |
| 177 | variants = sorted(set(variants)) # dedup |
| 178 | if not variants: |
| 179 | raise errors.NoDutAvailable( |
| 180 | 'Invalid constraints: %s;%s;%s;%s' % |
| 181 | (opts.board, opts.model, opts.sku, opts.dut_name)) |
| 182 | |
| 183 | # Filter variants by prebuilt images. |
| 184 | if opts.version_hint: |
| 185 | if not opts.builder_hint: |
| 186 | opts.builder_hint = opts.board |
| 187 | if not opts.builder_hint: |
| 188 | raise errors.ArgumentError('--builder_hint', |
| 189 | 'must be specified along with --version_hint') |
| 190 | boards_with_prebuilt = [] |
| 191 | versions = opts.version_hint.split(',') |
| 192 | for builder in opts.builder_hint.split(','): |
| 193 | if not all(cros_util.has_test_image(builder, v) for v in versions): |
| 194 | logger.warning( |
| 195 | 'builder=%s does not have prebuilt test image for %s, ignore', |
| 196 | builder, opts.version_hint) |
| 197 | continue |
| 198 | boards_with_prebuilt.append(cros_lab_util.normalize_board_name(builder)) |
| 199 | logger.info('boards with prebuilt: %s', boards_with_prebuilt) |
| 200 | if not boards_with_prebuilt: |
| 201 | raise errors.ArgumentError( |
| 202 | '--version_hint', |
| 203 | 'given builders have no prebuilt for %s' % opts.version_hint) |
| 204 | variants = filter_dimensions_by_board(boards_with_prebuilt, variants) |
| 205 | if not variants: |
| 206 | raise errors.NoDutAvailable( |
| 207 | 'Devices with specified constraints have no prebuilt. ' |
| 208 | 'Wrong version number?') |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 209 | |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 210 | while True: |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 211 | # Query every time because each iteration takes a few minutes |
| 212 | bots = select_available_bots_randomly( |
| 213 | dimensions, variants, num=opts.parallel, is_busy=False) |
| 214 | if not bots: |
| 215 | bots = select_available_bots_randomly( |
| 216 | dimensions, variants, num=opts.parallel, is_busy=True) |
| 217 | if not bots: |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 218 | raise errors.NoDutAvailable( |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 219 | 'no bots satisfy constraints; all are in maintenance state?') |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 220 | |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 221 | remaining_time = opts.time_limit - (time.time() - t0) |
| 222 | if remaining_time <= 0: |
| 223 | break |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 224 | timeout = min(120, remaining_time) |
| 225 | host = asyncio.run(lease_dut_parallelly(opts.duration, bots, timeout)) |
| 226 | if host: |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 227 | # Resolve what board we should build during bisection. |
| 228 | board_to_build = None |
| 229 | bots = cros_lab_util.swarming_bots_list(['dut_name:' + host]) |
| 230 | host_board = bots[0]['dimensions']['label-board'][0] |
| 231 | if opts.builder_hint: |
| 232 | for builder in opts.builder_hint.split(','): |
| 233 | if cros_lab_util.normalize_board_name(builder) == host_board: |
| 234 | board_to_build = builder |
| 235 | break |
| 236 | else: |
| 237 | board_to_build = host_board |
| 238 | |
| 239 | return 'ready', host, board_to_build |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 240 | time.sleep(1) |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 241 | |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 242 | logger.warning('unable to lease DUT in time limit') |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 243 | return 'wait', None, None |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 244 | |
| 245 | |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 246 | def cmd_allocate_dut(opts): |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 247 | leased_dut = None |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 248 | try: |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 249 | todo, host, board = do_allocate_dut(opts) |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 250 | leased_dut = cros_lab_util.dut_name_to_address(host) if host else None |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 251 | result = {'result': todo, 'leased_dut': leased_dut, 'board': board} |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 252 | print(json.dumps(result)) |
| 253 | except Exception as e: |
| 254 | logger.exception('cmd_allocate_dut failed') |
| 255 | exception_name = e.__class__.__name__ |
| 256 | result = { |
| 257 | 'result': 'failed', |
| 258 | 'exception': exception_name, |
| 259 | 'text': str(e), |
| 260 | } |
| 261 | print(json.dumps(result)) |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 262 | |
| 263 | |
Kuang-che Wu | a8c3c3e | 2019-08-28 18:49:28 +0800 | [diff] [blame] | 264 | def cmd_repair_dut(opts): |
| 265 | cros_lab_util.repair(opts.dut) |
| 266 | |
| 267 | |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 268 | @cli.fatal_error_handler |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 269 | def main(): |
| 270 | common.init() |
| 271 | parser = argparse.ArgumentParser() |
Kuang-che Wu | fe1e88a | 2019-09-10 21:52:25 +0800 | [diff] [blame] | 272 | cli.patching_argparser_exit(parser) |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 273 | common.add_common_arguments(parser) |
| 274 | subparsers = parser.add_subparsers( |
| 275 | dest='command', title='commands', metavar='<command>') |
| 276 | |
| 277 | parser_version_info = subparsers.add_parser( |
| 278 | 'version_info', |
| 279 | help='Query version info of given chromeos build', |
| 280 | description='Given chromeos `board` and `version`, ' |
| 281 | 'print version information of components.') |
| 282 | parser_version_info.add_argument( |
| 283 | 'board', help='ChromeOS board name, like "samus".') |
| 284 | parser_version_info.add_argument( |
| 285 | 'version', |
| 286 | type=cros_util.argtype_cros_version, |
| 287 | help='ChromeOS version, like "9876.0.0" or "R62-9876.0.0"') |
| 288 | parser_version_info.add_argument( |
| 289 | 'name', |
| 290 | nargs='?', |
| 291 | help='Component name. If specified, output its version string. ' |
| 292 | 'Otherwise output all version info as dict in json format.') |
| 293 | parser_version_info.set_defaults(func=cmd_version_info) |
| 294 | |
| 295 | parser_query_dut_board = subparsers.add_parser( |
| 296 | 'query_dut_board', help='Query board name of given DUT') |
| 297 | parser_query_dut_board.add_argument('dut') |
| 298 | parser_query_dut_board.set_defaults(func=cmd_query_dut_board) |
| 299 | |
| 300 | parser_reboot = subparsers.add_parser( |
| 301 | 'reboot', |
| 302 | help='Reboot a DUT', |
| 303 | description='Reboot a DUT and verify the reboot is successful.') |
| 304 | parser_reboot.add_argument('dut') |
| 305 | parser_reboot.set_defaults(func=cmd_reboot) |
| 306 | |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 307 | parser_lease_dut = subparsers.add_parser( |
| 308 | 'lease_dut', |
| 309 | help='Lease a DUT in the lab', |
| 310 | description='Lease a DUT in the lab. ' |
| 311 | 'This is implemented by `skylab lease-dut` with additional checking.') |
| 312 | # "skylab lease-dut" doesn't take reason, so this is not required=True. |
| 313 | parser_lease_dut.add_argument('--session', help='session name') |
| 314 | parser_lease_dut.add_argument('dut') |
| 315 | parser_lease_dut.add_argument( |
| 316 | '--duration', |
| 317 | type=float, |
| 318 | help='duration in seconds; will be round to minutes') |
| 319 | parser_lease_dut.set_defaults(func=cmd_lease_dut) |
| 320 | |
| 321 | parser_release_dut = subparsers.add_parser( |
| 322 | 'release_dut', |
| 323 | help='Release a DUT in the lab', |
| 324 | description='Release a DUT in the lab. ' |
| 325 | 'This is implemented by `skylab release-dut` with additional checking.') |
| 326 | parser_release_dut.add_argument('--session', help='session name') |
| 327 | parser_release_dut.add_argument('dut') |
| 328 | parser_release_dut.set_defaults(func=cmd_release_dut) |
| 329 | |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 330 | parser_allocate_dut = subparsers.add_parser( |
| 331 | 'allocate_dut', |
| 332 | help='Allocate a DUT in the lab', |
Kuang-che Wu | ca45646 | 2019-11-04 17:32:55 +0800 | [diff] [blame] | 333 | description='Allocate a DUT in the lab. It will lease a DUT in the lab ' |
| 334 | 'for bisecting. The caller (bisect-kit runner) of this command should ' |
| 335 | 'retry this command again later if no DUT available now.') |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 336 | parser_allocate_dut.add_argument( |
| 337 | '--session', required=True, help='session name') |
| 338 | parser_allocate_dut.add_argument( |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 339 | '--pool', |
| 340 | help='Pool to search DUT (default: %(default)s)', |
| 341 | default=DEFAULT_DUT_POOL) |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 342 | group = parser_allocate_dut.add_mutually_exclusive_group(required=True) |
| 343 | group.add_argument('--board', help='allocation criteria; comma separated') |
| 344 | group.add_argument('--model', help='allocation criteria; comma separated') |
| 345 | group.add_argument('--sku', help='allocation criteria; comma separated') |
| 346 | group.add_argument('--dut_name', help='allocation criteria; comma separated') |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 347 | parser_allocate_dut.add_argument( |
Kuang-che Wu | 1e56ce2 | 2020-06-29 11:21:51 +0800 | [diff] [blame] | 348 | '--version_hint', help='chromeos version; comma separated') |
Kuang-che Wu | b529d2d | 2020-09-10 12:26:56 +0800 | [diff] [blame^] | 349 | parser_allocate_dut.add_argument( |
| 350 | '--builder_hint', help='chromeos builder; comma separated') |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 351 | # Pubsub ack deadline is 10 minutes (b/143663659). Default 9 minutes with 1 |
| 352 | # minute buffer. |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 353 | parser_allocate_dut.add_argument( |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 354 | '--time_limit', |
| 355 | type=int, |
Kuang-che Wu | c26dcdf | 2019-11-01 16:30:06 +0800 | [diff] [blame] | 356 | default=9 * 60, |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 357 | help='Time limit to attempt lease in seconds (default: %(default)s)') |
| 358 | parser_allocate_dut.add_argument( |
| 359 | '--duration', |
| 360 | type=float, |
| 361 | help='lease duration in seconds; will be round to minutes') |
Kuang-che Wu | 5157dee | 2020-07-18 01:13:41 +0800 | [diff] [blame] | 362 | parser_allocate_dut.add_argument( |
| 363 | '--parallel', |
| 364 | type=int, |
| 365 | default=1, |
| 366 | help='Submit multiple lease tasks to speed up (default: %(default)d)') |
Kuang-che Wu | 22aa9d4 | 2019-01-25 10:35:33 +0800 | [diff] [blame] | 367 | parser_allocate_dut.set_defaults(func=cmd_allocate_dut) |
| 368 | |
Kuang-che Wu | a8c3c3e | 2019-08-28 18:49:28 +0800 | [diff] [blame] | 369 | parser_repair_dut = subparsers.add_parser( |
| 370 | 'repair_dut', |
| 371 | help='Repair a DUT in the lab', |
| 372 | description='Repair a DUT in the lab. ' |
| 373 | 'This is simply wrapper of "deploy repair" with additional checking.') |
| 374 | parser_repair_dut.add_argument('dut') |
| 375 | parser_repair_dut.set_defaults(func=cmd_repair_dut) |
| 376 | |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 377 | opts = parser.parse_args() |
| 378 | common.config_logging(opts) |
Kuang-che Wu | d3a4e84 | 2019-12-11 12:15:23 +0800 | [diff] [blame] | 379 | |
| 380 | # It's optional by default since python3. |
| 381 | if not opts.command: |
| 382 | parser.error('command is missing') |
Kuang-che Wu | 2ea804f | 2017-11-28 17:11:41 +0800 | [diff] [blame] | 383 | opts.func(opts) |
| 384 | |
| 385 | |
| 386 | if __name__ == '__main__': |
| 387 | main() |