Index: tools/telemetry/telemetry/page/cloud_storage.py |
diff --git a/tools/telemetry/telemetry/page/cloud_storage.py b/tools/telemetry/telemetry/page/cloud_storage.py |
index 2c5478574871bbe7e607a3d3266e44f93cc11c60..78f7db2bc247b84201b5952257bae927674b9d4b 100644 |
--- a/tools/telemetry/telemetry/page/cloud_storage.py |
+++ b/tools/telemetry/telemetry/page/cloud_storage.py |
@@ -13,6 +13,7 @@ import sys |
import tarfile |
import urllib2 |
+from telemetry.core.backends.chrome import cros_interface |
from telemetry.core import util |
@@ -23,7 +24,9 @@ INTERNAL_BUCKET = 'chrome-telemetry' |
_GSUTIL_URL = 'http://storage.googleapis.com/pub/gsutil.tar.gz' |
_DOWNLOAD_PATH = os.path.join(util.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 |
@@ -31,6 +34,8 @@ class CloudStorageError(Exception): |
if SupportsProdaccess(gsutil_path) and _FindExecutableInPath('prodaccess'): |
return 'Run prodaccess to authenticate.' |
else: |
+ if cros_interface.IsRunningOnCrosDevice(): |
+ gsutil_path = ('HOME=%s %s' % (_CROS_GSUTIL_HOME_WAR, gsutil_path)) |
return ('To configure your credentials:\n' |
' 1. Run "%s config" and follow its instructions.\n' |
' 2. If you have a @google.com account, use that account.\n' |
@@ -99,8 +104,21 @@ def SupportsProdaccess(gsutil_path): |
def _RunCommand(args): |
gsutil_path = FindGsutil() |
+ # On cros device, as telemetry is running as root, home will be set to /root/, |
+ # which is not writable. gsutil will attempt to create a download tracker dir |
+ # in home dir and fail. To avoid this, override HOME dir to something writable |
+ # when running on cros device. |
+ # |
+ # TODO(tbarzic): Figure out a better way to handle gsutil on cros. |
+ # http://crbug.com/386416, http://crbug.com/359293. |
+ gsutil_env = None |
+ if cros_interface.IsRunningOnCrosDevice(): |
+ gsutil_env = os.environ.copy() |
+ gsutil_env['HOME'] = _CROS_GSUTIL_HOME_WAR |
+ |
gsutil = subprocess.Popen([sys.executable, gsutil_path] + args, |
- stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
+ env=gsutil_env) |
stdout, stderr = gsutil.communicate() |
if gsutil.returncode: |
@@ -110,7 +128,8 @@ def _RunCommand(args): |
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: |
+ if (stderr.startswith('InvalidUriError') or 'No such object' in stderr or |
+ 'No URLs matched' in stderr): |
raise NotFoundError(stderr) |
raise CloudStorageError(stderr) |