Allow passing target image name to ImageExtractor

When generating the delta payload, we use ImageExtractor to extract
the latest image and use the image as a base to generate the delta
payload. Because ImageExtractor always assumes that the image to
extract is a test image ('chromiumos_test_image.bin'), we are unable
to generate the delta payload for non-test images. This needs to be
changed because there are builders (e.g. beaglebone) which do not
produces test images. This CL passes the target image name to
ImageExtractor so that a correct type of image can be used.

BUG=chromium:326632
TEST=unittest

Change-Id: Ibb347b4cccbf55079bc719200278dac74e0ab87f
Reviewed-on: https://chromium-review.googlesource.com/179085
Reviewed-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Yu-Ju Hong <yjhong@chromium.org>
Commit-Queue: Yu-Ju Hong <yjhong@chromium.org>
Tested-by: Yu-Ju Hong <yjhong@chromium.org>
diff --git a/generate_test_payloads/cros_generate_test_payloads.py b/generate_test_payloads/cros_generate_test_payloads.py
index 4703ef1..538d76f 100755
--- a/generate_test_payloads/cros_generate_test_payloads.py
+++ b/generate_test_payloads/cros_generate_test_payloads.py
@@ -393,7 +393,8 @@
   target_version = os.path.realpath(options.target).rsplit('/', 2)[-2]
   if options.base_latest_from_dir:
     # Extract the latest build.
-    extractor = image_extractor.ImageExtractor(options.base_latest_from_dir)
+    extractor = image_extractor.ImageExtractor(options.base_latest_from_dir,
+                                               os.path.basename(options.target))
     latest_image_dir = extractor.GetLatestImage(target_version)
     if latest_image_dir:
       options.base = extractor.UnzipImage(latest_image_dir)
diff --git a/lib/image_extractor.py b/lib/image_extractor.py
index 93a58eb..a3596e2 100644
--- a/lib/image_extractor.py
+++ b/lib/image_extractor.py
@@ -15,15 +15,18 @@
 
 class ImageExtractor(object):
   """Class used to get the latest image for the board."""
-  # The image we want to test.
+  # The default image to extract.
   IMAGE_TO_EXTRACT = 'chromiumos_test_image.bin'
   # Archive directory in the src tree to keep latest archived image after
   # we've unzipped them.
   SRC_ARCHIVE_DIR = 'latest_image'
 
-  def __init__(self, archive_dir):
+  def __init__(self, archive_dir, image_to_extract=None):
     """Initializes a extractor for the archive_dir."""
     self.archive = archive_dir
+    if not image_to_extract:
+      image_to_extract = self.IMAGE_TO_EXTRACT
+    self.image_to_extract = image_to_extract
 
   def GetLatestImage(self, target_version):
     """Gets the last image archived for the board.
@@ -69,7 +72,7 @@
     version_string = os.path.basename(image_dir)
     cached_dir = os.path.join(ImageExtractor.SRC_ARCHIVE_DIR, version_string)
     cached_image = os.path.abspath(os.path.join(
-        cached_dir, ImageExtractor.IMAGE_TO_EXTRACT))
+        cached_dir, self.image_to_extract))
     # If we previously unzipped the image, we're done.
     if os.path.exists(cached_image):
       logging.info('Re-using image with version %s that we previously '