Bump GCE detection timeout to 1 sec.

This commit is contained in:
Craig Citro
2015-01-09 13:35:51 -08:00
parent 8ee592b5c6
commit 2864ebc7a5
2 changed files with 3 additions and 3 deletions

View File

@@ -938,7 +938,7 @@ def _detect_gce_environment(urlopen=None):
# the metadata resolution was particularly slow. The latter case is # the metadata resolution was particularly slow. The latter case is
# "unlikely". # "unlikely".
try: try:
response = urlopen('http://169.254.169.254/', timeout=0.1) response = urlopen('http://169.254.169.254/', timeout=1)
return response.info().get('Metadata-Flavor', '') == 'Google' return response.info().get('Metadata-Flavor', '') == 'Google'
except socket.timeout: except socket.timeout:
logger.info('Timeout attempting to reach GCE metadata service.') logger.info('Timeout attempting to reach GCE metadata service.')

View File

@@ -215,7 +215,7 @@ class GoogleCredentialsTests(unittest.TestCase):
autospec=True) as urlopen: autospec=True) as urlopen:
self.assertEqual('GCE_PRODUCTION', _get_environment()) self.assertEqual('GCE_PRODUCTION', _get_environment())
urlopen.assert_called_once_with( urlopen.assert_called_once_with(
'http://169.254.169.254/', timeout=0.1) 'http://169.254.169.254/', timeout=1)
def test_get_environment_unknown(self): def test_get_environment_unknown(self):
os.environ['SERVER_SOFTWARE'] = '' os.environ['SERVER_SOFTWARE'] = ''
@@ -224,7 +224,7 @@ class GoogleCredentialsTests(unittest.TestCase):
autospec=True) as urlopen: autospec=True) as urlopen:
self.assertEqual(DEFAULT_ENV_NAME, _get_environment()) self.assertEqual(DEFAULT_ENV_NAME, _get_environment())
urlopen.assert_called_once_with( urlopen.assert_called_once_with(
'http://169.254.169.254/', timeout=0.1) 'http://169.254.169.254/', timeout=1)
def test_get_environment_variable_file(self): def test_get_environment_variable_file(self):
environment_variable_file = datafile( environment_variable_file = datafile(