[gsutil.py] Skip luci-auth wrapper on unsupported platforms

On unsupported platforms, luci-auth is not downloaded from CIPD and
hence the scripts relying on gsutil.py fail. Given we aren't using
luci-auth in unsupported platforms anyway, skip wrapping gsutil with
luci-auth on unsupported platforms.

Curently, only "aix" is added to the unsupported platforms list
eventhough we have other unsupported platforms too. This list will be
expanded if necessary.

R=yiwzhang

Change-Id: I70f6fceddc672c76bbea9a108a75b84662e26459
Fixed: 1467752
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4989412
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
changes/12/4989412/4
Aravind Vasudevan 1 year ago committed by LUCI CQ
parent 23c4defd8d
commit a413ee7249

@ -36,6 +36,10 @@ LUCI_AUTH_SCOPES = [
]
# Platforms unsupported by luci-auth.
LUCI_AUTH_UNSUPPORTED_PLATFORMS = ['aix']
class InvalidGsutilError(Exception):
pass
@ -154,6 +158,12 @@ def _is_luci_context():
return False
def _is_luci_auth_supported_platform():
"""Returns True if luci-auth is supported in the current platform."""
return not any(map(sys.platform.startswith,
LUCI_AUTH_UNSUPPORTED_PLATFORMS))
def luci_context(cmd):
"""Helper to call`luci-auth context`."""
p = _luci_auth_cmd('context', wrapped_cmds=cmd)
@ -264,8 +274,9 @@ def run_gsutil(target, args, clean=False):
_print_subprocess_result(p)
return p.returncode
# Skip wrapping commands if luci-auth is already being
if _is_luci_context():
# Skip wrapping commands if luci-auth is already being used or if the
# platform is unsupported by luci-auth.
if _is_luci_context() or not _is_luci_auth_supported_platform():
return _run_subprocess(cmd, interactive=True).returncode
# Wrap gsutil with luci-auth context.

@ -16,6 +16,7 @@ import tempfile
import unittest
import zipfile
import urllib.request
from unittest import mock
# Add depot_tools to path
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
@ -147,5 +148,15 @@ class GsutilUnitTests(unittest.TestCase):
gsutil_bin)
@mock.patch('sys.platform', 'linux')
def test__is_supported_platform_returns_true_for_supported_platform(self):
self.assertTrue(gsutil._is_luci_auth_supported_platform())
@mock.patch('sys.platform', 'aix')
def test__is_supported_platform_returns_false_for_unsupported_platform(
self):
self.assertFalse(gsutil._is_luci_auth_supported_platform())
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save