From a413ee724986d0ebc146f7dba253d031d5cfc4e5 Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Wed, 1 Nov 2023 22:19:25 +0000 Subject: [PATCH] [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 Auto-Submit: Aravind Vasudevan Commit-Queue: Aravind Vasudevan --- gsutil.py | 15 +++++++++++++-- tests/gsutil_test.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gsutil.py b/gsutil.py index 4dcb2d617..353476068 100755 --- a/gsutil.py +++ b/gsutil.py @@ -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. diff --git a/tests/gsutil_test.py b/tests/gsutil_test.py index 39e09187e..1c79bb8ee 100755 --- a/tests/gsutil_test.py +++ b/tests/gsutil_test.py @@ -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()