Merge "Add "kernel" into artifact files for acloud create." am: 49255c0bfd

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6b8aaf93e81b8079831696a3591448aa61b926f2
diff --git a/public/actions/remote_instance_cf_device_factory.py b/public/actions/remote_instance_cf_device_factory.py
index 786a49f..cfd36aa 100644
--- a/public/actions/remote_instance_cf_device_factory.py
+++ b/public/actions/remote_instance_cf_device_factory.py
@@ -31,8 +31,10 @@
 
 
 logger = logging.getLogger(__name__)
-# bootloader is one file required to launch AVD.
+# bootloader and kernel are files required to launch AVD.
 _BOOTLOADER = "bootloader"
+_KERNEL = "kernel"
+_ARTIFACT_FILES = ["*.img", _BOOTLOADER, _KERNEL]
 _HOME_FOLDER = os.path.expanduser("~")
 
 
@@ -52,7 +54,7 @@
     """
     def __init__(self, avd_spec, local_image_artifact=None,
                  cvd_host_package_artifact=None):
-        super(RemoteInstanceDeviceFactory, self).__init__(avd_spec, local_image_artifact)
+        super().__init__(avd_spec, local_image_artifact)
         self._cvd_host_package_artifact = cvd_host_package_artifact
 
     # pylint: disable=broad-except
@@ -279,10 +281,11 @@
             except IOError:
                 # Older builds may not have a required_images file. In this case
                 # we fall back to *.img.
-                artifact_files = [
-                    os.path.basename(image) for image in
-                    glob.glob(os.path.join(images_dir, "*.img"))]
-                artifact_files.append(_BOOTLOADER)
+                artifact_files = []
+                for file_name in _ARTIFACT_FILES:
+                    artifact_files.extend(
+                        os.path.basename(image) for image in glob.glob(
+                            os.path.join(images_dir, file_name)))
             cmd = ("tar -cf - --lzop -S -C {images_dir} {artifact_files} | "
                    "{ssh_cmd} -- tar -xf - --lzop -S".format(
                        images_dir=images_dir,
diff --git a/public/actions/remote_instance_cf_device_factory_test.py b/public/actions/remote_instance_cf_device_factory_test.py
index 12a9e30..34dd875 100644
--- a/public/actions/remote_instance_cf_device_factory_test.py
+++ b/public/actions/remote_instance_cf_device_factory_test.py
@@ -288,10 +288,10 @@
 
         # Test local image get from local folder case.
         fake_image = None
-        self.Patch(glob, "glob", return_value=["fake.img"])
+        self.Patch(glob, "glob", side_effect=[["fake.img"], ["bootloader"], ["kernel"]])
         factory._UploadArtifacts(fake_image, fake_host_package, fake_local_image_dir)
         expected_cmd = (
-            "tar -cf - --lzop -S -C %s fake.img bootloader | "
+            "tar -cf - --lzop -S -C %s fake.img bootloader kernel | "
             "%s -- tar -xf - --lzop -S" %
             (fake_local_image_dir, factory._ssh.GetBaseCmd(constants.SSH_BIN)))
         mock_shell.assert_called_once_with(expected_cmd)