aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsin-Yi Chen <hsinyichen@google.com>2024-03-18 15:35:20 +0800
committerHsin-Yi Chen <hsinyichen@google.com>2024-03-22 02:40:45 +0000
commitcfaa7cee8bfd5d219533c356b39aceb6fa388c1e (patch)
tree61aa17207b7feae87c93256c6595066577c6e38b
parentea96e49bb5d6eea7df173d44823a07b13f3b0418 (diff)
downloadacloud-cfaa7cee8bfd5d219533c356b39aceb6fa388c1e.tar.gz
Report the errors raised by _ProcessRemoteHostArtifacts
Test: acloud-dev create -vv --local-image ~/target_files.zip \ --cvd-host-package ~/cvd-host_package.tar.gz \ --local-system-image ~/system.img \ --host 192.168.9.2 --host-user vsoc-01 \ --host-ssh-private-key-path ~/id_rsa \ --remote-image-dir img Bug: 293966645 Change-Id: I722ed5c05b250e645eb99512e64d5e1a8f7a17f4
-rw-r--r--public/actions/remote_host_cf_device_factory.py23
-rw-r--r--public/actions/remote_host_cf_device_factory_test.py27
2 files changed, 44 insertions, 6 deletions
diff --git a/public/actions/remote_host_cf_device_factory.py b/public/actions/remote_host_cf_device_factory.py
index d052ae5b..0f76f42e 100644
--- a/public/actions/remote_host_cf_device_factory.py
+++ b/public/actions/remote_host_cf_device_factory.py
@@ -100,10 +100,18 @@ class RemoteHostDeviceFactory(base_device_factory.BaseDeviceFactory):
deadline = start_time + (self._avd_spec.boot_timeout_secs or
constants.DEFAULT_CF_BOOT_TIMEOUT)
self._compute_client.SetStage(constants.STAGE_ARTIFACT)
- # TODO(b/293966645): Handle errors.CreateError.
- image_args = self._ProcessRemoteHostArtifacts(deadline)
- start_time = self._compute_client.RecordTime(
- constants.TIME_ARTIFACT, start_time)
+ try:
+ image_args = self._ProcessRemoteHostArtifacts(deadline)
+ except (errors.CreateError, errors.DriverError,
+ subprocess.CalledProcessError) as e:
+ logger.exception("Fail to prepare artifacts.")
+ self._all_failures[instance] = str(e)
+ # If an SSH error or timeout happens, report the name for the
+ # caller to clean up this instance.
+ return instance
+ finally:
+ start_time = self._compute_client.RecordTime(
+ constants.TIME_ARTIFACT, start_time)
self._compute_client.SetStage(constants.STAGE_BOOT_UP)
error_msg = self._LaunchCvd(image_args, deadline)
@@ -464,11 +472,14 @@ class RemoteHostDeviceFactory(base_device_factory.BaseDeviceFactory):
Returns:
A list of string pairs, the replaced arguments.
+
+ Raises:
+ errors.CreateError if any path cannot be replaced.
"""
if any(remote_path.isabs(path) != remote_path.isabs(old_dir) for
_, path in launch_cvd_args):
- raise ValueError(f"Cannot convert {launch_cvd_args} to relative "
- f"paths under {old_dir}")
+ raise errors.CreateError(f"Cannot convert {launch_cvd_args} to "
+ f"relative paths under {old_dir}")
return [(option,
remote_path.join(new_dir, remote_path.relpath(path, old_dir)))
for option, path in launch_cvd_args]
diff --git a/public/actions/remote_host_cf_device_factory_test.py b/public/actions/remote_host_cf_device_factory_test.py
index a972e1fe..76b8022d 100644
--- a/public/actions/remote_host_cf_device_factory_test.py
+++ b/public/actions/remote_host_cf_device_factory_test.py
@@ -18,10 +18,12 @@ import time
import unittest
from unittest import mock
+from acloud import errors
from acloud.internal import constants
from acloud.internal.lib import driver_test_lib
from acloud.public.actions import remote_host_cf_device_factory
+
class RemoteHostDeviceFactoryTest(driver_test_lib.BaseDriverTest):
"""Test RemoteHostDeviceFactory."""
@@ -445,6 +447,31 @@ class RemoteHostDeviceFactoryTest(driver_test_lib.BaseDriverTest):
self.assertEqual(["arg", "acloud_cf_1/2"],
mock_cvd_utils.GetRemoteLaunchCvdCmd.call_args[0][3])
+ @mock.patch("acloud.public.actions.remote_host_cf_device_factory.ssh")
+ @mock.patch("acloud.public.actions.remote_host_cf_device_factory."
+ "cvd_utils")
+ @mock.patch("acloud.public.actions.remote_host_cf_device_factory."
+ "subprocess.check_call")
+ def testCreateInstanceWithCreateError(self, _mock_check_call,
+ mock_cvd_utils, mock_ssh):
+ """Test CreateInstance with CreateError."""
+ mock_avd_spec = self._CreateMockAvdSpec()
+ mock_avd_spec.remote_image_dir = "mock_img_dir"
+
+ mock_ssh_obj = mock.Mock()
+ mock_ssh.Ssh.return_value = mock_ssh_obj
+
+ mock_cvd_utils.GetRemoteHostBaseDir.return_value = "acloud_cf_1"
+ mock_cvd_utils.FormatRemoteHostInstanceName.return_value = "inst"
+ mock_cvd_utils.LoadRemoteImageArgs.side_effect = errors.CreateError(
+ "failure")
+ factory = remote_host_cf_device_factory.RemoteHostDeviceFactory(
+ mock_avd_spec)
+
+ self.assertEqual("inst", factory.CreateInstance())
+ self.assertEqual({"inst": "failure"}, factory.GetFailures())
+ mock_cvd_utils.ExecuteRemoteLaunchCvd.assert_not_called()
+
if __name__ == "__main__":
unittest.main()