Commit b36040c3 authored by tbarzic@chromium.org's avatar tbarzic@chromium.org

Override HOME dir for gsutil when running on cros device

Gsutil tries to create a dir (for keeping track of resumable downloads)
under home dir. On ChromeOS this is, given that the tests must be run
by root, read-only '/root/'. This causes gsutil commands to fail. To
avoid this, override HOME dir to writable '/home/chromeos-test'.

(this will also require gsuitl to be configured with the same HOME dir)

BUG=359293,386416

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278329 0039d316-1c4b-4281-b951-d872f2087c98
parent f404bdd1
......@@ -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)
......
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