Merge "Correct the error type in the report for goldfish AVD type." am: 5ce06f5233

Original change: https://android-review.googlesource.com/c/platform/tools/acloud/+/1560474

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I2724724a85a6791514785ecd85cb4f354efc58da
diff --git a/errors.py b/errors.py
index fc6a084..5b6d249 100644
--- a/errors.py
+++ b/errors.py
@@ -41,7 +41,7 @@
 
     def __init__(self, code, message):
         self.code = code
-        super(HttpError, self).__init__(message)
+        super().__init__(message)
 
     @staticmethod
     def CreateFromHttpError(http_error):
@@ -83,6 +83,10 @@
     """To catch device boot errors."""
 
 
+class DownloadArtifactError(DriverError):
+    """To catch download artifact errors."""
+
+
 class NoSubnetwork(DriverError):
     """When there is no subnetwork for the GCE."""
 
diff --git a/internal/lib/goldfish_compute_client.py b/internal/lib/goldfish_compute_client.py
index d868403..5571206 100644
--- a/internal/lib/goldfish_compute_client.py
+++ b/internal/lib/goldfish_compute_client.py
@@ -107,15 +107,16 @@
             instance: String
 
         Raises:
-            Raises an errors.DeviceBootError exception if a failure is detected.
+            errors.DownloadArtifactError: If it fails to download artifact.
+            errors.DeviceBootError: If it fails to boot up.
         """
         if self.BOOT_FAILED_MSG in serial_out:
             if self.EMULATOR_FETCH_FAILED_MSG in serial_out:
-                raise errors.DeviceBootError(
+                raise errors.DownloadArtifactError(
                     "Failed to download emulator build. Re-run with a newer build."
                 )
             if self.ANDROID_FETCH_FAILED_MSG in serial_out:
-                raise errors.DeviceBootError(
+                raise errors.DownloadArtifactError(
                     "Failed to download system image build. Re-run with a newer build."
                 )
             if self.BOOT_TIMEOUT_MSG in serial_out:
diff --git a/public/actions/common_operations.py b/public/actions/common_operations.py
index 6f60dca..9c50646 100644
--- a/public/actions/common_operations.py
+++ b/public/actions/common_operations.py
@@ -32,14 +32,16 @@
 
 
 logger = logging.getLogger(__name__)
+_ACLOUD_BOOT_UP_ERROR = "ACLOUD_BOOT_UP_ERROR"
+_ACLOUD_DOWNLOAD_ARTIFACT_ERROR = "ACLOUD_DOWNLOAD_ARTIFACT_ERROR"
+# Error type of GCE quota error.
+_GCE_QUOTA_ERROR = "GCE_QUOTA_ERROR"
 _DICT_ERROR_TYPE = {
     constants.STAGE_INIT: "ACLOUD_INIT_ERROR",
     constants.STAGE_GCE: "ACLOUD_CREATE_GCE_ERROR",
-    constants.STAGE_ARTIFACT: "ACLOUD_DOWNLOAD_ARTIFACT_ERROR",
-    constants.STAGE_BOOT_UP: "ACLOUD_BOOT_UP_ERROR",
+    constants.STAGE_ARTIFACT: _ACLOUD_DOWNLOAD_ARTIFACT_ERROR,
+    constants.STAGE_BOOT_UP: _ACLOUD_BOOT_UP_ERROR,
 }
-# Error type of GCE quota error.
-_GCE_QUOTA_ERROR = "GCE_QUOTA_ERROR"
 
 
 def CreateSshKeyPairIfNecessary(cfg):
@@ -274,7 +276,9 @@
                     ssh_user=constants.GCE_USER,
                     extra_args_ssh_tunnel=cfg.extra_args_ssh_tunnel)
             if device.instance_name in failures:
-                reporter.SetErrorType(_DICT_ERROR_TYPE[device.stage])
+                reporter.SetErrorType(_ACLOUD_BOOT_UP_ERROR)
+                if device.stage:
+                    reporter.SetErrorType(_DICT_ERROR_TYPE[device.stage])
                 reporter.AddData(key="devices_failing_boot", value=device_dict)
                 reporter.AddError(str(failures[device.instance_name]))
             else:
@@ -282,6 +286,8 @@
     except (errors.DriverError, errors.CheckGCEZonesQuotaError) as e:
         if isinstance(e, errors.CheckGCEZonesQuotaError):
             reporter.SetErrorType(_GCE_QUOTA_ERROR)
+        if isinstance(e, errors.DownloadArtifactError):
+            reporter.SetErrorType(_ACLOUD_DOWNLOAD_ARTIFACT_ERROR)
         reporter.AddError(str(e))
         reporter.SetStatus(report.Status.FAIL)
     return reporter