blob: 76aeb394ede227ed46289fede5bf150abdcf6154 [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 Wu8480a8a2021-04-21 15:44:59 +0800116def filter_dimensions_by_board(boards_with_prebuilt, dimensions, pool):
117 result = set()
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800118 for dimension in dimensions:
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800119 constraints = [dimension]
120 if pool:
121 constraints.append('label-pool:' + pool)
122 bots = cros_lab_util.swarming_bots_list(constraints, is_busy=None, limit=1)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800123 if not bots:
124 continue
125 board = bots[0]['dimensions']['label-board'][0]
126 if board not in boards_with_prebuilt:
127 logger.warning(
128 'dimension=%s (board=%s) does not have corresponding '
129 'prebuilt image, ignore', dimension, board)
130 continue
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800131 result.add(dimension)
132 return list(result)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800133
134
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800135def is_acceptable_bot(boards_with_prebuilt, bot):
136 model = bot['dimensions']['label-model'][0]
137 if model in models_to_avoid:
138 logger.warning('model=%s is bad (reason:%s), ignore', model,
139 models_to_avoid[model])
140 return False
141
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800142 if boards_with_prebuilt is not None:
143 # Sometimes swarming database has inconsistent records. For example,
144 # label-model=kefka + label-board=strago are incorrect (should be
145 # label-board=kefka). It is probably human errors (strago is kefka's
146 # reference board).
147 board = bot['dimensions']['label-board'][0]
148 if board not in boards_with_prebuilt:
149 logger.warning('%s has unexpected board=%s, ignore',
150 bot['dimensions']['dut_name'][0], board)
151 return False
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800152
153 return True
Kuang-che Wu04619772020-10-22 18:57:07 +0800154
155
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800156async def lease_dut_parallelly(duration, bots, reason, timeout=None):
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800157 tasks = []
158 hosts = []
159 for bot in bots:
160 host = bot['dimensions']['dut_name'][0]
161 hosts.append(host)
162 tasks.append(
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800163 asyncio.create_task(
164 cros_lab_util.async_lease(host, reason, duration=duration)))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800165
166 try:
167 logger.info('trying to lease %d DUTs: %s', len(hosts), hosts)
168 for coro in asyncio.as_completed(tasks, timeout=timeout):
169 host = await coro
170 if host:
171 logger.info('leased %s', host)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800172 # Unfinished lease tasks will be cancelled when asyncio.run is
173 # finishing.
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800174 return host
175 return None
176 except asyncio.TimeoutError:
177 return None
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800178
179
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800180def normalize_board_name(chromeos_root, board):
181 """Normalize BOARD name.
182
183 Here, we want to find the actual device board. Suffixes like -kernelnext will
184 be removed. So we can use that name to query DUTs inside the lab.
185
186 Args:
187 chromeos_root: chromeos source root
188 board: BOARD name
189
190 Returns:
191 normalized BOARD name
192 """
193 overlays = cros_util.parse_chromeos_overlays(chromeos_root)
194 boards_info = cros_util.resolve_basic_boards(overlays)
195 return boards_info[board]
196
197
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800198def do_allocate_dut(opts):
199 """Helper of cmd_allocate_dut.
200
201 Returns:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800202 (todo, host, board_to_build)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800203 todo: 'ready' or 'wait'
Kuang-che Wuca456462019-11-04 17:32:55 +0800204 host: leased host name
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800205 board_to_build: board name for building image
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800206 """
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800207 if not opts.dut_name and not opts.pool:
208 raise errors.ArgumentError('--pool',
209 'need to be specified if not --dut_name')
Kuang-che Wu7e8abe62020-07-02 09:42:27 +0800210 if opts.version_hint:
211 for v in opts.version_hint.split(','):
212 if cros_util.is_cros_version(v) or cros_util.is_cros_snapshot_version(v):
213 continue
214 raise errors.ArgumentError(
215 '--version_hint',
216 'should be Chrome OS version numbers, separated by comma')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800217 if opts.duration is not None and opts.duration < 60:
218 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800219
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800220 t0 = time.time()
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800221 dimensions = ['dut_state:ready']
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800222 if opts.dut_name:
223 # If dut_name is specified, pool is ignored.
224 opts.pool = None
225 else:
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800226 dimensions.append('label-pool:' + opts.pool)
227
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800228 variants = []
229 if opts.board:
230 for board in opts.board.split(','):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800231 variants.append('label-board:' +
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800232 normalize_board_name(opts.chromeos_root, board))
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800233 if opts.model:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800234 for model in opts.model.split(','):
Kuang-che Wu25723422020-09-24 22:20:26 +0800235 if model in models_to_avoid:
236 logger.warning('model=%s is bad (reason:%s), ignore', model,
237 models_to_avoid[model])
238 continue
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800239 variants.append('label-model:' + model)
Kuang-che Wu25723422020-09-24 22:20:26 +0800240 if not variants:
241 raise errors.ArgumentError('--model',
242 'all specified models are not supported')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800243 if opts.sku:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800244 for sku in opts.sku.split(','):
245 variants.append('label-hwid_sku:' + cros_lab_util.normalize_sku_name(sku))
246 if opts.dut_name:
247 for dut_name in opts.dut_name.split(','):
248 variants.append('dut_name:' + dut_name)
249
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800250 variants = verify_dimensions_by_lab(variants)
251 variants = sorted(set(variants)) # dedup
252 if not variants:
253 raise errors.NoDutAvailable(
254 'Invalid constraints: %s;%s;%s;%s' %
255 (opts.board, opts.model, opts.sku, opts.dut_name))
256
257 # Filter variants by prebuilt images.
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800258 boards_with_prebuilt = None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800259 if opts.version_hint:
260 if not opts.builder_hint:
261 opts.builder_hint = opts.board
262 if not opts.builder_hint:
263 raise errors.ArgumentError('--builder_hint',
264 'must be specified along with --version_hint')
265 boards_with_prebuilt = []
266 versions = opts.version_hint.split(',')
267 for builder in opts.builder_hint.split(','):
268 if not all(cros_util.has_test_image(builder, v) for v in versions):
269 logger.warning(
270 'builder=%s does not have prebuilt test image for %s, ignore',
271 builder, opts.version_hint)
272 continue
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800273 boards_with_prebuilt.append(
274 normalize_board_name(opts.chromeos_root, builder))
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800275 logger.info('boards with prebuilt: %s', boards_with_prebuilt)
276 if not boards_with_prebuilt:
277 raise errors.ArgumentError(
278 '--version_hint',
279 'given builders have no prebuilt for %s' % opts.version_hint)
Kuang-che Wu8480a8a2021-04-21 15:44:59 +0800280 variants = filter_dimensions_by_board(boards_with_prebuilt, variants,
281 opts.pool)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800282 if not variants:
283 raise errors.NoDutAvailable(
284 'Devices with specified constraints have no prebuilt. '
285 'Wrong version number?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800286
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800287 while True:
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800288 filter_func = lambda bot: is_acceptable_bot(boards_with_prebuilt, bot)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800289 # Query every time because each iteration takes a few minutes
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=False,
295 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800296 if not bots:
297 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800298 dimensions,
299 variants,
300 num=opts.parallel,
301 is_busy=True,
302 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800303 if not bots:
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800304 raise errors.NoDutAvailable(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800305 'no bots satisfy constraints; all are in maintenance state?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800306
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800307 remaining_time = opts.time_limit - (time.time() - t0)
308 if remaining_time <= 0:
309 break
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800310 timeout = min(120, remaining_time)
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800311 reason = cros_lab_util.make_lease_reason(opts.session)
312 host = asyncio.run(
313 lease_dut_parallelly(opts.duration, bots, reason, timeout))
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800314 if host:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800315 # Resolve what board we should build during bisection.
316 board_to_build = None
317 bots = cros_lab_util.swarming_bots_list(['dut_name:' + host])
318 host_board = bots[0]['dimensions']['label-board'][0]
319 if opts.builder_hint:
320 for builder in opts.builder_hint.split(','):
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800321 if normalize_board_name(opts.chromeos_root, builder) == host_board:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800322 board_to_build = builder
323 break
Kuang-che Wu04619772020-10-22 18:57:07 +0800324 else:
325 raise errors.DutLeaseException('DUT with unexpected board:%s' %
326 host_board)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800327 else:
328 board_to_build = host_board
329
330 return 'ready', host, board_to_build
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800331 time.sleep(1)
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800332
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800333 logger.warning('unable to lease DUT in time limit')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800334 return 'wait', None, None
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800335
336
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800337def cmd_allocate_dut(opts):
Kuang-che Wuca456462019-11-04 17:32:55 +0800338 leased_dut = None
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800339 try:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800340 todo, host, board = do_allocate_dut(opts)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800341 leased_dut = cros_lab_util.dut_name_to_address(host) if host else None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800342 result = {'result': todo, 'leased_dut': leased_dut, 'board': board}
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800343 print(json.dumps(result))
344 except Exception as e:
345 logger.exception('cmd_allocate_dut failed')
346 exception_name = e.__class__.__name__
347 result = {
348 'result': 'failed',
349 'exception': exception_name,
350 'text': str(e),
351 }
352 print(json.dumps(result))
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800353
354
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800355def cmd_repair_dut(opts):
356 cros_lab_util.repair(opts.dut)
357
358
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800359@cli.fatal_error_handler
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800360def main():
361 common.init()
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800362 parents = [common.common_argument_parser, common.session_optional_parser]
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800363 parser = argparse.ArgumentParser()
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800364 cli.patching_argparser_exit(parser)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800365 subparsers = parser.add_subparsers(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800366 dest='command', title='commands', metavar='<command>', required=True)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800367
368 parser_version_info = subparsers.add_parser(
369 'version_info',
370 help='Query version info of given chromeos build',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800371 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800372 description='Given chromeos `board` and `version`, '
373 'print version information of components.')
374 parser_version_info.add_argument(
375 'board', help='ChromeOS board name, like "samus".')
376 parser_version_info.add_argument(
377 'version',
378 type=cros_util.argtype_cros_version,
379 help='ChromeOS version, like "9876.0.0" or "R62-9876.0.0"')
380 parser_version_info.add_argument(
381 'name',
382 nargs='?',
383 help='Component name. If specified, output its version string. '
384 'Otherwise output all version info as dict in json format.')
385 parser_version_info.set_defaults(func=cmd_version_info)
386
387 parser_query_dut_board = subparsers.add_parser(
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800388 'query_dut_board', help='Query board name of given DUT', parents=parents)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800389 parser_query_dut_board.add_argument('dut')
390 parser_query_dut_board.set_defaults(func=cmd_query_dut_board)
391
392 parser_reboot = subparsers.add_parser(
393 'reboot',
394 help='Reboot a DUT',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800395 parents=parents,
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800396 description='Reboot a DUT and verify the reboot is successful.')
Kuang-che Wu2534bab2020-10-23 17:37:16 +0800397 parser_reboot.add_argument('--force', action='store_true')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800398 parser_reboot.add_argument('dut')
399 parser_reboot.set_defaults(func=cmd_reboot)
400
Kuang-che Wuca456462019-11-04 17:32:55 +0800401 parser_lease_dut = subparsers.add_parser(
402 'lease_dut',
403 help='Lease a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800404 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800405 description='Lease a DUT in the lab. '
406 'This is implemented by `skylab lease-dut` with additional checking.')
Kuang-che Wu7c1fa582021-01-14 17:57:49 +0800407 group = parser_lease_dut.add_mutually_exclusive_group(required=True)
408 group.add_argument('--session', help='session name')
409 group.add_argument('--reason', help='specify lease reason manually')
Kuang-che Wuca456462019-11-04 17:32:55 +0800410 parser_lease_dut.add_argument('dut')
411 parser_lease_dut.add_argument(
412 '--duration',
413 type=float,
414 help='duration in seconds; will be round to minutes')
415 parser_lease_dut.set_defaults(func=cmd_lease_dut)
416
417 parser_release_dut = subparsers.add_parser(
418 'release_dut',
419 help='Release a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800420 parents=parents,
Kuang-che Wuca456462019-11-04 17:32:55 +0800421 description='Release a DUT in the lab. '
422 'This is implemented by `skylab release-dut` with additional checking.')
Kuang-che Wuca456462019-11-04 17:32:55 +0800423 parser_release_dut.add_argument('dut')
424 parser_release_dut.set_defaults(func=cmd_release_dut)
425
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800426 parser_allocate_dut = subparsers.add_parser(
427 'allocate_dut',
428 help='Allocate a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800429 parents=[common.common_argument_parser],
Kuang-che Wuca456462019-11-04 17:32:55 +0800430 description='Allocate a DUT in the lab. It will lease a DUT in the lab '
431 'for bisecting. The caller (bisect-kit runner) of this command should '
432 'retry this command again later if no DUT available now.')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800433 parser_allocate_dut.add_argument(
434 '--session', required=True, help='session name')
435 parser_allocate_dut.add_argument(
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800436 '--pool',
437 help='Pool to search DUT (default: %(default)s)',
438 default=DEFAULT_DUT_POOL)
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800439 group = parser_allocate_dut.add_mutually_exclusive_group(required=True)
440 group.add_argument('--board', help='allocation criteria; comma separated')
441 group.add_argument('--model', help='allocation criteria; comma separated')
442 group.add_argument('--sku', help='allocation criteria; comma separated')
443 group.add_argument('--dut_name', help='allocation criteria; comma separated')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800444 parser_allocate_dut.add_argument(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800445 '--version_hint', help='chromeos version; comma separated')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800446 parser_allocate_dut.add_argument(
447 '--builder_hint', help='chromeos builder; comma separated')
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800448 # Pubsub ack deadline is 10 minutes (b/143663659). Default 9 minutes with 1
449 # minute buffer.
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800450 parser_allocate_dut.add_argument(
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800451 '--time_limit',
452 type=int,
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800453 default=9 * 60,
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800454 help='Time limit to attempt lease in seconds (default: %(default)s)')
455 parser_allocate_dut.add_argument(
456 '--duration',
457 type=float,
458 help='lease duration in seconds; will be round to minutes')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800459 parser_allocate_dut.add_argument(
460 '--parallel',
461 type=int,
462 default=1,
463 help='Submit multiple lease tasks to speed up (default: %(default)d)')
Kuang-che Wu9d14c162020-11-03 19:35:18 +0800464 parser_allocate_dut.add_argument(
465 '--chromeos_root',
466 type=cli.argtype_dir_path,
467 default=configure.get('DEFAULT_CHROMEOS_ROOT',
468 os.path.expanduser('~/chromiumos')),
469 help='Chrome OS source tree, for overlay data (default: %(default)s)')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800470 parser_allocate_dut.set_defaults(func=cmd_allocate_dut)
471
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800472 parser_repair_dut = subparsers.add_parser(
473 'repair_dut',
474 help='Repair a DUT in the lab',
Kuang-che Wud2d6e412021-01-28 16:26:41 +0800475 parents=parents,
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800476 description='Repair a DUT in the lab. '
477 'This is simply wrapper of "deploy repair" with additional checking.')
478 parser_repair_dut.add_argument('dut')
479 parser_repair_dut.set_defaults(func=cmd_repair_dut)
480
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800481 opts = parser.parse_args()
482 common.config_logging(opts)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800483 opts.func(opts)
484
485
486if __name__ == '__main__':
487 main()