Handle the case if launch_cvd doesn't support "-config".
If launch_cvd doesn't support "-config", Acloud needs to pass hardware
property args into launch_cvd.
Bug: 184088394
Test: acloud-dev create --build-target cf_x86_phone-userdebug --branch git_qt-gsi
Change-Id: If4c9b9894ddc785d2a7e0ab2f5a02791eadf22a6
diff --git a/internal/lib/cvd_compute_client_multi_stage.py b/internal/lib/cvd_compute_client_multi_stage.py
index 6e7137d..0e415ef 100644
--- a/internal/lib/cvd_compute_client_multi_stage.py
+++ b/internal/lib/cvd_compute_client_multi_stage.py
@@ -53,6 +53,7 @@
logger = logging.getLogger(__name__)
+_CONFIG_ARG = "-config"
_DECOMPRESS_KERNEL_ARG = "-decompress_kernel=true"
_AGREEMENT_PROMPT_ARG = "-report_anonymous_usage_stats=y"
_UNDEFOK_ARG = "-undefok=report_anonymous_usage_stats,config"
@@ -291,7 +292,7 @@
"-blank_data_image_mb=%d" % (blank_data_disk_size_gb * 1024))
if avd_spec:
launch_cvd_args.append("-config=%s" % avd_spec.flavor)
- if avd_spec.hw_customize:
+ if avd_spec.hw_customize or not self._ArgSupportInLaunchCVD(_CONFIG_ARG):
launch_cvd_args.append(
"-x_res=" + avd_spec.hw_property[constants.HW_X_RES])
launch_cvd_args.append(
@@ -334,6 +335,19 @@
launch_cvd_args.append(_AGREEMENT_PROMPT_ARG)
return launch_cvd_args
+ def _ArgSupportInLaunchCVD(self, arg):
+ """Check if the arg is supported in launch_cvd.
+
+ Args:
+ arg: String of the arg. e.g. "-config".
+
+ Returns:
+ True if this arg is supported. Otherwise False.
+ """
+ if arg in self._ssh.GetCmdOutput("./bin/launch_cvd --help"):
+ return True
+ return False
+
def StopCvd(self):
"""Stop CVD.
diff --git a/internal/lib/cvd_compute_client_multi_stage_test.py b/internal/lib/cvd_compute_client_multi_stage_test.py
index 6a882c8..4692666 100644
--- a/internal/lib/cvd_compute_client_multi_stage_test.py
+++ b/internal/lib/cvd_compute_client_multi_stage_test.py
@@ -85,6 +85,9 @@
self.Patch(cvd_compute_client_multi_stage.CvdComputeClient, "InitResourceHandle")
self.Patch(cvd_compute_client_multi_stage.CvdComputeClient, "_VerifyZoneByQuota",
return_value=True)
+ self.Patch(cvd_compute_client_multi_stage.CvdComputeClient,
+ "_ArgSupportInLaunchCVD",
+ return_value=True)
self.Patch(android_build_client.AndroidBuildClient, "InitResourceHandle")
self.Patch(android_build_client.AndroidBuildClient, "DownloadArtifact")
self.Patch(list_instances, "GetInstancesFromInstanceNames", return_value=mock.MagicMock())
@@ -264,6 +267,13 @@
self.assertEqual(self.cvd_compute_client_multi_stage.stage,
device_stage)
+ def testArgSupportInLaunchCVD(self):
+ """Test ArgSupportInLaunchCVD"""
+ self.Patch(Ssh, "GetCmdOutput", return_value="-config (Config)")
+ self.assertTrue(
+ self.cvd_compute_client_multi_stage._ArgSupportInLaunchCVD(
+ "-config"))
+
if __name__ == "__main__":
unittest.main()