download_from_google_storage: Fix tests and rename
the tests haven't been ran by presumbit for a while because of the plural in
the filename.
At some point some post "gsutil cp" file checking happened, which
broke the tests. This adds a callback to the fake gsutil cp so
that the expect file is copied over.
This also removes "gsutil version" checking from gsutil.py
and just assume that if the file exists, then it's good, which
should shave about 1-2s off of each gsutil.py call.
Bug: 772740,776311
Change-Id: I4fef62cfd46a849afed1f095dd6a96069376d13d
Reviewed-on: https://chromium-review.googlesource.com/707758
Commit-Queue: Ryan Tseng <hinoka@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
diff --git a/gsutil.py b/gsutil.py
index eb339bc..e8e9ca3 100755
--- a/gsutil.py
+++ b/gsutil.py
@@ -72,12 +72,6 @@
return target_filename
-def check_gsutil(gsutil_bin):
- """Run gsutil version and make sure it runs."""
- return subprocess.call(
- [sys.executable, gsutil_bin, 'version'],
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT) == 0
-
@contextlib.contextmanager
def temporary_directory(base):
tmpdir = tempfile.mkdtemp(prefix='gsutil_py', dir=base)
@@ -90,7 +84,10 @@
def ensure_gsutil(version, target, clean):
bin_dir = os.path.join(target, 'gsutil_%s' % version)
gsutil_bin = os.path.join(bin_dir, 'gsutil', 'gsutil')
- if not clean and os.path.isfile(gsutil_bin) and check_gsutil(gsutil_bin):
+ gsutil_flag = os.path.join(bin_dir, 'gsutil', 'install.flag')
+ # We assume that if gsutil_flag exists, then we have a good version
+ # of the gsutil package.
+ if not clean and os.path.isfile(gsutil_flag):
# Everything is awesome! we're all done here.
return gsutil_bin
@@ -116,10 +113,13 @@
except (OSError, IOError):
# Something else did this in parallel.
pass
+ # Final check that the gsutil bin exists. This should never fail.
+ if not os.path.isfile(gsutil_bin):
+ raise InvalidGsutilError()
+ # Drop a flag file.
+ with open(gsutil_flag, 'w') as f:
+ f.write('This flag file is dropped by gsutil.py')
- # Final check that the gsutil bin is okay. This should never fail.
- if not check_gsutil(gsutil_bin):
- raise InvalidGsutilError()
return gsutil_bin