blob: d521828e00e7fde6064c1b6f33a241d619423e5e [file] [log] [blame]
commit d9311fffa36dfe12ac12f81c778c1c8d95e43c57
Author: Ke Wu <mikewu@google.com>
Date: Tue Nov 8 15:26:32 2016 -0800
metadata_watcher.py: avoid keeping trying to connnect to metadata service
When ran on KVM, google-instance-setup.service (which is a oneshot
agent) keeps trying to connect to the metadata service which is
inaccessible during VM_Test of lakitu. It makes
google-instance-setup.service ends in an infinite loop and can't
finish the setup. Skip the loop completely.
diff --git a/google_compute_engine/metadata_watcher.py b/google_compute_engine/metadata_watcher.py
index e7da49b..b85a15f 100644
--- a/google_compute_engine/metadata_watcher.py
+++ b/google_compute_engine/metadata_watcher.py
@@ -152,17 +152,13 @@ class MetadataWatcher(object):
Returns:
json, the deserialized contents of the metadata server.
"""
- exception = None
while True:
try:
return self._GetMetadataUpdate(
metadata_key=metadata_key, recursive=recursive, wait=wait)
except (httpclient.HTTPException, socket.error, urlerror.URLError) as e:
- if isinstance(e, type(exception)):
- continue
- else:
- exception = e
- self.logger.exception('GET request error retrieving metadata.')
+ self.logger.exception('GET request error retrieving metadata. %s.', e)
+ break
def WatchMetadata(self, handler, metadata_key='', recursive=True):
"""Watch for changes to the contents of the metadata server.