Force heartbeat immediately after async command completes

This change passes the agent object into extensions, such that
they may call agent methods as needed. It also causes async
commands to force a heartbeat immediately after completing the
command. This allows Ironic to get a heartbeat and continue
work as quickly as possible, while also allowing deployers to
configure Ironic (agent) to heartbeat less often.

Change-Id: Ib3c3a43dfd0ed4ed51b7d52ac099f01181ca822f
This commit is contained in:
Jim Rollenhagen
2014-10-01 10:59:09 -07:00
parent 4f57590b2e
commit 082cf29cec
5 changed files with 45 additions and 9 deletions
ironic_python_agent

@ -121,6 +121,9 @@ class IronicPythonAgentHeartbeater(threading.Thread):
self.error_delay = min(self.error_delay * self.backoff_factor,
self.max_delay)
def force_heartbeat(self):
os.write(self.writer, 'b')
def stop(self):
"""Stop the heartbeat thread."""
if self.writer is not None:
@ -140,6 +143,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
namespace='ironic_python_agent.extensions',
invoke_on_load=True,
propagate_map_exceptions=True,
invoke_kwds={'agent': self},
)
self.api_url = api_url
self.driver_name = driver_name
@ -262,6 +266,9 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
raise errors.RequestedObjectNotFoundError('Command Result',
result_id)
def force_heartbeat(self):
self.heartbeater.force_heartbeat()
def run(self):
"""Run the Ironic Python Agent."""
# Get the UUID so we can heartbeat to Ironic. Raises LookupNodeError