diff options
Diffstat (limited to 'packages/python-google-compute-engine')
4 files changed, 20 insertions, 18 deletions
diff --git a/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/script_retriever.py b/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/script_retriever.py index fd07423..3de425b 100644 --- a/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/script_retriever.py +++ b/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/script_retriever.py @@ -97,7 +97,7 @@ class ScriptRetriever(object): if not self.token: response = self.watcher.GetMetadata( - self.token_metadata_key, recursive=False, retries=1) + self.token_metadata_key, recursive=False, retry=False) if not response: self.logger.info( diff --git a/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/tests/script_retriever_test.py b/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/tests/script_retriever_test.py index 4019bbe..0df8830 100644 --- a/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/tests/script_retriever_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/metadata_scripts/tests/script_retriever_test.py @@ -89,7 +89,7 @@ class ScriptRetrieverTest(unittest.TestCase): # GetMetadata includes a prefix, so remove it. stripped_url = token_url.replace(metadata_prefix, '') mock_get_metadata.assert_called_once_with( - stripped_url, recursive=False, retries=1) + stripped_url, recursive=False, retry=False) self.assertEqual(self.retriever.token, 'foo bar') @@ -119,7 +119,7 @@ class ScriptRetrieverTest(unittest.TestCase): prefix = 'http://metadata.google.internal/computeMetadata/v1/' stripped_url = token_url.replace(prefix, '') mock_get_metadata.assert_called_once_with( - stripped_url, recursive=False, retries=1) + stripped_url, recursive=False, retry=False) mock_download_url.assert_called_once_with(auth_url, self.dest_dir) self.assertIsNone(self.retriever.token) diff --git a/packages/python-google-compute-engine/google_compute_engine/metadata_watcher.py b/packages/python-google-compute-engine/google_compute_engine/metadata_watcher.py index bf688cf..72a12f9 100644 --- a/packages/python-google-compute-engine/google_compute_engine/metadata_watcher.py +++ b/packages/python-google-compute-engine/google_compute_engine/metadata_watcher.py @@ -154,7 +154,7 @@ class MetadataWatcher(object): def _HandleMetadataUpdate( self, metadata_key='', recursive=True, wait=True, timeout=None, - retries=5): + retry=True): """Wait for a successful metadata response. Args: @@ -162,23 +162,25 @@ class MetadataWatcher(object): recursive: bool, True if we should recursively watch for metadata changes. wait: bool, True if we should wait for a metadata change. timeout: int, timeout in seconds for returning metadata output. - retries: int, Number of times to retry obtaining metadata. + retry: bool, True if we should retry on failure. Returns: json, the deserialized contents of the metadata server. """ exception = None - while retries >= 0: + while True: try: return self._GetMetadataUpdate( metadata_key=metadata_key, recursive=recursive, wait=wait, timeout=timeout) except (httpclient.HTTPException, socket.error, urlerror.URLError) as e: - retries -= 1 if not isinstance(e, type(exception)): exception = e self.logger.error('GET request error retrieving metadata. %s.', e) - time.sleep(1) + if retry: + continue + else: + break def WatchMetadata( self, handler, metadata_key='', recursive=True, timeout=None): @@ -200,7 +202,7 @@ class MetadataWatcher(object): self.logger.exception('Exception calling the response handler. %s.', e) def GetMetadata( - self, metadata_key='', recursive=True, timeout=None, retries=5): + self, metadata_key='', recursive=True, timeout=None, retry=True): """Retrieve the contents of metadata server for a metadata key. Args: @@ -214,4 +216,4 @@ class MetadataWatcher(object): """ return self._HandleMetadataUpdate( metadata_key=metadata_key, recursive=recursive, wait=False, - timeout=timeout, retries=retries) + timeout=timeout, retry=retry) diff --git a/packages/python-google-compute-engine/google_compute_engine/tests/metadata_watcher_test.py b/packages/python-google-compute-engine/google_compute_engine/tests/metadata_watcher_test.py index 9c0ca46..1bce509 100644 --- a/packages/python-google-compute-engine/google_compute_engine/tests/metadata_watcher_test.py +++ b/packages/python-google-compute-engine/google_compute_engine/tests/metadata_watcher_test.py @@ -259,12 +259,12 @@ class MetadataWatcherTest(unittest.TestCase): metadata_key = 'instance/id' recursive = False wait = False - retries = 5 + retry = True self.assertEqual( self.mock_watcher._HandleMetadataUpdate( metadata_key=metadata_key, recursive=recursive, wait=wait, - timeout=None, retries=retries), + timeout=None, retry=retry), {}) expected_calls = [ mock.call( @@ -282,12 +282,12 @@ class MetadataWatcherTest(unittest.TestCase): metadata_key = 'instance/id' recursive = False wait = False - retries = 0 + retry = False self.assertIsNone( self.mock_watcher._HandleMetadataUpdate( metadata_key=metadata_key, recursive=recursive, wait=wait, - timeout=None, retries=retries)) + timeout=None, retry=retry)) expected_calls = [ mock.call( metadata_key=metadata_key, recursive=recursive, wait=wait, @@ -333,7 +333,7 @@ class MetadataWatcherTest(unittest.TestCase): self.assertEqual(self.mock_watcher.GetMetadata(), {}) mock_response.assert_called_once_with( - metadata_key='', recursive=True, wait=False, timeout=None, retries=5) + metadata_key='', recursive=True, wait=False, timeout=None, retry=True) self.mock_watcher.logger.exception.assert_not_called() def testGetMetadataArgs(self): @@ -342,15 +342,15 @@ class MetadataWatcherTest(unittest.TestCase): self.mock_watcher._HandleMetadataUpdate = mock_response metadata_key = 'instance/id' recursive = False - retries = 5 + retry = False response = self.mock_watcher.GetMetadata( metadata_key=metadata_key, recursive=recursive, timeout=60, - retries=retries) + retry=retry) self.assertEqual(response, {}) mock_response.assert_called_once_with( metadata_key=metadata_key, recursive=False, wait=False, timeout=60, - retries=5) + retry=False) self.mock_watcher.logger.exception.assert_not_called() |