Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 1 | # Copyright 2018 - The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | r"""Create args. |
| 15 | |
| 16 | Defines the create arg parser that holds create specific args. |
| 17 | """ |
| 18 | |
Kevin Cheng | 9aeed4d | 2018-12-18 14:37:34 -0800 | [diff] [blame] | 19 | import argparse |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame] | 20 | import logging |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 21 | import os |
| 22 | |
| 23 | from acloud import errors |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 24 | from acloud.create import create_common |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 25 | from acloud.internal import constants |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 26 | from acloud.internal.lib import utils |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 27 | |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame] | 28 | logger = logging.getLogger(__name__) |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 29 | _DEFAULT_GPU = "default" |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 30 | CMD_CREATE = "create" |
| 31 | |
| 32 | |
| 33 | # TODO: Add this into main create args once create_cf/gf is deprecated. |
herbertxue | 1b78429 | 2021-11-03 13:38:10 +0800 | [diff] [blame] | 34 | # pylint: disable=too-many-statements |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 35 | def AddCommonCreateArgs(parser): |
| 36 | """Adds arguments common to create parsers. |
| 37 | |
| 38 | Args: |
| 39 | parser: ArgumentParser object, used to parse flags. |
| 40 | """ |
| 41 | parser.add_argument( |
| 42 | "--num", |
| 43 | type=int, |
| 44 | dest="num", |
| 45 | required=False, |
| 46 | default=1, |
| 47 | help="Number of instances to create.") |
| 48 | parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 49 | "--serial-log-file", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 50 | type=str, |
| 51 | dest="serial_log_file", |
| 52 | required=False, |
| 53 | help="Path to a *tar.gz file where serial logs will be saved " |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 54 | "when a device fails on boot.") |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 55 | parser.add_argument( |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 56 | "--autoconnect", |
chojoyce | e86730a | 2019-12-11 15:37:58 +0800 | [diff] [blame] | 57 | type=str, |
| 58 | nargs="?", |
chojoyce | 2d11689 | 2021-09-27 15:56:41 +0800 | [diff] [blame] | 59 | const=constants.INS_KEY_WEBRTC, |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 60 | dest="autoconnect", |
| 61 | required=False, |
chojoyce | 4e2d922 | 2020-01-03 17:04:05 +0800 | [diff] [blame] | 62 | choices=[constants.INS_KEY_VNC, constants.INS_KEY_ADB, |
| 63 | constants.INS_KEY_WEBRTC], |
| 64 | help="Determines to establish a tunnel forwarding adb/vnc and " |
| 65 | "launch VNC/webrtc. Establish a tunnel forwarding adb and vnc " |
| 66 | "then launch vnc if --autoconnect vnc is provided. Establish a " |
| 67 | "tunnel forwarding adb if --autoconnect adb is provided. " |
| 68 | "Establish a tunnel forwarding adb and auto-launch on the browser " |
| 69 | "if --autoconnect webrtc is provided. For local goldfish " |
| 70 | "instance, create a window.") |
Kevin Cheng | 4a8f5cf | 2018-08-15 08:59:28 -0700 | [diff] [blame] | 71 | parser.add_argument( |
| 72 | "--no-autoconnect", |
| 73 | action="store_false", |
| 74 | dest="autoconnect", |
daviddclo | 53fd847 | 2018-12-27 16:24:06 +0800 | [diff] [blame] | 75 | required=False, |
| 76 | help="Will not automatically create ssh tunnels forwarding adb & vnc " |
| 77 | "when instance created.") |
herbertxue | cdd8d79 | 2021-11-09 14:13:59 +0800 | [diff] [blame] | 78 | parser.add_argument( |
| 79 | "--mkcert", |
| 80 | action="store_true", |
| 81 | dest="mkcert", |
| 82 | required=False, |
| 83 | help="Install mkcert package on the host. It helps to create the " |
| 84 | "certification files for the WEB browser.") |
chojoyce | 2d11689 | 2021-09-27 15:56:41 +0800 | [diff] [blame] | 85 | parser.set_defaults(autoconnect=constants.INS_KEY_WEBRTC) |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 86 | parser.add_argument( |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 87 | "--unlock", |
| 88 | action="store_true", |
| 89 | dest="unlock_screen", |
| 90 | required=False, |
| 91 | default=False, |
| 92 | help="This can unlock screen after invoke vnc client.") |
| 93 | parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 94 | "--report-internal-ip", |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 95 | action="store_true", |
| 96 | dest="report_internal_ip", |
| 97 | required=False, |
| 98 | help="Report internal ip of the created instance instead of external " |
Kevin Cheng | 1f582bc | 2018-10-02 10:37:02 -0700 | [diff] [blame] | 99 | "ip. Using the internal ip is used when connecting from another " |
Kevin Cheng | 86d43c7 | 2018-08-30 10:59:14 -0700 | [diff] [blame] | 100 | "GCE instance.") |
Kevin Cheng | c9424a8 | 2018-10-25 11:34:55 -0700 | [diff] [blame] | 101 | parser.add_argument( |
Spencer Chu | afb541b | 2021-05-27 20:32:31 +0000 | [diff] [blame] | 102 | "--disable-external-ip", |
| 103 | action="store_true", |
| 104 | dest="disable_external_ip", |
| 105 | required=False, |
| 106 | help="Disable the external ip of the created instance.") |
| 107 | parser.add_argument( |
herbertxue | 59fc96c | 2021-10-05 15:31:06 +0800 | [diff] [blame] | 108 | "--extra-files", |
| 109 | nargs='+', |
| 110 | type=str, |
| 111 | dest="extra_files", |
| 112 | required=False, |
| 113 | help="Upload the extra files into GCE instance. e.g. " |
| 114 | "/path/to/file_in_local,/path/to/file_in_gce") |
| 115 | parser.add_argument( |
Kevin Cheng | c9424a8 | 2018-10-25 11:34:55 -0700 | [diff] [blame] | 116 | "--network", |
| 117 | type=str, |
| 118 | dest="network", |
| 119 | required=False, |
| 120 | help="Set the network the GCE instance will utilize.") |
Kevin Cheng | fab8cfc | 2019-06-27 14:01:37 -0700 | [diff] [blame] | 121 | parser.add_argument( |
| 122 | "--skip-pre-run-check", |
| 123 | action="store_true", |
| 124 | dest="skip_pre_run_check", |
| 125 | required=False, |
| 126 | help="Skip the pre-run check.") |
cylan | 6bc90ff | 2019-07-10 13:40:56 +0800 | [diff] [blame] | 127 | parser.add_argument( |
| 128 | "--boot-timeout", |
| 129 | dest="boot_timeout_secs", |
| 130 | type=int, |
| 131 | required=False, |
herbertxue | 5804bc1 | 2021-09-15 19:45:30 +0800 | [diff] [blame] | 132 | help="The maximum time in seconds used to wait for the AVD to download " |
| 133 | "artifacts and boot.") |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 134 | parser.add_argument( |
herbertxue | 40e7efb | 2019-12-13 11:47:24 +0800 | [diff] [blame] | 135 | "--wait-for-ins-stable", |
| 136 | dest="ins_timeout_secs", |
| 137 | type=int, |
| 138 | required=False, |
| 139 | help="The maximum time in seconds used to wait for the instance boot " |
| 140 | "up. The default value to wait for instance up time is 300 secs.") |
| 141 | parser.add_argument( |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 142 | "--build-target", |
| 143 | type=str, |
| 144 | dest="build_target", |
Ram Muthiah | e313c43 | 2021-05-26 12:35:02 -0700 | [diff] [blame] | 145 | help="Android build target, e.g. aosp_cf_x86_64_phone-userdebug, " |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 146 | "or short names: phone, tablet, or tablet_mobile.") |
| 147 | parser.add_argument( |
| 148 | "--branch", |
| 149 | type=str, |
| 150 | dest="branch", |
| 151 | help="Android branch, e.g. mnc-dev or git_mnc-dev") |
| 152 | parser.add_argument( |
| 153 | "--build-id", |
| 154 | type=str, |
| 155 | dest="build_id", |
| 156 | help="Android build id, e.g. 2145099, P2804227") |
| 157 | parser.add_argument( |
herbertxue | e659d15 | 2020-10-15 18:52:06 +0800 | [diff] [blame] | 158 | "--bootloader-branch", |
| 159 | type=str, |
| 160 | dest="bootloader_branch", |
| 161 | help="'cuttlefish only' Branch to consume the bootloader from.", |
| 162 | required=False) |
| 163 | parser.add_argument( |
| 164 | "--bootloader-build-id", |
| 165 | type=str, |
| 166 | dest="bootloader_build_id", |
| 167 | help="'cuttlefish only' Bootloader build id, e.g. P2804227", |
| 168 | required=False) |
| 169 | parser.add_argument( |
| 170 | "--bootloader-build-target", |
| 171 | type=str, |
| 172 | dest="bootloader_build_target", |
| 173 | help="'cuttlefish only' Bootloader build target.", |
| 174 | required=False) |
| 175 | parser.add_argument( |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 176 | "--kernel-build-id", |
| 177 | type=str, |
| 178 | dest="kernel_build_id", |
| 179 | required=False, |
| 180 | help="Android kernel build id, e.g. 4586590. This is to test a new" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 181 | " kernel build with a particular Android build (--build-id). If neither" |
| 182 | " kernel-branch nor kernel-build-id are specified, the kernel that's" |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 183 | " bundled with the Android build would be used.") |
| 184 | parser.add_argument( |
| 185 | "--kernel-branch", |
| 186 | type=str, |
| 187 | dest="kernel_branch", |
| 188 | required=False, |
| 189 | help="Android kernel build branch name, e.g." |
| 190 | " kernel-common-android-4.14. This is to test a new kernel build with a" |
| 191 | " particular Android build (--build-id). If specified without" |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 192 | " specifying kernel-build-id, the last green build in the branch will" |
| 193 | " be used. If neither kernel-branch nor kernel-build-id are specified," |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 194 | " the kernel that's bundled with the Android build would be used.") |
| 195 | parser.add_argument( |
| 196 | "--kernel-build-target", |
| 197 | type=str, |
| 198 | dest="kernel_build_target", |
| 199 | default="kernel", |
| 200 | help="Kernel build target, specify if different from 'kernel'") |
| 201 | parser.add_argument( |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 202 | "--kernel-artifact", |
| 203 | type=str, |
| 204 | dest="kernel_artifact", |
| 205 | required=False, |
| 206 | help="Goldfish remote host only. The name of the boot image to be " |
| 207 | "retrieved from Android build, e.g., boot-5.10.img.") |
| 208 | parser.add_argument( |
herbertxue | 1b78429 | 2021-11-03 13:38:10 +0800 | [diff] [blame] | 209 | "--ota-branch", |
| 210 | type=str, |
| 211 | dest="ota_branch", |
| 212 | required=False, |
| 213 | help="'cuttlefish only' OTA tools branch name. e.g. aosp-master") |
| 214 | parser.add_argument( |
| 215 | "--ota-build-id", |
| 216 | type=str, |
| 217 | dest="ota_build_id", |
| 218 | required=False, |
| 219 | help="'cuttlefish only' OTA tools build id, e.g. 2145099, P2804227") |
| 220 | parser.add_argument( |
| 221 | "--ota-build-target", |
| 222 | type=str, |
| 223 | dest="ota_build_target", |
| 224 | required=False, |
| 225 | help="'cuttlefish only' OTA tools build target, e.g. " |
| 226 | "cf_x86_64_phone-userdebug.") |
| 227 | parser.add_argument( |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 228 | "--system-branch", |
| 229 | type=str, |
| 230 | dest="system_branch", |
| 231 | help="'cuttlefish only' Branch to consume the system image (system.img) " |
| 232 | "from, will default to what is defined by --branch. " |
| 233 | "That feature allows to (automatically) test various combinations " |
| 234 | "of vendor.img (CF, e.g.) and system images (GSI, e.g.). ", |
| 235 | required=False) |
| 236 | parser.add_argument( |
| 237 | "--system-build-id", |
| 238 | type=str, |
| 239 | dest="system_build_id", |
| 240 | help="'cuttlefish only' System image build id, e.g. 2145099, P2804227", |
| 241 | required=False) |
| 242 | parser.add_argument( |
| 243 | "--system-build-target", |
| 244 | type=str, |
| 245 | dest="system_build_target", |
| 246 | help="'cuttlefish only' System image build target, specify if different " |
herbertxue | 03eb5d7 | 2019-09-10 14:52:10 +0800 | [diff] [blame] | 247 | "from --build-target", |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 248 | required=False) |
herbertxue | 877df86 | 2021-04-14 13:49:50 +0800 | [diff] [blame] | 249 | parser.add_argument( |
| 250 | "--launch-args", |
| 251 | type=str, |
| 252 | dest="launch_args", |
| 253 | help="'cuttlefish only' Add extra args to launch_cvd command.", |
| 254 | required=False) |
herbertxue | 7caa30f | 2021-05-20 10:14:09 +0800 | [diff] [blame] | 255 | parser.add_argument( |
| 256 | "--gce-metadata", |
| 257 | type=str, |
| 258 | dest="gce_metadata", |
| 259 | default=None, |
| 260 | help="'GCE instance only' Record data into GCE instance metadata with " |
| 261 | "key-value pair format. e.g. id:12,name:unknown.") |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 262 | # TODO(146314062): Remove --multi-stage-launch after infra don't use this |
| 263 | # args. |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 264 | parser.add_argument( |
| 265 | "--multi-stage-launch", |
| 266 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 267 | action="store_true", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 268 | required=False, |
herbertxue | da2619b | 2019-12-06 12:09:47 +0800 | [diff] [blame] | 269 | default=True, |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 270 | help="Enable the multi-stage cuttlefish launch.") |
| 271 | parser.add_argument( |
| 272 | "--no-multi-stage-launch", |
| 273 | dest="multi_stage_launch", |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 274 | action="store_false", |
Cody Schuffelen | 102b3b5 | 2019-07-17 10:26:35 -0700 | [diff] [blame] | 275 | required=False, |
| 276 | default=None, |
| 277 | help="Disable the multi-stage cuttlefish launch.") |
herbertxue | 6e54612 | 2020-01-06 23:35:25 +0800 | [diff] [blame] | 278 | parser.add_argument( |
| 279 | "--no-pull-log", |
| 280 | dest="no_pull_log", |
| 281 | action="store_true", |
| 282 | required=False, |
| 283 | default=None, |
| 284 | help="Disable auto download logs when AVD booting up failed.") |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 285 | # TODO(147335651): Add gpu in user config. |
| 286 | # TODO(147335651): Support "--gpu" without giving any value. |
| 287 | parser.add_argument( |
| 288 | "--gpu", |
| 289 | type=str, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 290 | const=_DEFAULT_GPU, |
| 291 | nargs="?", |
herbertxue | 9a651d6 | 2020-01-08 21:58:34 +0800 | [diff] [blame] | 292 | dest="gpu", |
| 293 | required=False, |
| 294 | default=None, |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 295 | help="GPU accelerator to use if any. e.g. nvidia-tesla-k80. For local " |
| 296 | "instances, this arg without assigning any value is to enable " |
| 297 | "local gpu support.") |
herbertxue | ffbcbc2 | 2020-07-07 14:35:34 +0800 | [diff] [blame] | 298 | # Hide following args for users, it is only used in infra. |
herbertxue | 408dba8 | 2020-03-19 19:23:32 +0800 | [diff] [blame] | 299 | parser.add_argument( |
Hsin-Yi Chen | e0bc539 | 2020-09-08 00:48:43 +0800 | [diff] [blame] | 300 | "--local-instance-dir", |
| 301 | dest="local_instance_dir", |
| 302 | required=False, |
| 303 | help=argparse.SUPPRESS) |
| 304 | parser.add_argument( |
herbertxue | 408dba8 | 2020-03-19 19:23:32 +0800 | [diff] [blame] | 305 | "--num-avds-per-instance", |
| 306 | type=int, |
| 307 | dest="num_avds_per_instance", |
| 308 | required=False, |
| 309 | default=1, |
| 310 | help=argparse.SUPPRESS) |
herbertxue | ffbcbc2 | 2020-07-07 14:35:34 +0800 | [diff] [blame] | 311 | parser.add_argument( |
herbertxue | b157447 | 2021-04-08 14:44:47 +0800 | [diff] [blame] | 312 | "--oxygen", |
| 313 | action="store_true", |
| 314 | dest="oxygen", |
| 315 | required=False, |
| 316 | help=argparse.SUPPRESS) |
| 317 | parser.add_argument( |
herbertxue | ffbcbc2 | 2020-07-07 14:35:34 +0800 | [diff] [blame] | 318 | "--zone", |
| 319 | type=str, |
| 320 | dest="zone", |
| 321 | required=False, |
| 322 | help=argparse.SUPPRESS) |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 323 | |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 324 | # TODO(b/118439885): Old arg formats to support transition, delete when |
| 325 | # transistion is done. |
| 326 | parser.add_argument( |
| 327 | "--serial_log_file", |
| 328 | type=str, |
| 329 | dest="serial_log_file", |
| 330 | required=False, |
Kevin Cheng | 9aeed4d | 2018-12-18 14:37:34 -0800 | [diff] [blame] | 331 | help=argparse.SUPPRESS) |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 332 | parser.add_argument( |
Richard Fung | 97503b2 | 2019-02-06 13:43:38 -0800 | [diff] [blame] | 333 | "--build_id", |
| 334 | type=str, |
| 335 | dest="build_id", |
| 336 | required=False, |
| 337 | help=argparse.SUPPRESS) |
| 338 | parser.add_argument( |
| 339 | "--build_target", |
| 340 | type=str, |
| 341 | dest="build_target", |
| 342 | required=False, |
| 343 | help=argparse.SUPPRESS) |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 344 | parser.add_argument( |
| 345 | "--system_branch", |
| 346 | type=str, |
| 347 | dest="system_branch", |
| 348 | required=False, |
| 349 | help=argparse.SUPPRESS) |
| 350 | parser.add_argument( |
| 351 | "--system_build_id", |
| 352 | type=str, |
| 353 | dest="system_build_id", |
| 354 | required=False, |
| 355 | help=argparse.SUPPRESS) |
| 356 | parser.add_argument( |
| 357 | "--system_build_target", |
| 358 | type=str, |
| 359 | dest="system_build_target", |
| 360 | required=False, |
| 361 | help=argparse.SUPPRESS) |
herbertxue | c6f0c26 | 2019-07-31 16:59:49 +0800 | [diff] [blame] | 362 | parser.add_argument( |
| 363 | "--kernel_build_id", |
| 364 | type=str, |
| 365 | dest="kernel_build_id", |
| 366 | required=False, |
| 367 | help=argparse.SUPPRESS) |
| 368 | parser.add_argument( |
| 369 | "--kernel_branch", |
| 370 | type=str, |
| 371 | dest="kernel_branch", |
| 372 | required=False, |
| 373 | help=argparse.SUPPRESS) |
| 374 | parser.add_argument( |
| 375 | "--kernel_build_target", |
| 376 | type=str, |
| 377 | dest="kernel_build_target", |
| 378 | default="kernel", |
| 379 | help=argparse.SUPPRESS) |
herbertxue | e659d15 | 2020-10-15 18:52:06 +0800 | [diff] [blame] | 380 | parser.add_argument( |
| 381 | "--bootloader_branch", |
| 382 | type=str, |
| 383 | dest="bootloader_branch", |
| 384 | help=argparse.SUPPRESS, |
| 385 | required=False) |
| 386 | parser.add_argument( |
| 387 | "--bootloader_build_id", |
| 388 | type=str, |
| 389 | dest="bootloader_build_id", |
| 390 | help=argparse.SUPPRESS, |
| 391 | required=False) |
| 392 | parser.add_argument( |
| 393 | "--bootloader_build_target", |
| 394 | type=str, |
| 395 | dest="bootloader_build_target", |
| 396 | help=argparse.SUPPRESS, |
| 397 | required=False) |
Kevin Cheng | 85a20f6 | 2018-10-25 11:53:11 -0700 | [diff] [blame] | 398 | |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 399 | |
| 400 | def GetCreateArgParser(subparser): |
| 401 | """Return the create arg parser. |
| 402 | |
| 403 | Args: |
| 404 | subparser: argparse.ArgumentParser that is attached to main acloud cmd. |
| 405 | |
| 406 | Returns: |
| 407 | argparse.ArgumentParser with create options defined. |
| 408 | """ |
| 409 | create_parser = subparser.add_parser(CMD_CREATE) |
| 410 | create_parser.required = False |
| 411 | create_parser.set_defaults(which=CMD_CREATE) |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 412 | # Use default=None to distinguish remote instance or local. The instance |
| 413 | # type will be remote if the arg is not provided. |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 414 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 415 | "--local-instance", |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 416 | type=_PositiveInteger, |
| 417 | const=0, |
| 418 | metavar="ID", |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 419 | nargs="?", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 420 | dest="local_instance", |
| 421 | required=False, |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 422 | help="Create a local AVD instance using the resources associated with " |
| 423 | "the ID. Choose an unused ID automatically if the value is " |
| 424 | "not specified (primarily for infra usage).") |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 425 | create_parser.add_argument( |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 426 | "--adb-port", "-p", |
| 427 | type=int, |
| 428 | default=None, |
| 429 | dest="adb_port", |
| 430 | required=False, |
| 431 | help="Specify port for adb forwarding.") |
| 432 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 433 | "--avd-type", |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 434 | type=str, |
| 435 | dest="avd_type", |
| 436 | default=constants.TYPE_CF, |
Peter Collingbourne | dce6d72 | 2020-05-07 15:29:21 -0700 | [diff] [blame] | 437 | choices=[constants.TYPE_GCE, constants.TYPE_CF, constants.TYPE_GF, constants.TYPE_CHEEPS, |
herbertxue | b8f22d9 | 2021-10-27 11:51:15 +0800 | [diff] [blame] | 438 | constants.TYPE_FVP, constants.TYPE_OPENWRT], |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 439 | help="Android Virtual Device type (default %s)." % constants.TYPE_CF) |
| 440 | create_parser.add_argument( |
herbertxue | 60d70c9 | 2021-03-31 20:56:37 +0800 | [diff] [blame] | 441 | "--config", "--flavor", |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 442 | type=str, |
| 443 | dest="flavor", |
herbertxue | 60d70c9 | 2021-03-31 20:56:37 +0800 | [diff] [blame] | 444 | help="The device flavor of the AVD (default %s). e.g. phone, tv, foldable." |
| 445 | % constants.FLAVOR_PHONE) |
cylan | abe0a3a | 2018-08-16 18:50:09 +0800 | [diff] [blame] | 446 | create_parser.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 447 | "--local-image", |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 448 | const=constants.FIND_IN_BUILD_ENV, |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 449 | type=str, |
| 450 | dest="local_image", |
| 451 | nargs="?", |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 452 | required=False, |
Kevin Cheng | 01b58bd | 2018-10-17 16:03:10 -0700 | [diff] [blame] | 453 | help="Use the locally built image for the AVD. Look for the image " |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 454 | "artifact in $ANDROID_PRODUCT_OUT if no args value is provided." |
| 455 | "e.g --local-image or --local-image /path/to/dir or --local-image " |
| 456 | "/path/to/file") |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 457 | create_parser.add_argument( |
Hsin-Yi Chen | 6a65847 | 2021-06-03 11:57:03 +0800 | [diff] [blame] | 458 | "--local-kernel-image", "--local-boot-image", |
Hsin-Yi Chen | 469d0dc | 2021-04-14 19:21:41 +0800 | [diff] [blame] | 459 | const=constants.FIND_IN_BUILD_ENV, |
| 460 | type=str, |
| 461 | dest="local_kernel_image", |
| 462 | nargs="?", |
| 463 | required=False, |
| 464 | help="Use the locally built kernel image for the AVD. Look for " |
| 465 | "boot.img or boot-*.img if the argument is a directory. Look for the " |
| 466 | "image in $ANDROID_PRODUCT_OUT if no argument is provided. e.g., " |
| 467 | "--local-kernel-image, --local-kernel-image /path/to/dir, or " |
| 468 | "--local-kernel-image /path/to/img") |
| 469 | create_parser.add_argument( |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 470 | "--local-system-image", |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 471 | const=constants.FIND_IN_BUILD_ENV, |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 472 | type=str, |
| 473 | dest="local_system_image", |
| 474 | nargs="?", |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 475 | required=False, |
| 476 | help="Use the locally built system images for the AVD. Look for the " |
| 477 | "images in $ANDROID_PRODUCT_OUT if no args value is provided. " |
Hsin-Yi Chen | bef8736 | 2021-04-13 16:59:02 +0800 | [diff] [blame] | 478 | "e.g., --local-system-image, --local-system-image /path/to/dir, or " |
| 479 | "--local-system-image /path/to/img") |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 480 | create_parser.add_argument( |
Hsin-Yi Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 481 | "--local-tool", |
| 482 | type=str, |
| 483 | dest="local_tool", |
| 484 | action="append", |
| 485 | default=[], |
| 486 | required=False, |
| 487 | help="Use the tools in the specified directory to create local " |
herbertxue | 4f9d116 | 2021-07-19 12:05:21 +0800 | [diff] [blame] | 488 | "instances. The directory structure follows $ANDROID_SOONG_HOST_OUT " |
| 489 | "or $ANDROID_EMULATOR_PREBUILTS.") |
| 490 | create_parser.add_argument( |
| 491 | "--cvd-host-package", |
| 492 | type=str, |
| 493 | dest="cvd_host_package", |
| 494 | required=False, |
| 495 | help="Use the specified path of the cvd host package to create " |
| 496 | "instances. e.g. /path/cvd-host_package_v1.tar.gz") |
Hsin-Yi Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 497 | create_parser.add_argument( |
chojoyce | f23e7d5 | 2018-10-15 17:36:35 +0800 | [diff] [blame] | 498 | "--image-download-dir", |
| 499 | type=str, |
| 500 | dest="image_download_dir", |
| 501 | required=False, |
| 502 | help="Define remote image download directory, e.g. /usr/local/dl.") |
herbertxue | 7ef23b2 | 2019-02-27 09:34:24 +0800 | [diff] [blame] | 503 | create_parser.add_argument( |
| 504 | "--yes", "-y", |
| 505 | action="store_true", |
| 506 | dest="no_prompt", |
| 507 | required=False, |
| 508 | help=("Automatic yes to prompts. Assume 'yes' as answer to all prompts " |
| 509 | "and run non-interactively.")) |
cylan | 2d63351 | 2019-09-09 20:33:42 +0800 | [diff] [blame] | 510 | create_parser.add_argument( |
| 511 | "--reuse-gce", |
| 512 | type=str, |
| 513 | const=constants.SELECT_ONE_GCE_INSTANCE, |
| 514 | nargs="?", |
| 515 | dest="reuse_gce", |
| 516 | required=False, |
| 517 | help="'cuttlefish only' This can help users use their own instance. " |
| 518 | "Reusing specific gce instance if --reuse-gce [instance_name] is " |
| 519 | "provided. Select one gce instance to reuse if --reuse-gce is " |
| 520 | "provided.") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 521 | create_parser.add_argument( |
herbertxue | 102a7ac | 2021-11-30 11:08:59 +0800 | [diff] [blame] | 522 | "--openwrt", |
| 523 | action="store_true", |
| 524 | dest="openwrt", |
| 525 | required=False, |
| 526 | help="'cuttlefish only' Create OpenWrt device when launching cuttlefish " |
| 527 | "device.") |
| 528 | create_parser.add_argument( |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 529 | "--host", |
| 530 | type=str, |
| 531 | dest="remote_host", |
| 532 | default=None, |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 533 | help="'cuttlefish only' Provide host name to clean up the remote host. " |
| 534 | "For example: '--host 1.1.1.1'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 535 | create_parser.add_argument( |
| 536 | "--host-user", |
| 537 | type=str, |
| 538 | dest="host_user", |
cylan | 0f61af6 | 2019-12-30 22:31:10 +0800 | [diff] [blame] | 539 | default=constants.GCE_USER, |
| 540 | help="'remote host only' Provide host user for logging in to the host. " |
| 541 | "The default value is vsoc-01. For example: '--host 1.1.1.1 --host-user " |
| 542 | "vsoc-02'") |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 543 | create_parser.add_argument( |
| 544 | "--host-ssh-private-key-path", |
| 545 | type=str, |
| 546 | dest="host_ssh_private_key_path", |
| 547 | default=None, |
| 548 | help="'remote host only' Provide host key for login on on this host.") |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 549 | # User should not specify --spec and --hw_property at the same time. |
| 550 | hw_spec_group = create_parser.add_mutually_exclusive_group() |
| 551 | hw_spec_group.add_argument( |
Sam Chiu | e669ef7 | 2018-10-16 16:23:37 +0800 | [diff] [blame] | 552 | "--hw-property", |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 553 | type=str, |
| 554 | dest="hw_property", |
| 555 | required=False, |
| 556 | help="Supported HW properties and example values: %s" % |
| 557 | constants.HW_PROPERTIES_CMD_EXAMPLE) |
| 558 | hw_spec_group.add_argument( |
| 559 | "--spec", |
| 560 | type=str, |
| 561 | dest="spec", |
| 562 | required=False, |
| 563 | choices=constants.SPEC_NAMES, |
| 564 | help="The name of a pre-configured device spec that we are " |
| 565 | "going to use.") |
Yuchen He | c4a8f25 | 2021-10-21 18:15:29 +0000 | [diff] [blame] | 566 | create_parser.add_argument( |
| 567 | "--disk-type", |
| 568 | type=str, |
| 569 | dest="disk_type", |
| 570 | required=False, |
| 571 | help="This is used to customize the GCE instance disk type, the " |
| 572 | "default disk type is from the stable host image. Use pd-ssd or " |
| 573 | "pd-standard to specify instance disk type.") |
herbertxue | 0621449 | 2021-10-12 19:43:32 +0800 | [diff] [blame] | 574 | create_parser.add_argument( |
| 575 | "--stable-host-image-name", |
| 576 | type=str, |
| 577 | dest="stable_host_image_name", |
| 578 | required=False, |
| 579 | default=None, |
| 580 | help=("'cuttlefish only' The Cuttlefish host image from which instances " |
| 581 | "are launched. If specified here, the value set in Acloud config " |
| 582 | "file will be overridden.")) |
Yuchen He | c4a8f25 | 2021-10-21 18:15:29 +0000 | [diff] [blame] | 583 | |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 584 | # Arguments for goldfish type. |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 585 | create_parser.add_argument( |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 586 | "--emulator-build-id", |
| 587 | type=int, |
| 588 | dest="emulator_build_id", |
| 589 | required=False, |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 590 | help="'goldfish only' Emulator build ID used to run the images. " |
herbertxue | 494891e | 2019-01-19 13:50:53 +0800 | [diff] [blame] | 591 | "e.g. 4669466.") |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 592 | create_parser.add_argument( |
| 593 | "--emulator-build-target", |
| 594 | dest="emulator_build_target", |
| 595 | required=False, |
| 596 | help="'goldfish remote host only' Emulator build target used to run " |
| 597 | "the images. e.g. sdk_tools_linux.") |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 598 | |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 599 | # Arguments for cheeps type. |
| 600 | create_parser.add_argument( |
Shao-Chuan Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 601 | "--stable-cheeps-host-image-name", |
| 602 | type=str, |
| 603 | dest="stable_cheeps_host_image_name", |
| 604 | required=False, |
| 605 | default=None, |
| 606 | help=("'cheeps only' The Cheeps host image from which instances are " |
| 607 | "launched. If specified here, the value set in Acloud config " |
| 608 | "file will be overridden.")) |
| 609 | create_parser.add_argument( |
| 610 | "--stable-cheeps-host-image-project", |
| 611 | type=str, |
| 612 | dest="stable_cheeps_host_image_project", |
| 613 | required=False, |
| 614 | default=None, |
| 615 | help=("'cheeps only' The project hosting the specified Cheeps host " |
| 616 | "image. If specified here, the value set in Acloud config file " |
| 617 | "will be overridden.")) |
| 618 | create_parser.add_argument( |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 619 | "--user", |
| 620 | type=str, |
| 621 | dest="username", |
| 622 | required=False, |
| 623 | default=None, |
| 624 | help="'cheeps only' username to log in to Chrome OS as.") |
| 625 | create_parser.add_argument( |
| 626 | "--password", |
| 627 | type=str, |
| 628 | dest="password", |
| 629 | required=False, |
| 630 | default=None, |
| 631 | help="'cheeps only' password to log in to Chrome OS with.") |
Richard Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 632 | create_parser.add_argument( |
| 633 | "--betty-image", |
| 634 | type=str, |
| 635 | dest="cheeps_betty_image", |
| 636 | required=False, |
| 637 | default=None, |
| 638 | help=("'cheeps only' The L1 betty version to use. Only makes sense " |
| 639 | "when launching a controller image with " |
| 640 | "stable-cheeps-host-image")) |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 641 | |
Kevin Cheng | 3087af5 | 2018-08-13 13:26:50 -0700 | [diff] [blame] | 642 | AddCommonCreateArgs(create_parser) |
| 643 | return create_parser |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 644 | |
| 645 | |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 646 | def _PositiveInteger(arg): |
| 647 | """Convert an argument from a string to a positive integer.""" |
| 648 | try: |
| 649 | value = int(arg) |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 650 | except ValueError as e: |
| 651 | raise argparse.ArgumentTypeError(arg + " is not an integer.") from e |
Hsin-Yi Chen | caec52f | 2020-07-16 14:59:26 +0800 | [diff] [blame] | 652 | if value <= 0: |
| 653 | raise argparse.ArgumentTypeError(arg + " is not positive.") |
| 654 | return value |
| 655 | |
| 656 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 657 | def _VerifyLocalArgs(args): |
| 658 | """Verify args starting with --local. |
| 659 | |
| 660 | Args: |
| 661 | args: Namespace object from argparse.parse_args. |
| 662 | |
| 663 | Raises: |
| 664 | errors.CheckPathError: Image path doesn't exist. |
| 665 | errors.UnsupportedCreateArgs: The specified avd type does not support |
| 666 | --local-system-image. |
| 667 | errors.UnsupportedLocalInstanceId: Local instance ID is invalid. |
| 668 | """ |
| 669 | if args.local_image and not os.path.exists(args.local_image): |
| 670 | raise errors.CheckPathError( |
| 671 | "Specified path doesn't exist: %s" % args.local_image) |
| 672 | |
Hsin-Yi Chen | e0bc539 | 2020-09-08 00:48:43 +0800 | [diff] [blame] | 673 | if args.local_instance_dir and not os.path.exists(args.local_instance_dir): |
| 674 | raise errors.CheckPathError( |
| 675 | "Specified path doesn't exist: %s" % args.local_instance_dir) |
| 676 | |
Hsin-Yi Chen | c1f6964 | 2020-12-28 12:44:43 +0800 | [diff] [blame] | 677 | if not (args.local_system_image is None or |
Hsin-Yi Chen | 19d665c | 2020-12-28 18:13:22 +0800 | [diff] [blame] | 678 | args.avd_type in (constants.TYPE_CF, constants.TYPE_GF)): |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 679 | raise errors.UnsupportedCreateArgs("%s instance does not support " |
| 680 | "--local-system-image" % |
| 681 | args.avd_type) |
chojoyce | d71e03c | 2021-11-03 13:36:36 +0800 | [diff] [blame] | 682 | # TODO(b/179340595): To support local image remote instance with kernel build. |
| 683 | if args.local_instance is None and args.local_image is not None and ( |
chojoyce | c223ec1 | 2021-11-10 15:25:03 +0800 | [diff] [blame] | 684 | args.kernel_branch or args.kernel_build_id): |
chojoyce | d71e03c | 2021-11-03 13:36:36 +0800 | [diff] [blame] | 685 | raise errors.UnsupportedCreateArgs( |
| 686 | "Acloud didn't support local image with specific kernel. " |
| 687 | "Please download the specific kernel and put it into " |
| 688 | "your local image folder: '%s'." % ( |
| 689 | args.local_image if args.local_image else |
| 690 | utils.GetBuildEnvironmentVariable(constants.ENV_ANDROID_PRODUCT_OUT))) |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 691 | |
| 692 | if (args.local_system_image and |
| 693 | not os.path.exists(args.local_system_image)): |
| 694 | raise errors.CheckPathError( |
| 695 | "Specified path doesn't exist: %s" % args.local_system_image) |
| 696 | |
Hsin-Yi Chen | e76c1bf | 2019-12-23 15:15:47 +0800 | [diff] [blame] | 697 | for tool_dir in args.local_tool: |
| 698 | if not os.path.exists(tool_dir): |
| 699 | raise errors.CheckPathError( |
| 700 | "Specified path doesn't exist: %s" % tool_dir) |
| 701 | |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 702 | |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 703 | def _VerifyHostArgs(args): |
| 704 | """Verify args starting with --host. |
| 705 | |
| 706 | Args: |
| 707 | args: Namespace object from argparse.parse_args. |
| 708 | |
| 709 | Raises: |
| 710 | errors.UnsupportedCreateArgs: When a create arg is specified but |
| 711 | unsupported for remote host mode. |
| 712 | """ |
| 713 | if args.remote_host and args.local_instance is not None: |
| 714 | raise errors.UnsupportedCreateArgs( |
| 715 | "--host is not supported for local instance.") |
| 716 | |
| 717 | if args.remote_host and args.num > 1: |
| 718 | raise errors.UnsupportedCreateArgs( |
| 719 | "--num is not supported for remote host.") |
| 720 | |
cylan | 30ab4d6 | 2020-01-06 14:01:09 +0800 | [diff] [blame] | 721 | if args.host_user != constants.GCE_USER and args.remote_host is None: |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 722 | raise errors.UnsupportedCreateArgs( |
| 723 | "--host-user only support for remote host.") |
| 724 | |
| 725 | if args.host_ssh_private_key_path and args.remote_host is None: |
| 726 | raise errors.UnsupportedCreateArgs( |
| 727 | "--host-ssh-private-key-path only support for remote host.") |
| 728 | |
| 729 | |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 730 | def _VerifyGoldfishArgs(args): |
| 731 | """Verify goldfish args. |
| 732 | |
| 733 | Args: |
| 734 | args: Namespace object from argparse.parse_args. |
| 735 | |
| 736 | Raises: |
| 737 | errors.UnsupportedCreateArgs: When a create arg is specified but |
| 738 | unsupported for goldfish. |
| 739 | """ |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 740 | goldfish_only_flags = [ |
| 741 | args.emulator_build_id, |
| 742 | args.emulator_build_target, |
| 743 | args.kernel_artifact |
| 744 | ] |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 745 | if args.avd_type != constants.TYPE_GF and any(goldfish_only_flags): |
| 746 | raise errors.UnsupportedCreateArgs( |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 747 | "--emulator-* and --kernel-artifact are only valid with " |
| 748 | "avd_type == %s" % constants.TYPE_GF) |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 749 | |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 750 | # Exclude kernel_build_target because the default value isn't empty. |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 751 | remote_kernel_flags = [ |
| 752 | args.kernel_build_id, |
| 753 | args.kernel_branch, |
| 754 | args.kernel_artifact, |
| 755 | ] |
| 756 | if (args.avd_type == constants.TYPE_GF and any(remote_kernel_flags) and |
| 757 | not all(remote_kernel_flags)): |
| 758 | raise errors.UnsupportedCreateArgs( |
| 759 | "Either none or all of --kernel-branch, --kernel-build-target, " |
| 760 | "--kernel-build-id, and --kernel-artifact must be specified for " |
| 761 | "goldfish.") |
| 762 | |
| 763 | remote_system_flags = [ |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 764 | args.system_build_target, |
| 765 | args.system_build_id, |
| 766 | args.system_branch, |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 767 | ] |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 768 | if (args.avd_type == constants.TYPE_GF and any(remote_system_flags) and |
| 769 | not all(remote_system_flags)): |
| 770 | raise errors.UnsupportedCreateArgs( |
| 771 | "Either none or all of --system-branch, --system-build-target, " |
| 772 | "and --system-build-id must be specified for goldfish.") |
| 773 | |
| 774 | remote_host_only_flags = ([args.emulator_build_target] + |
| 775 | remote_kernel_flags + remote_system_flags) |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 776 | if args.avd_type == constants.TYPE_GF and args.remote_host is None and any( |
| 777 | remote_host_only_flags): |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 778 | raise errors.UnsupportedCreateArgs( |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 779 | "--kernel-*, --system-*, and --emulator-build-target for goldfish " |
Hsin-Yi Chen | dd8de5d | 2021-10-21 12:18:23 +0800 | [diff] [blame] | 780 | "are only supported for remote host.") |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 781 | |
| 782 | |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 783 | def VerifyArgs(args): |
| 784 | """Verify args. |
| 785 | |
| 786 | Args: |
| 787 | args: Namespace object from argparse.parse_args. |
| 788 | |
| 789 | Raises: |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 790 | errors.UnsupportedMultiAdbPort: multi adb port doesn't support. |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 791 | errors.UnsupportedCreateArgs: When a create arg is specified but |
| 792 | unsupported for a particular avd type. |
| 793 | (e.g. --system-build-id for gf) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 794 | """ |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 795 | # Verify that user specified flavor name is in support list. |
| 796 | # We don't use argparse's builtin validation because we need to be able to |
| 797 | # tell when a user doesn't specify a flavor. |
| 798 | if args.flavor and args.flavor not in constants.ALL_FLAVORS: |
herbertxue | 36b99f1 | 2021-03-25 14:47:28 +0800 | [diff] [blame] | 799 | logger.debug("Flavor[%s] isn't in default support list: %s", |
| 800 | args.flavor, constants.ALL_FLAVORS) |
| 801 | |
Hsin-Yi Chen | 725ca6f | 2021-10-06 17:58:58 +0800 | [diff] [blame] | 802 | if args.avd_type not in (constants.TYPE_CF, constants.TYPE_GF): |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 803 | if args.system_branch or args.system_build_id or args.system_build_target: |
| 804 | raise errors.UnsupportedCreateArgs( |
| 805 | "--system-* args are not supported for AVD type: %s" |
| 806 | % args.avd_type) |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 807 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 808 | if args.num > 1 and args.adb_port: |
| 809 | raise errors.UnsupportedMultiAdbPort( |
| 810 | "--adb-port is not supported for multi-devices.") |
| 811 | |
herbertxue | 755ad48 | 2019-11-21 11:31:29 +0800 | [diff] [blame] | 812 | if args.num > 1 and args.local_instance is not None: |
| 813 | raise errors.UnsupportedCreateArgs( |
| 814 | "--num is not supported for local instance.") |
| 815 | |
herbertxue | 93630f5 | 2020-03-06 16:06:56 +0800 | [diff] [blame] | 816 | if args.local_instance is None and args.gpu == _DEFAULT_GPU: |
| 817 | raise errors.UnsupportedCreateArgs( |
| 818 | "Please assign one gpu model for GCE instance. Reference: " |
| 819 | "https://cloud.google.com/compute/docs/gpus") |
| 820 | |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 821 | if args.adb_port: |
| 822 | utils.CheckPortFree(args.adb_port) |
| 823 | |
herbertxue | c58d281 | 2021-01-21 15:02:27 +0800 | [diff] [blame] | 824 | hw_properties = create_common.ParseKeyValuePairArgs(args.hw_property) |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 825 | for key in hw_properties: |
| 826 | if key not in constants.HW_PROPERTIES: |
| 827 | raise errors.InvalidHWPropertyError( |
| 828 | "[%s] is an invalid hw property, supported values are:%s. " |
| 829 | % (key, constants.HW_PROPERTIES)) |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 830 | |
Richard Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 831 | cheeps_only_flags = [args.stable_cheeps_host_image_name, |
| 832 | args.stable_cheeps_host_image_project, |
| 833 | args.username, |
| 834 | args.password, |
| 835 | args.cheeps_betty_image] |
| 836 | if args.avd_type != constants.TYPE_CHEEPS and any(cheeps_only_flags): |
Shao-Chuan Lee | 8024411 | 2020-02-04 17:14:07 +0900 | [diff] [blame] | 837 | raise errors.UnsupportedCreateArgs( |
Richard Fung | d7d57f4 | 2020-04-09 12:58:49 -0700 | [diff] [blame] | 838 | "--stable-cheeps-*, --betty-image, --username and --password are " |
| 839 | "only valid with avd_type == %s" % constants.TYPE_CHEEPS) |
Richard Fung | 8d3979e | 2019-06-12 16:00:34 -0700 | [diff] [blame] | 840 | if (args.username or args.password) and not (args.username and args.password): |
| 841 | raise ValueError("--username and --password must both be set") |
chojoyce | c60fa58 | 2019-07-11 16:09:02 +0800 | [diff] [blame] | 842 | if not args.autoconnect and args.unlock_screen: |
| 843 | raise ValueError("--no-autoconnect and --unlock couldn't be " |
| 844 | "passed in together.") |
Sam Chiu | 5912054 | 2019-08-15 09:32:32 +0800 | [diff] [blame] | 845 | |
Hsin-Yi Chen | c7e7699 | 2021-07-26 18:37:36 +0800 | [diff] [blame] | 846 | _VerifyGoldfishArgs(args) |
Hsin-Yi Chen | 2a60933 | 2019-10-07 19:39:52 +0800 | [diff] [blame] | 847 | _VerifyLocalArgs(args) |
cylan | d43f293 | 2019-11-26 17:37:28 +0800 | [diff] [blame] | 848 | _VerifyHostArgs(args) |