blob: 5cee155328111ef076c70fc2d7afff9eb1c68fdb [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
Kuang-che Wu25723422020-09-24 22:20:26 +080028}
29
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080030
31def cmd_version_info(opts):
32 info = cros_util.version_info(opts.board, opts.version)
33 if opts.name:
34 if opts.name not in info:
35 logger.error('unknown name=%s', opts.name)
36 print(info[opts.name])
37 else:
38 print(json.dumps(info, sort_keys=True, indent=4))
39
40
41def cmd_query_dut_board(opts):
42 assert cros_util.is_dut(opts.dut)
43 print(cros_util.query_dut_board(opts.dut))
44
45
46def cmd_reboot(opts):
Kuang-che Wu2534bab2020-10-23 17:37:16 +080047 if not cros_util.is_dut(opts.dut):
48 if opts.force:
49 logger.warning('%s is not a Chrome OS device?', opts.dut)
50 else:
51 raise errors.ArgumentError(
52 'dut', 'not a Chrome OS device (--force to continue)')
53
Kuang-che Wu2ac9a922020-09-03 16:50:12 +080054 cros_util.reboot(
55 opts.dut, force_reboot_callback=cros_lab_util.reboot_via_servo)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080056
57
Kuang-che Wuc45cfa42019-01-15 00:15:01 +080058def _get_label_by_prefix(info, prefix):
59 for label in info['Labels']:
60 if label.startswith(prefix + ':'):
61 return label
62 return None
63
64
Kuang-che Wuca456462019-11-04 17:32:55 +080065def cmd_lease_dut(opts):
Kuang-che Wu5157dee2020-07-18 01:13:41 +080066 if opts.duration is not None and opts.duration < 60:
67 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
Kuang-che Wu7c1fa582021-01-14 17:57:49 +080068 reason = opts.reason or cros_lab_util.make_lease_reason(opts.session)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080069 host = cros_lab_util.dut_host_name(opts.dut)
Kuang-che Wu220cc162019-10-31 00:29:37 +080070 logger.info('trying to lease %s', host)
Kuang-che Wu7c1fa582021-01-14 17:57:49 +080071 if cros_lab_util.skylab_lease_dut(host, reason, opts.duration):
Kuang-che Wuca456462019-11-04 17:32:55 +080072 logger.info('leased %s', host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080073 else:
Kuang-che Wuca456462019-11-04 17:32:55 +080074 raise Exception('unable to lease %s' % host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080075
76
Kuang-che Wuca456462019-11-04 17:32:55 +080077def cmd_release_dut(opts):
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080078 host = cros_lab_util.dut_host_name(opts.dut)
Kuang-che Wu220cc162019-10-31 00:29:37 +080079 cros_lab_util.skylab_release_dut(host)
Kuang-che Wuca456462019-11-04 17:32:55 +080080 logger.info('%s released', host)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080081
82
Kuang-che Wu1e56ce22020-06-29 11:21:51 +080083def verify_dimensions_by_lab(dimensions):
84 result = []
85 bots_dimensions = cros_lab_util.swarming_bots_dimensions()
86 for dimension in dimensions:
87 key, value = dimension.split(':', 1)
88 if value in bots_dimensions.get(key, []):
89 result.append(dimension)
90 else:
91 logger.warning('dimension=%s is unknown in the lab, typo? ignored',
92 dimension)
93 return result
94
95
Kuang-che Wueac89bd2020-10-23 16:07:15 +080096def select_available_bots_randomly(dimensions,
97 variants,
98 num=1,
99 is_busy=None,
100 filter_func=None):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800101 bots = []
102 for variant in variants:
103 # There might be thousand bots available, set 'limit' to reduce swarming
104 # API cost. This is not uniform random, but should be good enough.
105 bots += cros_lab_util.swarming_bots_list(
106 dimensions + [variant], is_busy=is_busy, limit=10)
Kuang-che Wu25723422020-09-24 22:20:26 +0800107
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800108 if filter_func:
109 bots = list(filter(filter_func, bots))
110 return random.sample(bots, min(num, len(bots)))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800111
112
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800113def filter_dimensions_by_board(boards_with_prebuilt, dimensions, pool):
114 result = set()
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800115 for dimension in dimensions:
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800116 constraints = [dimension]
117 if pool:
118 constraints.append('label-pool:' + pool)
119 bots = cros_lab_util.swarming_bots_list(constraints, is_busy=None, limit=1)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800120 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
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800128 result.add(dimension)
129 return list(result)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800130
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 Wu8480a8a2021-04-21 15:44:59 +0800219 if opts.dut_name:
220 # If dut_name is specified, pool is ignored.
221 opts.pool = None
222 else:
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800223 dimensions.append('label-pool:' + opts.pool)
224
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800225 variants = []
226 if opts.board:
227 for board in opts.board.split(','):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800228 variants.append('label-board:' +
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800229 normalize_board_name(opts.chromeos_root, board))
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800230 if opts.model:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800231 for model in opts.model.split(','):
Kuang-che Wu25723422020-09-24 22:20:26 +0800232 if model in models_to_avoid:
233 logger.warning('model=%s is bad (reason:%s), ignore', model,
234 models_to_avoid[model])
235 continue
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800236 variants.append('label-model:' + model)
Kuang-che Wu25723422020-09-24 22:20:26 +0800237 if not variants:
238 raise errors.ArgumentError('--model',
239 'all specified models are not supported')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800240 if opts.sku:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800241 for sku in opts.sku.split(','):
242 variants.append('label-hwid_sku:' + cros_lab_util.normalize_sku_name(sku))
243 if opts.dut_name:
244 for dut_name in opts.dut_name.split(','):
245 variants.append('dut_name:' + dut_name)
246
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800247 variants = verify_dimensions_by_lab(variants)
248 variants = sorted(set(variants)) # dedup
249 if not variants:
250 raise errors.NoDutAvailable(
251 'Invalid constraints: %s;%s;%s;%s' %
252 (opts.board, opts.model, opts.sku, opts.dut_name))
253
254 # Filter variants by prebuilt images.
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800255 boards_with_prebuilt = None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800256 if opts.version_hint:
257 if not opts.builder_hint:
258 opts.builder_hint = opts.board
259 if not opts.builder_hint:
260 raise errors.ArgumentError('--builder_hint',
261 'must be specified along with --version_hint')
262 boards_with_prebuilt = []
263 versions = opts.version_hint.split(',')
264 for builder in opts.builder_hint.split(','):
265 if not all(cros_util.has_test_image(builder, v) for v in versions):
266 logger.warning(
267 'builder=%s does not have prebuilt test image for %s, ignore',
268 builder, opts.version_hint)
269 continue
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800270 boards_with_prebuilt.append(
271 normalize_board_name(opts.chromeos_root, builder))
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800272 logger.info('boards with prebuilt: %s', boards_with_prebuilt)
273 if not boards_with_prebuilt:
274 raise errors.ArgumentError(
275 '--version_hint',
276 'given builders have no prebuilt for %s' % opts.version_hint)
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800277 variants = filter_dimensions_by_board(boards_with_prebuilt, variants,
278 opts.pool)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800279 if not variants:
280 raise errors.NoDutAvailable(
281 'Devices with specified constraints have no prebuilt. '
282 'Wrong version number?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800283
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800284 while True:
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800285 filter_func = lambda bot: is_acceptable_bot(boards_with_prebuilt, bot)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800286 # Query every time because each iteration takes a few minutes
287 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800288 dimensions,
289 variants,
290 num=opts.parallel,
291 is_busy=False,
292 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800293 if not bots:
294 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800295 dimensions,
296 variants,
297 num=opts.parallel,
298 is_busy=True,
299 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800300 if not bots:
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800301 raise errors.NoDutAvailable(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800302 'no bots satisfy constraints; all are in maintenance state?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800303
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800304 remaining_time = opts.time_limit - (time.time() - t0)
305 if remaining_time <= 0:
306 break
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800307 timeout = min(120, remaining_time)
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800308 reason = cros_lab_util.make_lease_reason(opts.session)
309 host = asyncio.run(
310 lease_dut_parallelly(opts.duration, bots, reason, timeout))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800311 if host:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800312 # Resolve what board we should build during bisection.
313 board_to_build = None
314 bots = cros_lab_util.swarming_bots_list(['dut_name:' + host])
315 host_board = bots[0]['dimensions']['label-board'][0]
316 if opts.builder_hint:
317 for builder in opts.builder_hint.split(','):
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800318 if normalize_board_name(opts.chromeos_root, builder) == host_board:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800319 board_to_build = builder
320 break
Kuang-che Wu04619772020-10-22 18:57:07 +0800321 else:
322 raise errors.DutLeaseException('DUT with unexpected board:%s' %
323 host_board)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800324 else:
325 board_to_build = host_board
326
327 return 'ready', host, board_to_build
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800328 time.sleep(1)
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800329
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800330 logger.warning('unable to lease DUT in time limit')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800331 return 'wait', None, None
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800332
333
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800334def cmd_allocate_dut(opts):
Kuang-che Wuca456462019-11-04 17:32:55 +0800335 leased_dut = None
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800336 try:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800337 todo, host, board = do_allocate_dut(opts)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800338 leased_dut = cros_lab_util.dut_name_to_address(host) if host else None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800339 result = {'result': todo, 'leased_dut': leased_dut, 'board': board}
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800340 print(json.dumps(result))
341 except Exception as e:
342 logger.exception('cmd_allocate_dut failed')
343 exception_name = e.__class__.__name__
344 result = {
345 'result': 'failed',
346 'exception': exception_name,
347 'text': str(e),
348 }
349 print(json.dumps(result))
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800350
351
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800352def cmd_repair_dut(opts):
353 cros_lab_util.repair(opts.dut)
354
355
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800356@cli.fatal_error_handler
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800357def main():
358 common.init()
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800359 parents = [common.common_argument_parser, common.session_optional_parser]
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800360 parser = argparse.ArgumentParser()
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800361 cli.patching_argparser_exit(parser)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800362 subparsers = parser.add_subparsers(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800363 dest='command', title='commands', metavar='<command>', required=True)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800364
365 parser_version_info = subparsers.add_parser(
366 'version_info',
367 help='Query version info of given chromeos build',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800368 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800369 description='Given chromeos `board` and `version`, '
370 'print version information of components.')
371 parser_version_info.add_argument(
372 'board', help='ChromeOS board name, like "samus".')
373 parser_version_info.add_argument(
374 'version',
375 type=cros_util.argtype_cros_version,
376 help='ChromeOS version, like "9876.0.0" or "R62-9876.0.0"')
377 parser_version_info.add_argument(
378 'name',
379 nargs='?',
380 help='Component name. If specified, output its version string. '
381 'Otherwise output all version info as dict in json format.')
382 parser_version_info.set_defaults(func=cmd_version_info)
383
384 parser_query_dut_board = subparsers.add_parser(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800385 'query_dut_board', help='Query board name of given DUT', parents=parents)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800386 parser_query_dut_board.add_argument('dut')
387 parser_query_dut_board.set_defaults(func=cmd_query_dut_board)
388
389 parser_reboot = subparsers.add_parser(
390 'reboot',
391 help='Reboot a DUT',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800392 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800393 description='Reboot a DUT and verify the reboot is successful.')
Kuang-che Wu2534bab2020-10-23 17:37:16 +0800394 parser_reboot.add_argument('--force', action='store_true')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800395 parser_reboot.add_argument('dut')
396 parser_reboot.set_defaults(func=cmd_reboot)
397
Kuang-che Wuca456462019-11-04 17:32:55 +0800398 parser_lease_dut = subparsers.add_parser(
399 'lease_dut',
400 help='Lease a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800401 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800402 description='Lease a DUT in the lab. '
403 'This is implemented by `skylab lease-dut` with additional checking.')
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800404 group = parser_lease_dut.add_mutually_exclusive_group(required=True)
405 group.add_argument('--session', help='session name')
406 group.add_argument('--reason', help='specify lease reason manually')
Kuang-che Wuca456462019-11-04 17:32:55 +0800407 parser_lease_dut.add_argument('dut')
408 parser_lease_dut.add_argument(
409 '--duration',
410 type=float,
411 help='duration in seconds; will be round to minutes')
412 parser_lease_dut.set_defaults(func=cmd_lease_dut)
413
414 parser_release_dut = subparsers.add_parser(
415 'release_dut',
416 help='Release a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800417 parents=parents,
Kuang-che Wuca456462019-11-04 17:32:55 +0800418 description='Release a DUT in the lab. '
419 'This is implemented by `skylab release-dut` with additional checking.')
Kuang-che Wuca456462019-11-04 17:32:55 +0800420 parser_release_dut.add_argument('dut')
421 parser_release_dut.set_defaults(func=cmd_release_dut)
422
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800423 parser_allocate_dut = subparsers.add_parser(
424 'allocate_dut',
425 help='Allocate a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800426 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800427 description='Allocate a DUT in the lab. It will lease a DUT in the lab '
428 'for bisecting. The caller (bisect-kit runner) of this command should '
429 'retry this command again later if no DUT available now.')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800430 parser_allocate_dut.add_argument(
431 '--session', required=True, help='session name')
432 parser_allocate_dut.add_argument(
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800433 '--pool',
434 help='Pool to search DUT (default: %(default)s)',
435 default=DEFAULT_DUT_POOL)
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800436 group = parser_allocate_dut.add_mutually_exclusive_group(required=True)
437 group.add_argument('--board', help='allocation criteria; comma separated')
438 group.add_argument('--model', help='allocation criteria; comma separated')
439 group.add_argument('--sku', help='allocation criteria; comma separated')
440 group.add_argument('--dut_name', help='allocation criteria; comma separated')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800441 parser_allocate_dut.add_argument(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800442 '--version_hint', help='chromeos version; comma separated')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800443 parser_allocate_dut.add_argument(
444 '--builder_hint', help='chromeos builder; comma separated')
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800445 # Pubsub ack deadline is 10 minutes (b/143663659). Default 9 minutes with 1
446 # minute buffer.
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800447 parser_allocate_dut.add_argument(
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800448 '--time_limit',
449 type=int,
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800450 default=9 * 60,
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800451 help='Time limit to attempt lease in seconds (default: %(default)s)')
452 parser_allocate_dut.add_argument(
453 '--duration',
454 type=float,
455 help='lease duration in seconds; will be round to minutes')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800456 parser_allocate_dut.add_argument(
457 '--parallel',
458 type=int,
459 default=1,
460 help='Submit multiple lease tasks to speed up (default: %(default)d)')
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800461 parser_allocate_dut.add_argument(
462 '--chromeos_root',
463 type=cli.argtype_dir_path,
464 default=configure.get('DEFAULT_CHROMEOS_ROOT',
465 os.path.expanduser('~/chromiumos')),
466 help='Chrome OS source tree, for overlay data (default: %(default)s)')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800467 parser_allocate_dut.set_defaults(func=cmd_allocate_dut)
468
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800469 parser_repair_dut = subparsers.add_parser(
470 'repair_dut',
471 help='Repair a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800472 parents=parents,
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800473 description='Repair a DUT in the lab. '
474 'This is simply wrapper of "deploy repair" with additional checking.')
475 parser_repair_dut.add_argument('dut')
476 parser_repair_dut.set_defaults(func=cmd_repair_dut)
477
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800478 opts = parser.parse_args()
479 common.config_logging(opts)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800480 opts.func(opts)
481
482
483if __name__ == '__main__':
484 main()