Permalink
Browse files

Check that public hostname can be resolved before stopping IaaS poll

This is a workaround for OpenStack, which returns the local hostname as
the public hostname for some time during the launch, even though the
instance is running. If this hostname cannot be resolved, we continue
polling IaaS until we get a resolvable hostname.
  • Loading branch information...
1 parent 2ff3b0b commit f3dc6021df1d07fc0a5b68b3377caf2a8ab1e400 @priteau priteau committed Feb 5, 2013
Showing with 18 additions and 12 deletions.
  1. +18 −12 cloudinitd/pollables.py
View
@@ -217,10 +217,21 @@ def poll(self):
state = self._instance.get_state()
cloudinitd.log(self._log, logging.DEBUG, "Current iaas state in poll for %s is %s" % (self.get_instance_id(), state))
if state == "running":
- self._done = True
- self._thread.join()
- self._execute_done_cb()
- return True
+ # Workaround for OpenStack sending the internal hostname as the
+ # public hostname: we wait until the hostname can be resolved
+ hostname = self.get_hostname()
+ try:
+ socket.gethostbyname(hostname)
+ except socket.gaierror as e:
+ cloudinitd.log(self._log, logging.WARN, "Hostname %s fails to resolve, continuing iaas poll: %s" % (hostname, e))
+ return False
+ except Exception:
+ raise
+ else:
+ self._done = True
+ self._thread.join()
+ self._execute_done_cb()
+ return True
if state not in self._ok_states:
msg = "The current state is %s. Never reached state running" % (state)
cloudinitd.log(self._log, logging.DEBUG, msg, tb=traceback)
@@ -263,14 +274,9 @@ def _thread_poll(self, poll_period=1.0):
done = False
while not self._done and not done:
try:
- if self._instance.get_state() not in self._ok_states:
- cloudinitd.log(self._log, logging.DEBUG, "%s polling thread done" % (self.get_instance_id()))
- done = True
- # because update is called in start we will sleep first
- else:
- time.sleep(poll_period)
- self._update()
- cloudinitd.log(self._log, logging.DEBUG, "Current iaas state in thread for %s is %s" % (self.get_instance_id(), self._instance.get_state()))
+ time.sleep(poll_period)
+ self._update()
+ cloudinitd.log(self._log, logging.DEBUG, "Current iaas state in thread for %s is %s" % (self.get_instance_id(), self._instance.get_state()))
except Exception, ex:
cloudinitd.log(self._log, logging.ERROR, str(ex), tb=traceback)
self.exception = IaaSException(ex)

0 comments on commit f3dc602

Please sign in to comment.