Commit 4ad23a40 authored by dtu's avatar dtu Committed by Commit bot

[telemetry] Use consistent bucket naming.

Also catch 401 errors.

BUG=None.
TEST=None.

Review URL: https://codereview.chromium.org/556003002

Cr-Commit-Position: refs/heads/master@{#294921}
parent 772b3352
......@@ -82,17 +82,15 @@ def _SyncFilesToCloud(input_api, output_api):
continue
try:
bucket_input = raw_input('Uploading to Cloud Storage: %s\n'
'Is this file [P]ublic or Google-[i]nternal?'
% file_path).lower()
if 'public'.startswith(bucket_input):
bucket = cloud_storage.PUBLIC_BUCKET
elif ('internal'.startswith(bucket_input) or
'google-internal'.startswith(bucket_input)):
bucket = cloud_storage.INTERNAL_BUCKET
else:
bucket_aliases_string = ', '.join(cloud_storage.BUCKET_ALIASES)
bucket_input = raw_input(
'Uploading to Cloud Storage: %s\n'
'Which bucket should this go in? (%s) '
% (file_path, bucket_aliases_string)).lower()
bucket = cloud_storage.BUCKET_ALIASES.get(bucket_input, None)
if not bucket:
results.append(output_api.PresubmitError(
'Response was neither "public" nor "internal": %s' % bucket_input))
'"%s" was not one of %s' % (bucket_input, bucket_aliases_string)))
return results
cloud_storage.Insert(bucket, file_hash, file_path)
......
......@@ -13,13 +13,8 @@ from telemetry.core import command_line
from telemetry.util import cloud_storage
BUCKET_ALIASES = {
'public': cloud_storage.PUBLIC_BUCKET,
'partner': cloud_storage.PARTNER_BUCKET,
'google-only': cloud_storage.INTERNAL_BUCKET,
}
BUCKETS = {bucket: easy_bucket_name for easy_bucket_name, bucket
in BUCKET_ALIASES.iteritems()}
in cloud_storage.BUCKET_ALIASES.iteritems()}
def _GetPaths(path):
......@@ -116,11 +111,11 @@ class Mv(command_line.Command):
@classmethod
def AddCommandLineArgs(cls, parser):
parser.add_argument('files', nargs='+')
parser.add_argument('bucket', choices=BUCKET_ALIASES)
parser.add_argument('bucket', choices=cloud_storage.BUCKET_ALIASES)
@classmethod
def ProcessCommandLineArgs(cls, parser, args):
args.bucket = BUCKET_ALIASES[args.bucket]
args.bucket = cloud_storage.BUCKET_ALIASES[args.bucket]
def Run(self, args):
files = _FindFilesInCloudStorage(args.files)
......@@ -166,11 +161,11 @@ class Upload(command_line.Command):
@classmethod
def AddCommandLineArgs(cls, parser):
parser.add_argument('files', nargs='+')
parser.add_argument('bucket', choices=BUCKET_ALIASES)
parser.add_argument('bucket', choices=cloud_storage.BUCKET_ALIASES)
@classmethod
def ProcessCommandLineArgs(cls, parser, args):
args.bucket = BUCKET_ALIASES[args.bucket]
args.bucket = cloud_storage.BUCKET_ALIASES[args.bucket]
for path in args.files:
if not os.path.exists(path):
......
......@@ -23,28 +23,16 @@ class PageSetArchiveInfo(object):
# Download all .wpr files.
if not ignore_archive:
# TODO(tbarzic): Remove this once http://crbug.com/351143 is diagnosed.
log_cloud_storage_exception = True
for archive_path in data['archives']:
archive_path = self._WprFileNameToPath(archive_path)
try:
cloud_storage.GetIfChanged(archive_path)
except (cloud_storage.CredentialsError,
cloud_storage.PermissionError) as e:
except (cloud_storage.CredentialsError, cloud_storage.PermissionError):
if os.path.exists(archive_path):
# If the archive exists, assume the user recorded their own and
# simply warn.
logging.warning('Need credentials to update WPR archive: %s',
archive_path)
elif log_cloud_storage_exception:
# Log access errors only once, as they should stay the same in other
# iterations.
log_cloud_storage_exception = False
logging.warning('Error getting WPR archive %s: %s ' %
(archive_path, str(e)))
logging.info(
'HOME: "%s"; USER: "%s"' %
(os.environ.get('HOME', ''), os.environ.get('USER', '')))
# Map from the relative path (as it appears in the metadata file) of the
# .wpr file to a list of page names it supports.
......@@ -66,8 +54,6 @@ class PageSetArchiveInfo(object):
with open(file_path, 'r') as f:
data = json.load(f)
return cls(file_path, data, ignore_archive=ignore_archive)
# TODO(tbarzic): Remove this once http://crbug.com/351143 is diagnosed.
logging.warning('Page set archives not found: %s' % file_path)
return cls(file_path, {'archives': {}}, ignore_archive=ignore_archive)
def WprFilePathForPage(self, page):
......
......@@ -123,8 +123,14 @@ class AdbCommandsModuleStub(object):
class CloudStorageModuleStub(object):
INTERNAL_BUCKET = None
PUBLIC_BUCKET = None
PUBLIC_BUCKET = 'chromium-telemetry'
PARTNER_BUCKET = 'chrome-partner-telemetry'
INTERNAL_BUCKET = 'chrome-telemetry'
BUCKET_ALIASES = {
'public': PUBLIC_BUCKET,
'partner': PARTNER_BUCKET,
'internal': INTERNAL_BUCKET,
}
class CloudStorageError(Exception):
pass
......
......@@ -17,17 +17,26 @@ import urllib2
from telemetry.core import platform
from telemetry.util import path
PUBLIC_BUCKET = 'chromium-telemetry'
PARTNER_BUCKET = 'chrome-partner-telemetry'
INTERNAL_BUCKET = 'chrome-telemetry'
BUCKET_ALIASES = {
'public': PUBLIC_BUCKET,
'partner': PARTNER_BUCKET,
'internal': INTERNAL_BUCKET,
}
_GSUTIL_URL = 'http://storage.googleapis.com/pub/gsutil.tar.gz'
_DOWNLOAD_PATH = os.path.join(path.GetTelemetryDir(), 'third_party', 'gsutil')
# TODO(tbarzic): A workaround for http://crbug.com/386416 and
# http://crbug.com/359293. See |_RunCommand|.
_CROS_GSUTIL_HOME_WAR = '/home/chromeos-test/'
class CloudStorageError(Exception):
@staticmethod
def _GetConfigInstructions(gsutil_path):
......@@ -127,6 +136,8 @@ def _RunCommand(args):
'You are attempting to access protected data with no configured',
'Failure: No handler was ready to authenticate.')):
raise CredentialsError(gsutil_path)
if 'status=401' in stderr or 'status 401' in stderr:
raise CredentialsError(gsutil_path)
if 'status=403' in stderr or 'status 403' in stderr:
raise PermissionError(gsutil_path)
if (stderr.startswith('InvalidUriError') or 'No such object' in stderr or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment