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