blob: 1d705c8f3831c7749e4d7327b6e63ed1e4961284 [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
Kuang-che Wu5157dee2020-07-18 01:13:41 +08008import asyncio
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08009import argparse
10import json
11import logging
Kuang-che Wu0c9b7942019-10-30 16:55:39 +080012import random
13import time
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080014
Kuang-che Wufe1e88a2019-09-10 21:52:25 +080015from bisect_kit import cli
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080016from bisect_kit import common
Kuang-che Wuc45cfa42019-01-15 00:15:01 +080017from bisect_kit import cros_lab_util
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080018from bisect_kit import cros_util
Kuang-che Wu22aa9d42019-01-25 10:35:33 +080019from bisect_kit import errors
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080020
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +080021DEFAULT_DUT_POOL = 'DUT_POOL_QUOTA'
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080022logger = logging.getLogger(__name__)
23
Kuang-che Wu25723422020-09-24 22:20:26 +080024models_to_avoid = {
25 # model: reason
26 'kasumi': 'b/160458394 stateful partition is too small',
27 'mimrock': 'b/160458394 stateful partition is too small',
28 'vorticon': 'b/160458394 stateful partition is too small',
29}
30
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080031
32def cmd_version_info(opts):
33 info = cros_util.version_info(opts.board, opts.version)
34 if opts.name:
35 if opts.name not in info:
36 logger.error('unknown name=%s', opts.name)
37 print(info[opts.name])
38 else:
39 print(json.dumps(info, sort_keys=True, indent=4))
40
41
42def cmd_query_dut_board(opts):
43 assert cros_util.is_dut(opts.dut)
44 print(cros_util.query_dut_board(opts.dut))
45
46
47def cmd_reboot(opts):
Kuang-che Wu2534bab2020-10-23 17:37:16 +080048 if not cros_util.is_dut(opts.dut):
49 if opts.force:
50 logger.warning('%s is not a Chrome OS device?', opts.dut)
51 else:
52 raise errors.ArgumentError(
53 'dut', 'not a Chrome OS device (--force to continue)')
54
Kuang-che Wu2ac9a922020-09-03 16:50:12 +080055 cros_util.reboot(
56 opts.dut, force_reboot_callback=cros_lab_util.reboot_via_servo)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080057
58
Kuang-che Wuc45cfa42019-01-15 00:15:01 +080059def _get_label_by_prefix(info, prefix):
60 for label in info['Labels']:
61 if label.startswith(prefix + ':'):
62 return label
63 return None
64
65
Kuang-che Wuca456462019-11-04 17:32:55 +080066def cmd_lease_dut(opts):
Kuang-che Wu5157dee2020-07-18 01:13:41 +080067 if opts.duration is not None and opts.duration < 60:
68 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
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)
71 if cros_lab_util.skylab_lease_dut(host, 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 Wub529d2d2020-09-10 12:26:56 +0800113def filter_dimensions_by_board(boards_with_prebuilt, dimensions):
114 result = []
115 for dimension in dimensions:
116 bots = cros_lab_util.swarming_bots_list([dimension], is_busy=None, limit=1)
117 if not bots:
118 continue
119 board = bots[0]['dimensions']['label-board'][0]
120 if board not in boards_with_prebuilt:
121 logger.warning(
122 'dimension=%s (board=%s) does not have corresponding '
123 'prebuilt image, ignore', dimension, board)
124 continue
125 result.append(dimension)
126 return result
127
128
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800129def is_acceptable_bot(boards_with_prebuilt, bot):
130 model = bot['dimensions']['label-model'][0]
131 if model in models_to_avoid:
132 logger.warning('model=%s is bad (reason:%s), ignore', model,
133 models_to_avoid[model])
134 return False
135
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800136 if boards_with_prebuilt is not None:
137 # Sometimes swarming database has inconsistent records. For example,
138 # label-model=kefka + label-board=strago are incorrect (should be
139 # label-board=kefka). It is probably human errors (strago is kefka's
140 # reference board).
141 board = bot['dimensions']['label-board'][0]
142 if board not in boards_with_prebuilt:
143 logger.warning('%s has unexpected board=%s, ignore',
144 bot['dimensions']['dut_name'][0], board)
145 return False
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800146
147 return True
Kuang-che Wu04619772020-10-22 18:57:07 +0800148
149
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800150async def lease_dut_parallelly(duration, bots, timeout=None):
151 tasks = []
152 hosts = []
153 for bot in bots:
154 host = bot['dimensions']['dut_name'][0]
155 hosts.append(host)
156 tasks.append(
157 asyncio.create_task(cros_lab_util.async_lease(host, duration=duration)))
158
159 try:
160 logger.info('trying to lease %d DUTs: %s', len(hosts), hosts)
161 for coro in asyncio.as_completed(tasks, timeout=timeout):
162 host = await coro
163 if host:
164 logger.info('leased %s', host)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800165 # Unfinished lease tasks will be cancelled when asyncio.run is
166 # finishing.
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800167 return host
168 return None
169 except asyncio.TimeoutError:
170 return None
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800171
172
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800173def do_allocate_dut(opts):
174 """Helper of cmd_allocate_dut.
175
176 Returns:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800177 (todo, host, board_to_build)
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800178 todo: 'ready' or 'wait'
Kuang-che Wuca456462019-11-04 17:32:55 +0800179 host: leased host name
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800180 board_to_build: board name for building image
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800181 """
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800182 if not opts.dut_name and not opts.pool:
183 raise errors.ArgumentError('--pool',
184 'need to be specified if not --dut_name')
Kuang-che Wu7e8abe62020-07-02 09:42:27 +0800185 if opts.version_hint:
186 for v in opts.version_hint.split(','):
187 if cros_util.is_cros_version(v) or cros_util.is_cros_snapshot_version(v):
188 continue
189 raise errors.ArgumentError(
190 '--version_hint',
191 'should be Chrome OS version numbers, separated by comma')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800192 if opts.duration is not None and opts.duration < 60:
193 raise errors.ArgumentError('--duration', 'must be at least 60 seconds')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800194
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800195 t0 = time.time()
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800196 dimensions = ['dut_state:ready']
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800197 if not opts.dut_name:
Zheng-Jie Chang17f36c82020-06-16 05:21:59 +0800198 dimensions.append('label-pool:' + opts.pool)
199
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800200 variants = []
201 if opts.board:
202 for board in opts.board.split(','):
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800203 variants.append('label-board:' +
204 cros_lab_util.normalize_board_name(board))
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800205 if opts.model:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800206 for model in opts.model.split(','):
Kuang-che Wu25723422020-09-24 22:20:26 +0800207 if model in models_to_avoid:
208 logger.warning('model=%s is bad (reason:%s), ignore', model,
209 models_to_avoid[model])
210 continue
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800211 variants.append('label-model:' + model)
Kuang-che Wu25723422020-09-24 22:20:26 +0800212 if not variants:
213 raise errors.ArgumentError('--model',
214 'all specified models are not supported')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800215 if opts.sku:
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800216 for sku in opts.sku.split(','):
217 variants.append('label-hwid_sku:' + cros_lab_util.normalize_sku_name(sku))
218 if opts.dut_name:
219 for dut_name in opts.dut_name.split(','):
220 variants.append('dut_name:' + dut_name)
221
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800222 variants = verify_dimensions_by_lab(variants)
223 variants = sorted(set(variants)) # dedup
224 if not variants:
225 raise errors.NoDutAvailable(
226 'Invalid constraints: %s;%s;%s;%s' %
227 (opts.board, opts.model, opts.sku, opts.dut_name))
228
229 # Filter variants by prebuilt images.
Kuang-che Wu79ea1192020-10-27 15:16:05 +0800230 boards_with_prebuilt = None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800231 if opts.version_hint:
232 if not opts.builder_hint:
233 opts.builder_hint = opts.board
234 if not opts.builder_hint:
235 raise errors.ArgumentError('--builder_hint',
236 'must be specified along with --version_hint')
237 boards_with_prebuilt = []
238 versions = opts.version_hint.split(',')
239 for builder in opts.builder_hint.split(','):
240 if not all(cros_util.has_test_image(builder, v) for v in versions):
241 logger.warning(
242 'builder=%s does not have prebuilt test image for %s, ignore',
243 builder, opts.version_hint)
244 continue
245 boards_with_prebuilt.append(cros_lab_util.normalize_board_name(builder))
246 logger.info('boards with prebuilt: %s', boards_with_prebuilt)
247 if not boards_with_prebuilt:
248 raise errors.ArgumentError(
249 '--version_hint',
250 'given builders have no prebuilt for %s' % opts.version_hint)
251 variants = filter_dimensions_by_board(boards_with_prebuilt, variants)
252 if not variants:
253 raise errors.NoDutAvailable(
254 'Devices with specified constraints have no prebuilt. '
255 'Wrong version number?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800256
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800257 while True:
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800258 filter_func = lambda bot: is_acceptable_bot(boards_with_prebuilt, bot)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800259 # Query every time because each iteration takes a few minutes
260 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800261 dimensions,
262 variants,
263 num=opts.parallel,
264 is_busy=False,
265 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800266 if not bots:
267 bots = select_available_bots_randomly(
Kuang-che Wueac89bd2020-10-23 16:07:15 +0800268 dimensions,
269 variants,
270 num=opts.parallel,
271 is_busy=True,
272 filter_func=filter_func)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800273 if not bots:
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800274 raise errors.NoDutAvailable(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800275 'no bots satisfy constraints; all are in maintenance state?')
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800276
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800277 remaining_time = opts.time_limit - (time.time() - t0)
278 if remaining_time <= 0:
279 break
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800280 timeout = min(120, remaining_time)
281 host = asyncio.run(lease_dut_parallelly(opts.duration, bots, timeout))
282 if host:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800283 # Resolve what board we should build during bisection.
284 board_to_build = None
285 bots = cros_lab_util.swarming_bots_list(['dut_name:' + host])
286 host_board = bots[0]['dimensions']['label-board'][0]
287 if opts.builder_hint:
288 for builder in opts.builder_hint.split(','):
289 if cros_lab_util.normalize_board_name(builder) == host_board:
290 board_to_build = builder
291 break
Kuang-che Wu04619772020-10-22 18:57:07 +0800292 else:
293 raise errors.DutLeaseException('DUT with unexpected board:%s' %
294 host_board)
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800295 else:
296 board_to_build = host_board
297
298 return 'ready', host, board_to_build
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800299 time.sleep(1)
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800300
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800301 logger.warning('unable to lease DUT in time limit')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800302 return 'wait', None, None
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800303
304
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800305def cmd_allocate_dut(opts):
Kuang-che Wuca456462019-11-04 17:32:55 +0800306 leased_dut = None
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800307 try:
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800308 todo, host, board = do_allocate_dut(opts)
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800309 leased_dut = cros_lab_util.dut_name_to_address(host) if host else None
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800310 result = {'result': todo, 'leased_dut': leased_dut, 'board': board}
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800311 print(json.dumps(result))
312 except Exception as e:
313 logger.exception('cmd_allocate_dut failed')
314 exception_name = e.__class__.__name__
315 result = {
316 'result': 'failed',
317 'exception': exception_name,
318 'text': str(e),
319 }
320 print(json.dumps(result))
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800321
322
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800323def cmd_repair_dut(opts):
324 cros_lab_util.repair(opts.dut)
325
326
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800327@cli.fatal_error_handler
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800328def main():
329 common.init()
330 parser = argparse.ArgumentParser()
Kuang-che Wufe1e88a2019-09-10 21:52:25 +0800331 cli.patching_argparser_exit(parser)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800332 common.add_common_arguments(parser)
333 subparsers = parser.add_subparsers(
334 dest='command', title='commands', metavar='<command>')
335
336 parser_version_info = subparsers.add_parser(
337 'version_info',
338 help='Query version info of given chromeos build',
339 description='Given chromeos `board` and `version`, '
340 'print version information of components.')
341 parser_version_info.add_argument(
342 'board', help='ChromeOS board name, like "samus".')
343 parser_version_info.add_argument(
344 'version',
345 type=cros_util.argtype_cros_version,
346 help='ChromeOS version, like "9876.0.0" or "R62-9876.0.0"')
347 parser_version_info.add_argument(
348 'name',
349 nargs='?',
350 help='Component name. If specified, output its version string. '
351 'Otherwise output all version info as dict in json format.')
352 parser_version_info.set_defaults(func=cmd_version_info)
353
354 parser_query_dut_board = subparsers.add_parser(
355 'query_dut_board', help='Query board name of given DUT')
356 parser_query_dut_board.add_argument('dut')
357 parser_query_dut_board.set_defaults(func=cmd_query_dut_board)
358
359 parser_reboot = subparsers.add_parser(
360 'reboot',
361 help='Reboot a DUT',
362 description='Reboot a DUT and verify the reboot is successful.')
Kuang-che Wu2534bab2020-10-23 17:37:16 +0800363 parser_reboot.add_argument('--force', action='store_true')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800364 parser_reboot.add_argument('dut')
365 parser_reboot.set_defaults(func=cmd_reboot)
366
Kuang-che Wuca456462019-11-04 17:32:55 +0800367 parser_lease_dut = subparsers.add_parser(
368 'lease_dut',
369 help='Lease a DUT in the lab',
370 description='Lease a DUT in the lab. '
371 'This is implemented by `skylab lease-dut` with additional checking.')
372 # "skylab lease-dut" doesn't take reason, so this is not required=True.
373 parser_lease_dut.add_argument('--session', help='session name')
374 parser_lease_dut.add_argument('dut')
375 parser_lease_dut.add_argument(
376 '--duration',
377 type=float,
378 help='duration in seconds; will be round to minutes')
379 parser_lease_dut.set_defaults(func=cmd_lease_dut)
380
381 parser_release_dut = subparsers.add_parser(
382 'release_dut',
383 help='Release a DUT in the lab',
384 description='Release a DUT in the lab. '
385 'This is implemented by `skylab release-dut` with additional checking.')
386 parser_release_dut.add_argument('--session', help='session name')
387 parser_release_dut.add_argument('dut')
388 parser_release_dut.set_defaults(func=cmd_release_dut)
389
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800390 parser_allocate_dut = subparsers.add_parser(
391 'allocate_dut',
392 help='Allocate a DUT in the lab',
Kuang-che Wuca456462019-11-04 17:32:55 +0800393 description='Allocate a DUT in the lab. It will lease a DUT in the lab '
394 'for bisecting. The caller (bisect-kit runner) of this command should '
395 'retry this command again later if no DUT available now.')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800396 parser_allocate_dut.add_argument(
397 '--session', required=True, help='session name')
398 parser_allocate_dut.add_argument(
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800399 '--pool',
400 help='Pool to search DUT (default: %(default)s)',
401 default=DEFAULT_DUT_POOL)
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800402 group = parser_allocate_dut.add_mutually_exclusive_group(required=True)
403 group.add_argument('--board', help='allocation criteria; comma separated')
404 group.add_argument('--model', help='allocation criteria; comma separated')
405 group.add_argument('--sku', help='allocation criteria; comma separated')
406 group.add_argument('--dut_name', help='allocation criteria; comma separated')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800407 parser_allocate_dut.add_argument(
Kuang-che Wu1e56ce22020-06-29 11:21:51 +0800408 '--version_hint', help='chromeos version; comma separated')
Kuang-che Wub529d2d2020-09-10 12:26:56 +0800409 parser_allocate_dut.add_argument(
410 '--builder_hint', help='chromeos builder; comma separated')
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800411 # Pubsub ack deadline is 10 minutes (b/143663659). Default 9 minutes with 1
412 # minute buffer.
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800413 parser_allocate_dut.add_argument(
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800414 '--time_limit',
415 type=int,
Kuang-che Wuc26dcdf2019-11-01 16:30:06 +0800416 default=9 * 60,
Kuang-che Wu0c9b7942019-10-30 16:55:39 +0800417 help='Time limit to attempt lease in seconds (default: %(default)s)')
418 parser_allocate_dut.add_argument(
419 '--duration',
420 type=float,
421 help='lease duration in seconds; will be round to minutes')
Kuang-che Wu5157dee2020-07-18 01:13:41 +0800422 parser_allocate_dut.add_argument(
423 '--parallel',
424 type=int,
425 default=1,
426 help='Submit multiple lease tasks to speed up (default: %(default)d)')
Kuang-che Wu22aa9d42019-01-25 10:35:33 +0800427 parser_allocate_dut.set_defaults(func=cmd_allocate_dut)
428
Kuang-che Wua8c3c3e2019-08-28 18:49:28 +0800429 parser_repair_dut = subparsers.add_parser(
430 'repair_dut',
431 help='Repair a DUT in the lab',
432 description='Repair a DUT in the lab. '
433 'This is simply wrapper of "deploy repair" with additional checking.')
434 parser_repair_dut.add_argument('dut')
435 parser_repair_dut.set_defaults(func=cmd_repair_dut)
436
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800437 opts = parser.parse_args()
438 common.config_logging(opts)
Kuang-che Wud3a4e842019-12-11 12:15:23 +0800439
440 # It's optional by default since python3.
441 if not opts.command:
442 parser.error('command is missing')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800443 opts.func(opts)
444
445
446if __name__ == '__main__':
447 main()