Commit 5d5aafa9 authored by Haiyang Pan's avatar Haiyang Pan Committed by Commit Bot

emulator: add "--dry-run" option for avd create

Bug: 922145
Change-Id: I08d3a9cc3dda9fe4673399c27d07a41d4eeadcc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2138791
Commit-Queue: Haiyang Pan <hypan@google.com>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757534}
parent 88c280cc
...@@ -183,7 +183,8 @@ class AvdConfig(object): ...@@ -183,7 +183,8 @@ class AvdConfig(object):
force=False, force=False,
snapshot=False, snapshot=False,
keep=False, keep=False,
cipd_json_output=None): cipd_json_output=None,
dry_run=False):
"""Create an instance of the AVD CIPD package. """Create an instance of the AVD CIPD package.
This method: This method:
...@@ -192,7 +193,8 @@ class AvdConfig(object): ...@@ -192,7 +193,8 @@ class AvdConfig(object):
- modifies the AVD's ini files to support running chromium tests - modifies the AVD's ini files to support running chromium tests
in chromium infrastructure in chromium infrastructure
- optionally starts & stops the AVD for snapshotting (default no) - optionally starts & stops the AVD for snapshotting (default no)
- creates and uploads an instance of the AVD CIPD package - By default creates and uploads an instance of the AVD CIPD package
(can be turned off by dry_run flag).
- optionally deletes the AVD (default yes) - optionally deletes the AVD (default yes)
Args: Args:
...@@ -202,6 +204,8 @@ class AvdConfig(object): ...@@ -202,6 +204,8 @@ class AvdConfig(object):
keep: bool indicating whether to keep the AVD after creating keep: bool indicating whether to keep the AVD after creating
the CIPD package. the CIPD package.
cipd_json_output: string path to pass to `cipd create` via -json-output. cipd_json_output: string path to pass to `cipd create` via -json-output.
dry_run: When set to True, it will skip the CIPD package creation
after creating the AVD.
""" """
logging.info('Installing required packages.') logging.info('Installing required packages.')
self._InstallCipdPackages(packages=[ self._InstallCipdPackages(packages=[
...@@ -309,13 +313,16 @@ class AvdConfig(object): ...@@ -309,13 +313,16 @@ class AvdConfig(object):
'-json-output', '-json-output',
cipd_json_output, cipd_json_output,
]) ])
try: if dry_run:
for line in cmd_helper.IterCmdOutputLines(cipd_create_cmd): logging.info('Dry run. CIPD package creation skipped')
logging.info(' %s', line) else:
except subprocess.CalledProcessError as e: try:
raise AvdException( for line in cmd_helper.IterCmdOutputLines(cipd_create_cmd):
'CIPD package creation failed: %s' % str(e), logging.info(' %s', line)
command=cipd_create_cmd) except subprocess.CalledProcessError as e:
raise AvdException(
'CIPD package creation failed: %s' % str(e),
command=cipd_create_cmd)
finally: finally:
if not keep: if not keep:
......
...@@ -69,11 +69,18 @@ def main(raw_args): ...@@ -69,11 +69,18 @@ def main(raw_args):
metavar='PATH', metavar='PATH',
help='Path to which `cipd create` should dump json output ' help='Path to which `cipd create` should dump json output '
'via -json-output.') 'via -json-output.')
create_parser.add_argument(
'--dry-run',
action='store_true',
help='Skip the CIPD package creation after creating the AVD.')
def create_cmd(args): def create_cmd(args):
avd.AvdConfig(args.avd_config).Create( avd.AvdConfig(args.avd_config).Create(
force=args.force, snapshot=args.snapshot, keep=args.keep, force=args.force,
cipd_json_output=args.cipd_json_output) snapshot=args.snapshot,
keep=args.keep,
cipd_json_output=args.cipd_json_output,
dry_run=args.dry_run)
return 0 return 0
create_parser.set_defaults(func=create_cmd) create_parser.set_defaults(func=create_cmd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment