diff options
| author | vmud213 <vinay50muddu@yahoo.com> | 2016-04-08 15:13:23 +0000 |
|---|---|---|
| committer | vmud213 <vinay50muddu@yahoo.com> | 2016-06-14 12:36:52 +0000 |
| commit | 09db71d640a296e4daed3fb7927f734b020dde8e (patch) | |
| tree | 1f08684f52477a9fe04210a09274a2759cc282e5 /ironic_python_agent/agent.py | |
| parent | 9965b449d639f881994d04eb490311ebab4b8d2b (diff) | |
| download | ironic-python-agent-09db71d640a296e4daed3fb7927f734b020dde8e.tar.gz | |
Wait for at least one interface before node lookup
During node look up sometimes IPA sends hardware inventory information before
the interfaces are up, resulting in empty interfaces information being sent
to the conductor. This causes conductor to throw exceptions and polluting
the log until the real interfaces information is populated. This change makes
IPA to wait for at least one interface to be up before trying for node lookup.
Change-Id: Ifdb91298eaa5c725f108fa722263ed925691ecda
Closes-Bug: #1562786
Diffstat (limited to 'ironic_python_agent/agent.py')
| -rw-r--r-- | ironic_python_agent/agent.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py index b5d9fdd0..0a1799aa 100644 --- a/ironic_python_agent/agent.py +++ b/ironic_python_agent/agent.py @@ -38,6 +38,13 @@ from ironic_python_agent import utils LOG = log.getLogger(__name__) +# Time(in seconds) to wait for any of the interfaces to be up +# before lookup of the node is attempted +NETWORK_WAIT_TIMEOUT = 60 + +# Time(in seconds) to wait before reattempt +NETWORK_WAIT_RETRY = 5 + def _time(): """Wraps time.time() for simpler testing.""" @@ -283,6 +290,24 @@ class IronicPythonAgent(base.ExecuteCommandMixin): if not self.standalone: self.heartbeater.force_heartbeat() + def _wait_for_interface(self): + """Wait until at least one interface is up.""" + + wait_till = time.time() + NETWORK_WAIT_TIMEOUT + while time.time() < wait_till: + interfaces = hardware.dispatch_to_managers( + 'list_network_interfaces') + if not any(ifc.mac_address for ifc in interfaces): + LOG.debug('Network is not up yet. ' + 'No valid interfaces found, retrying ...') + time.sleep(NETWORK_WAIT_RETRY) + else: + break + + else: + LOG.warning("No valid network interfaces found. " + "Node lookup will probably fail.") + def run(self): """Run the Ironic Python Agent.""" # Get the UUID so we can heartbeat to Ironic. Raises LookupNodeError @@ -303,6 +328,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin): # lookup will fail due to unknown MAC. uuid = inspector.inspect() + self._wait_for_interface() content = self.api_client.lookup_node( hardware_info=hardware.dispatch_to_managers( 'list_hardware_info'), |
