build_telemetry: Set timeout to 'cipd auth-info' command.

When it's offline or the internet connection is unstable,
build_telemetry.enabled() may fail, which end up with
blocking autoninja command.

Bug: 364611323
Change-Id: Ie0d26e7b950e29af1392e452a0cd7e986494cdcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5842066
Auto-Submit: Junji Watanabe <jwata@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
Reviewed-by: Philipp Wollermann <philwo@google.com>
changes/66/5842066/6
Junji Watanabe 6 months ago committed by LUCI CQ
parent 4250face7b
commit 28edf94b2b

@ -149,17 +149,19 @@ def load_config(cfg_path=_DEFAULT_CONFIG_PATH, countdown=_DEFAULT_COUNTDOWN):
def check_auth():
"""Checks auth information."""
p = subprocess.run(
"cipd auth-info --json-output -",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
shell=True,
)
if p.returncode != 0:
try:
out = subprocess.check_output(
"cipd auth-info --json-output -",
text=True,
shell=True,
timeout=3,
)
except Exception as e:
print("WARNING: depot_tools.build_telemetry: "
f"failed to get auth info: {e}")
return {}
try:
return json.loads(p.stdout)
return json.loads(out)
except json.JSONDecodeError as e:
logging.error(e)
return {}

@ -5,6 +5,7 @@
import json
import os
import subprocess
import sys
import tempfile
import unittest
@ -19,19 +20,18 @@ import build_telemetry
class BuildTelemetryTest(unittest.TestCase):
def test_check_auth(self):
with unittest.mock.patch('subprocess.run') as run_mock:
run_mock.return_value.returncode = 0
with unittest.mock.patch('subprocess.check_output') as run_mock:
auth = {'email': 'bob@google.com'}
run_mock.return_value.stdout = json.dumps(auth)
run_mock.return_value = json.dumps(auth)
self.assertEqual(build_telemetry.check_auth(), auth)
with unittest.mock.patch('subprocess.run') as run_mock:
run_mock.return_value.returncode = 1
with unittest.mock.patch('subprocess.check_output') as run_mock:
run_mock.side_effect = subprocess.CalledProcessError(
1, cmd=['check auth'], stderr='failed')
self.assertEqual(build_telemetry.check_auth(), {})
with unittest.mock.patch('subprocess.run') as run_mock:
run_mock.return_value.returncode = 0
run_mock.return_value.stdout = ''
with unittest.mock.patch('subprocess.check_output') as run_mock:
run_mock.return_value = ''
self.assertEqual(build_telemetry.check_auth(), {})
def test_load_and_save_config(self):

Loading…
Cancel
Save