Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Parse & Validate CLI arguments for run_suite_skylab.py.""" |
| 6 | |
| 7 | from __future__ import absolute_import |
| 8 | from __future__ import division |
| 9 | from __future__ import print_function |
| 10 | |
| 11 | import argparse |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 12 | import ast |
Xixuan Wu | 52e396e | 2018-07-19 17:02:04 -0700 | [diff] [blame] | 13 | import sys |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 14 | |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 15 | from lucifer import autotest |
| 16 | from skylab_suite import cros_suite |
Xixuan Wu | 8930076 | 2018-07-13 14:58:46 -0700 | [diff] [blame] | 17 | from skylab_suite import swarming_lib |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def make_parser(): |
| 21 | """Make ArgumentParser instance for run_suite_skylab.py.""" |
| 22 | parser = argparse.ArgumentParser(prog='run_suite_skylab', |
| 23 | description=__doc__) |
| 24 | |
| 25 | # Suite-related parameters. |
| 26 | parser.add_argument('--board', required=True) |
| 27 | parser.add_argument( |
| 28 | '--model', |
| 29 | help=('The device model to run tests against. For non-unified ' |
| 30 | 'builds, model and board are synonymous, but board is more ' |
| 31 | 'accurate in some cases. Only pass this option if your build ' |
| 32 | 'is a unified build.')) |
| 33 | parser.add_argument( |
| 34 | '--pool', default='suites', |
| 35 | help=('Specify the pool of DUTs to run this suite. If you want no ' |
| 36 | 'pool, you can specify it with --pool="". USE WITH CARE.')) |
| 37 | parser.add_argument( |
| 38 | '--suite_name', required=True, |
| 39 | help='Specify the suite to run.') |
| 40 | parser.add_argument( |
| 41 | '--build', required=True, |
| 42 | help='Specify the build to run the suite with.') |
| 43 | parser.add_argument( |
| 44 | '--cheets_build', default=None, |
| 45 | help='ChromeOS Android build to be installed on dut.') |
| 46 | parser.add_argument( |
| 47 | '--firmware_rw_build', default=None, |
| 48 | help='Firmware build to be installed in dut RW firmware.') |
| 49 | parser.add_argument( |
| 50 | '--firmware_ro_build', default=None, |
| 51 | help='Firmware build to be installed in dut RO firmware.') |
| 52 | parser.add_argument( |
| 53 | '--test_source_build', default=None, |
| 54 | help=('Build that contains the test code. It can be the value ' |
| 55 | 'of arguments "--build", "--firmware_rw_build" or ' |
| 56 | '"--firmware_ro_build". Default is to use test code from ' |
| 57 | 'the "--build" version (CrOS image)')) |
| 58 | parser.add_argument( |
Xixuan Wu | 8930076 | 2018-07-13 14:58:46 -0700 | [diff] [blame] | 59 | '--priority', type=int, |
| 60 | default=swarming_lib.SKYLAB_HWTEST_PRIORITIES_MAP['Default'], |
| 61 | choices=[value for name, value in |
| 62 | swarming_lib.SORTED_SKYLAB_HWTEST_PRIORITY], |
| 63 | help=('The priority to run the suite. A high value means this suite ' |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 64 | 'will be executed in a low priority, e.g. being delayed to ' |
| 65 | 'execute. Each numerical value represents: '+ ', '.join([ |
Xixuan Wu | 8930076 | 2018-07-13 14:58:46 -0700 | [diff] [blame] | 66 | '(%s: %d)' % (name, value) for name, value in |
| 67 | swarming_lib.SORTED_SKYLAB_HWTEST_PRIORITY]))) |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 68 | parser.add_argument( |
| 69 | "--suite_args", type=ast.literal_eval, default=None, |
| 70 | action="store", |
| 71 | help="A dict of args passed to the suite control file.") |
Xixuan Wu | b279566 | 2018-06-28 16:02:53 -0700 | [diff] [blame] | 72 | parser.add_argument( |
| 73 | "--job_keyvals", type=ast.literal_eval, default={}, |
| 74 | action="store", |
| 75 | help="A dict of job keyvals to be passed to child jobs.") |
Xixuan Wu | 0956b63 | 2018-08-06 14:40:23 -0700 | [diff] [blame] | 76 | parser.add_argument( |
| 77 | "--minimum_duts", type=int, default=1, action="store", |
| 78 | help="A minimum required numbers of DUTs to run this suite.") |
Allen Li | b5888f0 | 2018-09-04 18:14:45 -0700 | [diff] [blame] | 79 | # TODO(ayatane): Make sure no callers pass --use_fallback before removing. |
Xixuan Wu | c79b1b7 | 2018-08-06 17:03:43 -0700 | [diff] [blame] | 80 | parser.add_argument( |
Allen Li | b5888f0 | 2018-09-04 18:14:45 -0700 | [diff] [blame] | 81 | "--use_fallback", action="store_true", help='Deprecated') |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 82 | |
| 83 | # Swarming-related parameters. |
| 84 | parser.add_argument( |
Xixuan Wu | 88c697b | 2018-05-30 16:35:25 -0700 | [diff] [blame] | 85 | '--execution_timeout_seconds', type=int, default=30, |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 86 | help='Seconds to allow a task to complete, once execution beings.') |
| 87 | |
| 88 | # logic-related parameters. |
| 89 | parser.add_argument( |
Xixuan Wu | 88c697b | 2018-05-30 16:35:25 -0700 | [diff] [blame] | 90 | '--create_and_return', action='store_true', |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 91 | help='Create the child jobs of a suite, then finish immediately.') |
| 92 | parser.add_argument( |
Xixuan Wu | c743071 | 2018-07-10 12:04:34 -0700 | [diff] [blame] | 93 | '--suite_id', default=None, |
| 94 | help='A suite ID, wait for whose child tests to finish.') |
| 95 | parser.add_argument( |
Xixuan Wu | 56424bc | 2018-05-15 11:03:27 -0700 | [diff] [blame] | 96 | '--test_retry', default=False, action='store_true', |
| 97 | help='Enable test-level retry.') |
| 98 | parser.add_argument( |
Xixuan Wu | 88c697b | 2018-05-30 16:35:25 -0700 | [diff] [blame] | 99 | '--max_retries', default=0, type=int, action='store', |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 100 | help='Maximum retries allowed at suite level. No retry if it is 0.') |
| 101 | parser.add_argument( |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 102 | '--timeout_mins', default=90, type=int, action='store', |
| 103 | help='Maximum minutes to wait for a suite to finish.') |
| 104 | parser.add_argument( |
Xixuan Wu | b098363 | 2018-08-17 17:54:42 -0700 | [diff] [blame] | 105 | '--passed_mins', default=0, type=int, action='store', |
| 106 | help='The minutes that this suite already runs for.') |
| 107 | parser.add_argument( |
Xixuan Wu | 88c697b | 2018-05-30 16:35:25 -0700 | [diff] [blame] | 108 | '--run_prod_code', action='store_true', default=False, |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 109 | help='Run the test code that lives in prod aka the test ' |
| 110 | 'code currently on the lab servers.') |
| 111 | parser.add_argument( |
Xixuan Wu | e71c893 | 2018-05-07 17:18:34 -0700 | [diff] [blame] | 112 | '--dry_run', action='store_true', |
| 113 | help=('Used for kicking off a run of suite with fake commands.')) |
| 114 | parser.add_argument( |
Xixuan Wu | 8565317 | 2018-08-22 16:52:32 -0700 | [diff] [blame] | 115 | '--pre_check', action='store_true', |
| 116 | help=('Used for checking whether a same suite is already kicked off' |
| 117 | 'to Skylab.')) |
| 118 | parser.add_argument( |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 119 | '--do_nothing', action='store_true', |
| 120 | help=('Used for monitoring purposes, to measure no-op swarming proxy ' |
| 121 | 'latency or create a dummy run_suite_skylab run.')) |
| 122 | |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 123 | # Abort-related parameters. |
| 124 | parser.add_argument( |
Xixuan Wu | 52e396e | 2018-07-19 17:02:04 -0700 | [diff] [blame] | 125 | '--abort_limit', default=sys.maxint, type=int, action='store', |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 126 | help=('Only abort first N parent tasks which fulfill the search ' |
| 127 | 'requirements.')) |
Xixuan Wu | ae8bfd2 | 2018-06-15 10:29:42 -0700 | [diff] [blame] | 128 | parser.add_argument( |
| 129 | '--suite_task_ids', nargs='*', default=[], |
| 130 | help=('Specify the parent swarming task id to abort.')) |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 131 | |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 132 | return parser |
| 133 | |
| 134 | |
| 135 | def verify_and_clean_options(options): |
| 136 | """Validate options.""" |
Xixuan Wu | 2406be3 | 2018-05-14 13:51:30 -0700 | [diff] [blame] | 137 | if options.suite_args is None: |
| 138 | options.suite_args = {} |
| 139 | |
Xixuan Wu | 17c8f7b | 2018-04-19 14:43:33 -0700 | [diff] [blame] | 140 | return True |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 141 | |
| 142 | |
Xixuan Wu | 9287fda | 2018-07-12 16:22:06 -0700 | [diff] [blame] | 143 | def parse_suite_spec(options): |
| 144 | """Parse options to suite_spec.""" |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 145 | suite_common = autotest.load('server.cros.dynamic_suite.suite_common') |
| 146 | builds = suite_common.make_builds_from_options(options) |
Xixuan Wu | 9287fda | 2018-07-12 16:22:06 -0700 | [diff] [blame] | 147 | return cros_suite.SuiteSpec( |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 148 | builds=builds, |
| 149 | suite_name=options.suite_name, |
| 150 | suite_file_name=suite_common.canonicalize_suite_name( |
| 151 | options.suite_name), |
| 152 | test_source_build=suite_common.get_test_source_build( |
| 153 | builds, test_source_build=options.test_source_build), |
| 154 | suite_args=options.suite_args, |
| 155 | priority=options.priority, |
| 156 | board=options.board, |
| 157 | pool=options.pool, |
Xixuan Wu | b279566 | 2018-06-28 16:02:53 -0700 | [diff] [blame] | 158 | job_keyvals=options.job_keyvals, |
Xixuan Wu | 0956b63 | 2018-08-06 14:40:23 -0700 | [diff] [blame] | 159 | minimum_duts=options.minimum_duts, |
Xixuan Wu | ba0276c | 2018-08-10 09:36:23 -0700 | [diff] [blame] | 160 | timeout_mins=options.timeout_mins, |
Xixuan Wu | 53d1571 | 2018-06-12 10:52:55 -0700 | [diff] [blame] | 161 | ) |