Assorted bugs to get AU E2E test working with paygen suite.
1) Fixed a bug from a previous CL introduced that returned from an omaha
ping before we processed it for remote info (autoupdate.py)
2) If we expect a single item returned from gsutil but get multiple,
if the name we gave matches one exactly, return that.
BUG=chromium:267896
TEST=Ran it with unittests + AU E2E test with paygen test.
Change-Id: Ifd1266d9050824ad397df3bf80a1d314f01610db
Reviewed-on: https://gerrit.chromium.org/gerrit/66140
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Joy Chen <joychen@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
diff --git a/gsutil_util.py b/gsutil_util.py
index 8373047..a6e2324 100644
--- a/gsutil_util.py
+++ b/gsutil_util.py
@@ -5,6 +5,7 @@
"""Module containing gsutil helper methods."""
import distutils.version
+import logging
import random
import re
import subprocess
@@ -106,7 +107,9 @@
pattern: Regular expression pattern to identify the target artifact.
archive_url: URL of the Google Storage bucket.
err_str: String to display in the error message on error.
- single_item: Only a single item should be returned.
+ single_item: Only a single item should be returned. If more than one item
+ matches the pattern errors out unless pattern matches one
+ exactly.
timeout/delay: optional and self-explanatory.
Returns:
@@ -139,9 +142,15 @@
found_names = _GetGSNamesFromList(uploaded_list, pattern)
if found_names:
if single_item and len(found_names) > 1:
- raise PatternNotSpecific(
+ found_names_exact = _GetGSNamesFromList(uploaded_list, '^%s$' % pattern)
+ if not found_names_exact:
+ raise PatternNotSpecific(
'Too many items %s returned by pattern %s in %s' % (
str(found_names), pattern, archive_url))
+ else:
+ logging.info('More than one item returned but one file matched'
+ ' exactly so returning that: %s.', found_names_exact)
+ found_names = found_names_exact
return found_names