diff options
author | Caroline Tice <cmtice@google.com> | 2015-12-08 11:35:42 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-12-11 00:46:50 +0000 |
commit | 25cc6609029758944641f58c4ba8189bbbf717ff (patch) | |
tree | b83419bd16704a87ac7421af4bcf1b95255bc59a /crosperf/download_images.py | |
parent | 93950177ce54e64d29b3d4793f0a37cc4b0b4cde (diff) | |
download | toolchain-utils-25cc6609029758944641f58c4ba8189bbbf717ff.tar.gz |
Improve error message when crosperf can't find image to download.
Currently if crosperf tries to download an image from
gs://chromeos-image-archive, it fails with a very cryptic message
that does NOT indicate what really went wrong. This CL makes
crosperf look for the image before attempting to download it, and
fixes the error messages to make sure they reflect the actual
problem. It also has some minor formatting fixes.
BUG=chromium:533526
TEST=Tested with both existing and non-existing image names.
Change-Id: Ic2f5e4f25f7d63c130895dd4cb078164a370f081
Reviewed-on: https://chrome-internal-review.googlesource.com/241057
Commit-Ready: Caroline Tice <cmtice@google.com>
Tested-by: Caroline Tice <cmtice@google.com>
Reviewed-by: Caroline Tice <cmtice@google.com>
Diffstat (limited to 'crosperf/download_images.py')
-rw-r--r-- | crosperf/download_images.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/crosperf/download_images.py b/crosperf/download_images.py index 9fe94fc8..e3951b99 100644 --- a/crosperf/download_images.py +++ b/crosperf/download_images.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# Copyright (c) 2014 The Chromium OS Authors. All rights reserved. +# Copyright (c) 2014, 2015 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -9,6 +9,9 @@ import os from utils import command_executer +class MissingImage(Exception): + """Raised when the requested image does not exist in gs://""" + class ImageDownloader(object): def __init__(self, logger_to_use=None, log_level="verbose", @@ -25,14 +28,18 @@ class ImageDownloader(object): "python translate_xbuddy.py '%s'" % xbuddy_label) retval, build_id_tuple_str, _ = self._ce.ChrootRunCommand(chromeos_root, command, True) + if not build_id_tuple_str: + raise MissingImage ("Unable to find image for '%s'" % xbuddy_label) + build_id_tuple = ast.literal_eval(build_id_tuple_str) build_id = build_id_tuple[0] return build_id - def _DownloadImage(self, chromeos_root, build_id): + def _DownloadImage(self, chromeos_root, build_id, image_name): if self.log_level == "average": - self._logger.LogOutput ("Preparing to download %s image to local directory." % build_id) + self._logger.LogOutput ("Preparing to download %s image to local " + "directory." % build_id) # Make sure the directory for downloading the image exists. download_path = os.path.join(chromeos_root, "chroot/tmp", @@ -45,9 +52,7 @@ class ImageDownloader(object): # download the image. status = 0 if not os.path.exists(image_path): - command = ("gsutil cp gs://chromeos-image-archive/%s" - "/chromiumos_test_image.tar.xz /tmp/%s" % (build_id, - build_id)) + command = "gsutil cp %s /tmp/%s" % (image_name, build_id) if self.log_level != "verbose": self._logger.LogOutput ("CMD: %s" % command) @@ -77,10 +82,17 @@ class ImageDownloader(object): def Run(self, chromeos_root, xbuddy_label): build_id = self._GetBuildID(chromeos_root, xbuddy_label) - - + image_name = ("gs://chromeos-image-archive/%s/chromiumos_test_image.tar.xz" + % build_id) + + # Verify that image exists for build_id, before attempting to + # download it. + cmd = "gsutil ls %s" % image_name + status = self._ce.ChrootRunCommand(chromeos_root, cmd) + if status != 0: + raise MissingImage("Cannot find official image: %s." % image_name) + image_path = self._DownloadImage(chromeos_root, build_id, image_name) retval = 0 - image_path = self._DownloadImage(chromeos_root, build_id) if image_path: retval = self._UncompressImage(chromeos_root, build_id) else: |