Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Merge 216c7c9 into bb2386e
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Jul 27, 2016
2 parents bb2386e + 216c7c9 commit ead74c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion oauth2client/client.py
Expand Up @@ -102,6 +102,14 @@
# If set to True _get_environment avoid GCE check (_detect_gce_environment)
NO_GCE_CHECK = os.environ.setdefault('NO_GCE_CHECK', 'False')

# Timeout in seconds to wait for the GCE metadata server when detecting the
# GCE environment.
try:
GCE_METADATA_TIMEOUT = int(
os.environ.setdefault('GCE_METADATA_TIMEOUT', '3'))
except ValueError: # pragma: NO COVER
GCE_METADATA_TIMEOUT = 3

_SERVER_SOFTWARE = 'SERVER_SOFTWARE'
_GCE_METADATA_HOST = '169.254.169.254'
_METADATA_FLAVOR_HEADER = 'Metadata-Flavor'
Expand Down Expand Up @@ -998,7 +1006,7 @@ def _detect_gce_environment():
# the metadata resolution was particularly slow. The latter case is
# "unlikely".
connection = six.moves.http_client.HTTPConnection(
_GCE_METADATA_HOST, timeout=1)
_GCE_METADATA_HOST, timeout=GCE_METADATA_TIMEOUT)

try:
headers = {_METADATA_FLAVOR_HEADER: _DESIRED_METADATA_FLAVOR}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_client.py
Expand Up @@ -399,7 +399,8 @@ def _environment_check_gce_helper(self, status_ok=True, socket_error=False,

if server_software == '':
http_client_module.HTTPConnection.assert_called_once_with(
client._GCE_METADATA_HOST, timeout=1)
client._GCE_METADATA_HOST,
timeout=client.GCE_METADATA_TIMEOUT)
connection.getresponse.assert_called_once_with()
# Remaining calls are not "getresponse"
headers = {
Expand Down

0 comments on commit ead74c4

Please sign in to comment.