Skip to content
This repository was archived by the owner on Sep 23, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions cloudinitd/pollables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down