Use "--config" in launch_cvd command for default hardware settings.
The launch_cvd have new feature to setup hardware default settings with
"--config". Acloud don't need to pass resolution or memory settings in
launch_cvd command.
Bug: 180618596
Test: acloud-dev create -vv
acloud-dev create --flavor auto --branch git_master -vv
acloud-dev create --local-instance -vv
Change-Id: I795787d8ba2c70dbad9f53aaf386278d0d184f33
diff --git a/create/avd_spec.py b/create/avd_spec.py
index af61f4b..32661a2 100644
--- a/create/avd_spec.py
+++ b/create/avd_spec.py
@@ -124,6 +124,7 @@
self._kernel_build_info = None
self._bootloader_build_info = None
self._hw_property = None
+ self._hw_customize = False
self._remote_host = None
self._gce_metadata = None
self._host_user = None
@@ -280,11 +281,13 @@
logger.debug("Default hw property for [%s] flavor: %s", self._flavor,
self._hw_property)
if self._cfg.hw_property:
+ self._hw_customize = True
cfg_hw_property = self._ParseHWPropertyStr(self._cfg.hw_property)
logger.debug("Hw property from config: %s", cfg_hw_property)
self._hw_property.update(cfg_hw_property)
if args.hw_property:
+ self._hw_customize = True
arg_hw_property = self._ParseHWPropertyStr(args.hw_property)
logger.debug("Use custom hw property: %s", arg_hw_property)
self._hw_property.update(arg_hw_property)
@@ -707,6 +710,11 @@
return self._hw_property
@property
+ def hw_customize(self):
+ """Return the hw_customize."""
+ return self._hw_customize
+
+ @property
def local_image_dir(self):
"""Return local image dir."""
return self._local_image_dir
diff --git a/create/local_image_local_instance.py b/create/local_image_local_instance.py
index 30a2dc1..124c431 100644
--- a/create/local_image_local_instance.py
+++ b/create/local_image_local_instance.py
@@ -75,12 +75,12 @@
_TARGET_FILES_IMAGES_DIR_NAME = "IMAGES"
_TARGET_FILES_META_DIR_NAME = "META"
_MIXED_SUPER_IMAGE_NAME = "mixed_super.img"
-_CMD_LAUNCH_CVD_ARGS = (" -daemon -cpus %s -x_res %s -y_res %s -dpi %s "
- "-memory_mb %s -run_adb_connector=%s "
+_CMD_LAUNCH_CVD_ARGS = (" -daemon -config=%s -run_adb_connector=%s "
"-system_image_dir %s -instance_dir %s "
"-undefok=report_anonymous_usage_stats,enable_sandbox "
"-report_anonymous_usage_stats=y "
"-enable_sandbox=false")
+_CMD_LAUNCH_CVD_HW_ARGS = " -cpus %s -x_res %s -y_res %s -dpi %s -memory_mb %s"
_CMD_LAUNCH_CVD_GPU_ARG = " -gpu_mode=auto"
_CMD_LAUNCH_CVD_DISK_ARGS = (" -blank_data_image_mb %s "
"-data_policy always_create")
@@ -186,6 +186,7 @@
return ins_id, ins_lock
raise errors.CreateError(_INSTANCES_IN_USE_MSG)
+ #pylint: disable=too-many-locals
def _CreateInstance(self, local_instance_id, artifact_paths, avd_spec,
no_prompts):
"""Create a CVD instance.
@@ -213,8 +214,11 @@
self.PrepareLocalCvdToolsLink(cvd_home_dir, artifact_paths.host_bins)
launch_cvd_path = os.path.join(artifact_paths.host_bins, "bin",
constants.CMD_LAUNCH_CVD)
+ hw_property = None
+ if avd_spec.hw_customize:
+ hw_property = avd_spec.hw_property
cmd = self.PrepareLaunchCVDCmd(launch_cvd_path,
- avd_spec.hw_property,
+ hw_property,
avd_spec.connect_adb,
artifact_paths.image_dir,
runtime_dir,
@@ -222,7 +226,8 @@
avd_spec.connect_vnc,
avd_spec.gpu,
super_image_path,
- avd_spec.cfg.launch_args)
+ avd_spec.cfg.launch_args,
+ avd_spec.flavor)
result_report = report.Report(command="create")
instance_name = instance.GetLocalInstanceName(local_instance_id)
@@ -391,7 +396,7 @@
def PrepareLaunchCVDCmd(launch_cvd_path, hw_property, connect_adb,
image_dir, runtime_dir, connect_webrtc,
connect_vnc, gpu, super_image_path,
- launch_args):
+ launch_args, flavor):
"""Prepare launch_cvd command.
Create the launch_cvd commands with all the required args and add
@@ -409,17 +414,20 @@
"default" if gpu is enabled.
super_image_path: String of non-default super image path.
launch_args: String of launch args.
+ flavor: String of flavor name.
Returns:
String, launch_cvd cmd.
"""
launch_cvd_w_args = launch_cvd_path + _CMD_LAUNCH_CVD_ARGS % (
- hw_property["cpu"], hw_property["x_res"], hw_property["y_res"],
- hw_property["dpi"], hw_property["memory"],
- ("true" if connect_adb else "false"), image_dir, runtime_dir)
- if constants.HW_ALIAS_DISK in hw_property:
- launch_cvd_w_args = (launch_cvd_w_args + _CMD_LAUNCH_CVD_DISK_ARGS %
- hw_property[constants.HW_ALIAS_DISK])
+ flavor, ("true" if connect_adb else "false"), image_dir, runtime_dir)
+ if hw_property:
+ launch_cvd_w_args = launch_cvd_w_args + _CMD_LAUNCH_CVD_HW_ARGS % (
+ hw_property["cpu"], hw_property["x_res"], hw_property["y_res"],
+ hw_property["dpi"], hw_property["memory"])
+ if constants.HW_ALIAS_DISK in hw_property:
+ launch_cvd_w_args = (launch_cvd_w_args + _CMD_LAUNCH_CVD_DISK_ARGS %
+ hw_property[constants.HW_ALIAS_DISK])
if connect_webrtc:
launch_cvd_w_args = launch_cvd_w_args + _CMD_LAUNCH_CVD_WEBRTC_ARGS
diff --git a/create/local_image_local_instance_test.py b/create/local_image_local_instance_test.py
index 88215b1..98fee97 100644
--- a/create/local_image_local_instance_test.py
+++ b/create/local_image_local_instance_test.py
@@ -35,32 +35,32 @@
LAUNCH_CVD_CMD_WITH_DISK = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -blank_data_image_mb fake -data_policy always_create -start_vnc_server=true
+launch_cvd -daemon -config=phone -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -blank_data_image_mb fake -data_policy always_create -start_vnc_server=true
EOF"""
LAUNCH_CVD_CMD_NO_DISK = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true
+launch_cvd -daemon -config=phone -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -start_vnc_server=true
EOF"""
LAUNCH_CVD_CMD_NO_DISK_WITH_GPU = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true -gpu_mode=auto
+launch_cvd -daemon -config=phone -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -start_vnc_server=true -gpu_mode=auto
EOF"""
LAUNCH_CVD_CMD_WITH_WEBRTC = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -guest_enforce_security=false -vm_manager=crosvm -start_webrtc=true -webrtc_public_ip=0.0.0.0
+launch_cvd -daemon -config=auto -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -guest_enforce_security=false -vm_manager=crosvm -start_webrtc=true -webrtc_public_ip=0.0.0.0
EOF"""
LAUNCH_CVD_CMD_WITH_SUPER_IMAGE = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true -super_image=fake_super_image
+launch_cvd -daemon -config=phone -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true -super_image=fake_super_image
EOF"""
LAUNCH_CVD_CMD_WITH_ARGS = """sg group1 <<EOF
sg group2
-launch_cvd -daemon -cpus fake -x_res fake -y_res fake -dpi fake -memory_mb fake -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true -setupwizard_mode=REQUIRED
+launch_cvd -daemon -config=phone -run_adb_connector=true -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,enable_sandbox -report_anonymous_usage_stats=y -enable_sandbox=false -start_vnc_server=true -setupwizard_mode=REQUIRED
EOF"""
_EXPECTED_DEVICES_IN_REPORT = [
@@ -337,7 +337,7 @@
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
- "fake_cvd_dir", False, True, None, None, None)
+ "fake_cvd_dir", False, True, None, None, None, "phone")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_DISK)
# "disk" doesn't exist in hw_property.
@@ -345,30 +345,31 @@
"dpi": "fake", "memory": "fake"}
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
- "fake_cvd_dir", False, True, None, None, None)
+ "fake_cvd_dir", False, True, None, None, None, "phone")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_NO_DISK)
# "gpu" is enabled with "default"
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
- "fake_cvd_dir", False, True, "default", None, None)
+ "fake_cvd_dir", False, True, "default", None, None, "phone")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_NO_DISK_WITH_GPU)
+ # Following test with hw_property is None.
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
- constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
- "fake_cvd_dir", True, False, None, None, None)
+ constants.CMD_LAUNCH_CVD, None, True, "fake_image_dir",
+ "fake_cvd_dir", True, False, None, None, None, "auto")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_WEBRTC)
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
- constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
- "fake_cvd_dir", False, True, None, "fake_super_image", None)
+ constants.CMD_LAUNCH_CVD, None, True, "fake_image_dir",
+ "fake_cvd_dir", False, True, None, "fake_super_image", None, "phone")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_SUPER_IMAGE)
# Add args into launch command with "-setupwizard_mode=REQUIRED"
launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
- constants.CMD_LAUNCH_CVD, hw_property, True, "fake_image_dir",
+ constants.CMD_LAUNCH_CVD, None, True, "fake_image_dir",
"fake_cvd_dir", False, True, None, None,
- "-setupwizard_mode=REQUIRED")
+ "-setupwizard_mode=REQUIRED", "phone")
self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_ARGS)
@mock.patch.object(utils, "GetUserAnswerYes")
diff --git a/internal/lib/cvd_compute_client_multi_stage.py b/internal/lib/cvd_compute_client_multi_stage.py
index 3a79bac..76dd644 100644
--- a/internal/lib/cvd_compute_client_multi_stage.py
+++ b/internal/lib/cvd_compute_client_multi_stage.py
@@ -297,24 +297,26 @@
launch_cvd_args.append(
"-blank_data_image_mb=%d" % (blank_data_disk_size_gb * 1024))
if avd_spec:
- launch_cvd_args.append(
- "-x_res=" + avd_spec.hw_property[constants.HW_X_RES])
- launch_cvd_args.append(
- "-y_res=" + avd_spec.hw_property[constants.HW_Y_RES])
- launch_cvd_args.append(
- "-dpi=" + avd_spec.hw_property[constants.HW_ALIAS_DPI])
- if constants.HW_ALIAS_DISK in avd_spec.hw_property:
+ launch_cvd_args.append("-config=%s" % avd_spec.flavor)
+ if avd_spec.hw_customize:
launch_cvd_args.append(
- "-data_policy=" + self.DATA_POLICY_ALWAYS_CREATE)
+ "-x_res=" + avd_spec.hw_property[constants.HW_X_RES])
launch_cvd_args.append(
- "-blank_data_image_mb="
- + avd_spec.hw_property[constants.HW_ALIAS_DISK])
- if constants.HW_ALIAS_CPUS in avd_spec.hw_property:
+ "-y_res=" + avd_spec.hw_property[constants.HW_Y_RES])
launch_cvd_args.append(
- "-cpus=%s" % avd_spec.hw_property[constants.HW_ALIAS_CPUS])
- if constants.HW_ALIAS_MEMORY in avd_spec.hw_property:
- launch_cvd_args.append(
- "-memory_mb=%s" % avd_spec.hw_property[constants.HW_ALIAS_MEMORY])
+ "-dpi=" + avd_spec.hw_property[constants.HW_ALIAS_DPI])
+ if constants.HW_ALIAS_DISK in avd_spec.hw_property:
+ launch_cvd_args.append(
+ "-data_policy=" + self.DATA_POLICY_ALWAYS_CREATE)
+ launch_cvd_args.append(
+ "-blank_data_image_mb="
+ + avd_spec.hw_property[constants.HW_ALIAS_DISK])
+ if constants.HW_ALIAS_CPUS in avd_spec.hw_property:
+ launch_cvd_args.append(
+ "-cpus=%s" % avd_spec.hw_property[constants.HW_ALIAS_CPUS])
+ if constants.HW_ALIAS_MEMORY in avd_spec.hw_property:
+ launch_cvd_args.append(
+ "-memory_mb=%s" % avd_spec.hw_property[constants.HW_ALIAS_MEMORY])
if avd_spec.connect_webrtc:
launch_cvd_args.extend(_WEBRTC_ARGS)
launch_cvd_args.append(_WEBRTC_ID % {"instance": instance})
diff --git a/internal/lib/cvd_compute_client_multi_stage_test.py b/internal/lib/cvd_compute_client_multi_stage_test.py
index 34ea323..0027ee3 100644
--- a/internal/lib/cvd_compute_client_multi_stage_test.py
+++ b/internal/lib/cvd_compute_client_multi_stage_test.py
@@ -111,7 +111,7 @@
"""test GetLaunchCvdArgs."""
# test GetLaunchCvdArgs with avd_spec
fake_avd_spec = avd_spec.AVDSpec(self.args)
- expeted_args = ["-x_res=1080", "-y_res=1920", "-dpi=240",
+ expeted_args = ["-config=phone", "-x_res=1080", "-y_res=1920", "-dpi=240",
"-data_policy=always_create", "-blank_data_image_mb=10240",
"-cpus=2", "-memory_mb=4096", "-num_instances=2",
"--setupwizard_mode=REQUIRED", "-gpu_mode=auto",