blob: 2b535f9ea91f0e5b0f683874771eb5deee329d01 [file] [log] [blame]
Kuang-che Wu875c89a2020-01-08 14:30:55 +08001#!/usr/bin/env python3
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08003# 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 Wu68db08a2018-03-30 11:50:34 +08006"""Helper script to manipulate chromeos DUT or query info."""
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08007from __future__ import print_function
8import argparse
Kuang-che Wu9d14c162020-11-03 19:35:18 +08009import asyncio
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080010import json
11import logging
Kuang-che Wu9d14c162020-11-03 19:35:18 +080012import os
Kuang-che Wu0c9b7942019-10-30 16:55:39 +080013import random
14import time
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080015
Kuang-che Wufe1e88a2019-09-10 21:52:25 +080016from bisect_kit import cli
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080017from bisect_kit import common
Kuang-che Wu9d14c162020-11-03 19:35:18 +080018from bisect_kit import configure
Kuang-che Wuc45cfa42019-01-15 00:15:01 +080019from bisect_kit import cros_lab_util
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080020from bisect_kit import cros_util
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080021from bisect_kit import errors
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080022
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +080023DEFAULT_DUT_POOL = 'DUT_POOL_QUOTA'
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080024logger = logging.getLogger(__name__)
25
Kuang-che Wu25723422020-09-24 22:20:26 +080026models_to_avoid = {
27 # model: reason
28 'kasumi': 'b/160458394 stateful partition is too small',
29 'mimrock': 'b/160458394 stateful partition is too small',
30 'vorticon': 'b/160458394 stateful partition is too small',
31}
32
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080033
34def cmd_version_info(opts):
35 info = cros_util.version_info(opts.board, opts.version)
36 if opts.name:
37 if opts.name not in info:
38 logger.error('unknown name=%s', opts.name)
39 print(info[opts.name])
40 else:
41 print(json.dumps(info, sort_keys=True, indent=4))
42
43
44def cmd_query_dut_board(opts):
45 assert cros_util.is_dut(opts.dut)
46 print(cros_util.query_dut_board(opts.dut))
47
48
49def cmd_reboot(opts):
Kuang-che Wu2534bab2020-10-23 17:37:16 +080050 if not cros_util.is_dut(opts.dut):
51 if opts.force:
52 logger.warning('%s is not a Chrome OS device?', opts.dut)
53 else:
54 raise errors.ArgumentError(
55 'dut', 'not a Chrome OS device (--force to continue)')
56
Kuang-che Wu2ac9a922020-09-03 16:50:12 +080057 cros_util.reboot(
58 opts.dut, force_reboot_callback=cros_lab_util.reboot_via_servo)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080059
60
Kuang-che Wuc45cfa42019-01-15 00:15:01 +080061def _get_label_by_prefix(info, prefix):
62 for label in info['Labels']:
63 if label.startswith(prefix + ':'):
64 return label
65 return None
66
67
Kuang-che Wuca456462019-11-04 17:32:55 +080068def cmd_lease_dut(opts):
Kuang-che Wu5157dee2020-07-18 01:13:41 +080069 if opts.duration is not None and opts.duration < 60:
70 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
Kuang-che Wu7c1fa582021-01-14 17:57:49 +080071 reason = opts.reason or cros_lab_util.make_lease_reason(opts.session)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080072 host = cros_lab_util.dut_host_name(opts.dut)
Kuang-che Wu220cc162019-10-31 00:29:37 +080073 logger.info('trying to lease %s', host)
Kuang-che Wu7c1fa582021-01-14 17:57:49 +080074 if cros_lab_util.skylab_lease_dut(host, reason, opts.duration):
Kuang-che Wuca456462019-11-04 17:32:55 +080075 logger.info('leased %s', host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080076 else:
Kuang-che Wuca456462019-11-04 17:32:55 +080077 raise Exception('unable to lease %s' % host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080078
79
Kuang-che Wuca456462019-11-04 17:32:55 +080080def cmd_release_dut(opts):
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080081 host = cros_lab_util.dut_host_name(opts.dut)
Kuang-che Wu220cc162019-10-31 00:29:37 +080082 cros_lab_util.skylab_release_dut(host)
Kuang-che Wuca456462019-11-04 17:32:55 +080083 logger.info('%s released', host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080084
85
Kuang-che Wu1e56ce22020-06-29 11:21:51 +080086def verify_dimensions_by_lab(dimensions):
87 result = []
88 bots_dimensions = cros_lab_util.swarming_bots_dimensions()
89 for dimension in dimensions:
90 key, value = dimension.split(':', 1)
91 if value in bots_dimensions.get(key, []):
92 result.append(dimension)
93 else:
94 logger.warning('dimension=%s is unknown in the lab, typo? ignored',
95 dimension)
96 return result
97
98
Kuang-che Wueac89bd2020-10-23 16:07:15 +080099def select_available_bots_randomly(dimensions,
100 variants,
101 num=1,
102 is_busy=None,
103 filter_func=None):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800104 bots = []
105 for variant in variants:
106 # There might be thousand bots available, set 'limit' to reduce swarming
107 # API cost. This is not uniform random, but should be good enough.
108 bots += cros_lab_util.swarming_bots_list(
109 dimensions + [variant], is_busy=is_busy, limit=10)
Kuang-che Wu25723422020-09-24 22:20:26 +0800110
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800111 if filter_func:
112 bots = list(filter(filter_func, bots))
113 return random.sample(bots, min(num, len(bots)))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800114
115
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800116def filter_dimensions_by_board(boards_with_prebuilt, dimensions):
117 result = []
118 for dimension in dimensions:
119 bots = cros_lab_util.swarming_bots_list([dimension], is_busy=None, limit=1)
120 if not bots:
121 continue
122 board = bots[0]['dimensions']['label-board'][0]
123 if board not in boards_with_prebuilt:
124 logger.warning(
125 'dimension=%s (board=%s) does not have corresponding '
126 'prebuilt image, ignore', dimension, board)
127 continue
128 result.append(dimension)
129 return result
130
131
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800132def is_acceptable_bot(boards_with_prebuilt, bot):
133 model = bot['dimensions']['label-model'][0]
134 if model in models_to_avoid:
135 logger.warning('model=%s is bad (reason:%s), ignore', model,
136 models_to_avoid[model])
137 return False
138
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800139 if boards_with_prebuilt is not None:
140 # Sometimes swarming database has inconsistent records. For example,
141 # label-model=kefka + label-board=strago are incorrect (should be
142 # label-board=kefka). It is probably human errors (strago is kefka's
143 # reference board).
144 board = bot['dimensions']['label-board'][0]
145 if board not in boards_with_prebuilt:
146 logger.warning('%s has unexpected board=%s, ignore',
147 bot['dimensions']['dut_name'][0], board)
148 return False
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800149
150 return True
Kuang-che Wu04619772020-10-22 18:57:07 +0800151
152
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800153async def lease_dut_parallelly(duration, bots, reason, timeout=None):
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800154 tasks = []
155 hosts = []
156 for bot in bots:
157 host = bot['dimensions']['dut_name'][0]
158 hosts.append(host)
159 tasks.append(
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800160 asyncio.create_task(
161 cros_lab_util.async_lease(host, reason, duration=duration)))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800162
163 try:
164 logger.info('trying to lease %d DUTs: %s', len(hosts), hosts)
165 for coro in asyncio.as_completed(tasks, timeout=timeout):
166 host = await coro
167 if host:
168 logger.info('leased %s', host)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800169 # Unfinished lease tasks will be cancelled when asyncio.run is
170 # finishing.
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800171 return host
172 return None
173 except asyncio.TimeoutError:
174 return None
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800175
176
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800177def normalize_board_name(chromeos_root, board):
178 """Normalize BOARD name.
179
180 Here, we want to find the actual device board. Suffixes like -kernelnext will
181 be removed. So we can use that name to query DUTs inside the lab.
182
183 Args:
184 chromeos_root: chromeos source root
185 board: BOARD name
186
187 Returns:
188 normalized BOARD name
189 """
190 overlays = cros_util.parse_chromeos_overlays(chromeos_root)
191 boards_info = cros_util.resolve_basic_boards(overlays)
192 return boards_info[board]
193
194
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800195def do_allocate_dut(opts):
196 """Helper of cmd_allocate_dut.
197
198 Returns:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800199 (todo, host, board_to_build)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800200 todo: 'ready' or 'wait'
Kuang-che Wuca456462019-11-04 17:32:55 +0800201 host: leased host name
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800202 board_to_build: board name for building image
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800203 """
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800204 if not opts.dut_name and not opts.pool:
205 raise errors.ArgumentError('--pool',
206 'need to be specified if not --dut_name')
Kuang-che Wu7e8abe62020-07-02 09:42:27 +0800207 if opts.version_hint:
208 for v in opts.version_hint.split(','):
209 if cros_util.is_cros_version(v) or cros_util.is_cros_snapshot_version(v):
210 continue
211 raise errors.ArgumentError(
212 '--version_hint',
213 'should be Chrome OS version numbers, separated by comma')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800214 if opts.duration is not None and opts.duration < 60:
215 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800216
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800217 t0 = time.time()
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800218 dimensions = ['dut_state:ready']
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800219 if not opts.dut_name:
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800220 dimensions.append('label-pool:' + opts.pool)
221
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800222 variants = []
223 if opts.board:
224 for board in opts.board.split(','):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800225 variants.append('label-board:' +
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800226 normalize_board_name(opts.chromeos_root, board))
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800227 if opts.model:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800228 for model in opts.model.split(','):
Kuang-che Wu25723422020-09-24 22:20:26 +0800229 if model in models_to_avoid:
230 logger.warning('model=%s is bad (reason:%s), ignore', model,
231 models_to_avoid[model])
232 continue
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800233 variants.append('label-model:' + model)
Kuang-che Wu25723422020-09-24 22:20:26 +0800234 if not variants:
235 raise errors.ArgumentError('--model',
236 'all specified models are not supported')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800237 if opts.sku:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800238 for sku in opts.sku.split(','):
239 variants.append('label-hwid_sku:' + cros_lab_util.normalize_sku_name(sku))
240 if opts.dut_name:
241 for dut_name in opts.dut_name.split(','):
242 variants.append('dut_name:' + dut_name)
243
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800244 variants = verify_dimensions_by_lab(variants)
245 variants = sorted(set(variants)) # dedup
246 if not variants:
247 raise errors.NoDutAvailable(
248 'Invalid constraints: %s;%s;%s;%s' %
249 (opts.board, opts.model, opts.sku, opts.dut_name))
250
251 # Filter variants by prebuilt images.
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800252 boards_with_prebuilt = None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800253 if opts.version_hint:
254 if not opts.builder_hint:
255 opts.builder_hint = opts.board
256 if not opts.builder_hint:
257 raise errors.ArgumentError('--builder_hint',
258 'must be specified along with --version_hint')
259 boards_with_prebuilt = []
260 versions = opts.version_hint.split(',')
261 for builder in opts.builder_hint.split(','):
262 if not all(cros_util.has_test_image(builder, v) for v in versions):
263 logger.warning(
264 'builder=%s does not have prebuilt test image for %s, ignore',
265 builder, opts.version_hint)
266 continue
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800267 boards_with_prebuilt.append(
268 normalize_board_name(opts.chromeos_root, builder))
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800269 logger.info('boards with prebuilt: %s', boards_with_prebuilt)
270 if not boards_with_prebuilt:
271 raise errors.ArgumentError(
272 '--version_hint',
273 'given builders have no prebuilt for %s' % opts.version_hint)
274 variants = filter_dimensions_by_board(boards_with_prebuilt, variants)
275 if not variants:
276 raise errors.NoDutAvailable(
277 'Devices with specified constraints have no prebuilt. '
278 'Wrong version number?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800279
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800280 while True:
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800281 filter_func = lambda bot: is_acceptable_bot(boards_with_prebuilt, bot)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800282 # Query every time because each iteration takes a few minutes
283 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800284 dimensions,
285 variants,
286 num=opts.parallel,
287 is_busy=False,
288 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800289 if not bots:
290 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800291 dimensions,
292 variants,
293 num=opts.parallel,
294 is_busy=True,
295 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800296 if not bots:
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800297 raise errors.NoDutAvailable(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800298 'no bots satisfy constraints; all are in maintenance state?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800299
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800300 remaining_time = opts.time_limit - (time.time() - t0)
301 if remaining_time <= 0:
302 break
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800303 timeout = min(120, remaining_time)
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800304 reason = cros_lab_util.make_lease_reason(opts.session)
305 host = asyncio.run(
306 lease_dut_parallelly(opts.duration, bots, reason, timeout))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800307 if host:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800308 # Resolve what board we should build during bisection.
309 board_to_build = None
310 bots = cros_lab_util.swarming_bots_list(['dut_name:' + host])
311 host_board = bots[0]['dimensions']['label-board'][0]
312 if opts.builder_hint:
313 for builder in opts.builder_hint.split(','):
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800314 if normalize_board_name(opts.chromeos_root, builder) == host_board:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800315 board_to_build = builder
316 break
Kuang-che Wu04619772020-10-22 18:57:07 +0800317 else:
318 raise errors.DutLeaseException('DUT with unexpected board:%s' %
319 host_board)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800320 else:
321 board_to_build = host_board
322
323 return 'ready', host, board_to_build
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800324 time.sleep(1)
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800325
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800326 logger.warning('unable to lease DUT in time limit')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800327 return 'wait', None, None
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800328
329
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800330def cmd_allocate_dut(opts):
Kuang-che Wuca456462019-11-04 17:32:55 +0800331 leased_dut = None
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800332 try:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800333 todo, host, board = do_allocate_dut(opts)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800334 leased_dut = cros_lab_util.dut_name_to_address(host) if host else None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800335 result = {'result': todo, 'leased_dut': leased_dut, 'board': board}
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800336 print(json.dumps(result))
337 except Exception as e:
338 logger.exception('cmd_allocate_dut failed')
339 exception_name = e.__class__.__name__
340 result = {
341 'result': 'failed',
342 'exception': exception_name,
343 'text': str(e),
344 }
345 print(json.dumps(result))
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800346
347
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800348def cmd_repair_dut(opts):
349 cros_lab_util.repair(opts.dut)
350
351
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800352@cli.fatal_error_handler
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800353def main():
354 common.init()
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800355 parents = [common.common_argument_parser, common.session_optional_parser]
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800356 parser = argparse.ArgumentParser()
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800357 cli.patching_argparser_exit(parser)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800358 subparsers = parser.add_subparsers(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800359 dest='command', title='commands', metavar='<command>', required=True)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800360
361 parser_version_info = subparsers.add_parser(
362 'version_info',
363 help='Query version info of given chromeos build',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800364 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800365 description='Given chromeos `board` and `version`, '
366 'print version information of components.')
367 parser_version_info.add_argument(
368 'board', help='ChromeOS board name, like "samus".')
369 parser_version_info.add_argument(
370 'version',
371 type=cros_util.argtype_cros_version,
372 help='ChromeOS version, like "9876.0.0" or "R62-9876.0.0"')
373 parser_version_info.add_argument(
374 'name',
375 nargs='?',
376 help='Component name. If specified, output its version string. '
377 'Otherwise output all version info as dict in json format.')
378 parser_version_info.set_defaults(func=cmd_version_info)
379
380 parser_query_dut_board = subparsers.add_parser(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800381 'query_dut_board', help='Query board name of given DUT', parents=parents)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800382 parser_query_dut_board.add_argument('dut')
383 parser_query_dut_board.set_defaults(func=cmd_query_dut_board)
384
385 parser_reboot = subparsers.add_parser(
386 'reboot',
387 help='Reboot a DUT',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800388 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800389 description='Reboot a DUT and verify the reboot is successful.')
Kuang-che Wu2534bab2020-10-23 17:37:16 +0800390 parser_reboot.add_argument('--force', action='store_true')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800391 parser_reboot.add_argument('dut')
392 parser_reboot.set_defaults(func=cmd_reboot)
393
Kuang-che Wuca456462019-11-04 17:32:55 +0800394 parser_lease_dut = subparsers.add_parser(
395 'lease_dut',
396 help='Lease a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800397 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800398 description='Lease a DUT in the lab. '
399 'This is implemented by `skylab lease-dut` with additional checking.')
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800400 group = parser_lease_dut.add_mutually_exclusive_group(required=True)
401 group.add_argument('--session', help='session name')
402 group.add_argument('--reason', help='specify lease reason manually')
Kuang-che Wuca456462019-11-04 17:32:55 +0800403 parser_lease_dut.add_argument('dut')
404 parser_lease_dut.add_argument(
405 '--duration',
406 type=float,
407 help='duration in seconds; will be round to minutes')
408 parser_lease_dut.set_defaults(func=cmd_lease_dut)
409
410 parser_release_dut = subparsers.add_parser(
411 'release_dut',
412 help='Release a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800413 parents=parents,
Kuang-che Wuca456462019-11-04 17:32:55 +0800414 description='Release a DUT in the lab. '
415 'This is implemented by `skylab release-dut` with additional checking.')
Kuang-che Wuca456462019-11-04 17:32:55 +0800416 parser_release_dut.add_argument('dut')
417 parser_release_dut.set_defaults(func=cmd_release_dut)
418
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800419 parser_allocate_dut = subparsers.add_parser(
420 'allocate_dut',
421 help='Allocate a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800422 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800423 description='Allocate a DUT in the lab. It will lease a DUT in the lab '
424 'for bisecting. The caller (bisect-kit runner) of this command should '
425 'retry this command again later if no DUT available now.')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800426 parser_allocate_dut.add_argument(
427 '--session', required=True, help='session name')
428 parser_allocate_dut.add_argument(
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800429 '--pool',
430 help='Pool to search DUT (default: %(default)s)',
431 default=DEFAULT_DUT_POOL)
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800432 group = parser_allocate_dut.add_mutually_exclusive_group(required=True)
433 group.add_argument('--board', help='allocation criteria; comma separated')
434 group.add_argument('--model', help='allocation criteria; comma separated')
435 group.add_argument('--sku', help='allocation criteria; comma separated')
436 group.add_argument('--dut_name', help='allocation criteria; comma separated')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800437 parser_allocate_dut.add_argument(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800438 '--version_hint', help='chromeos version; comma separated')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800439 parser_allocate_dut.add_argument(
440 '--builder_hint', help='chromeos builder; comma separated')
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800441 # Pubsub ack deadline is 10 minutes (b/143663659). Default 9 minutes with 1
442 # minute buffer.
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800443 parser_allocate_dut.add_argument(
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800444 '--time_limit',
445 type=int,
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800446 default=9 * 60,
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800447 help='Time limit to attempt lease in seconds (default: %(default)s)')
448 parser_allocate_dut.add_argument(
449 '--duration',
450 type=float,
451 help='lease duration in seconds; will be round to minutes')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800452 parser_allocate_dut.add_argument(
453 '--parallel',
454 type=int,
455 default=1,
456 help='Submit multiple lease tasks to speed up (default: %(default)d)')
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800457 parser_allocate_dut.add_argument(
458 '--chromeos_root',
459 type=cli.argtype_dir_path,
460 default=configure.get('DEFAULT_CHROMEOS_ROOT',
461 os.path.expanduser('~/chromiumos')),
462 help='Chrome OS source tree, for overlay data (default: %(default)s)')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800463 parser_allocate_dut.set_defaults(func=cmd_allocate_dut)
464
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800465 parser_repair_dut = subparsers.add_parser(
466 'repair_dut',
467 help='Repair a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800468 parents=parents,
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800469 description='Repair a DUT in the lab. '
470 'This is simply wrapper of "deploy repair" with additional checking.')
471 parser_repair_dut.add_argument('dut')
472 parser_repair_dut.set_defaults(func=cmd_repair_dut)
473
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800474 opts = parser.parse_args()
475 common.config_logging(opts)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800476 opts.func(opts)
477
478
479if __name__ == '__main__':
480 main()