From 047cd6302a8b53a0f3746d9dc0f519f95a9a6f24 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 9 Aug 2022 08:50:19 -0400 Subject: [PATCH] Add wait for IP connectivity After config, there may be a delay before the configuration takes effect. This delay can break nodeconfig. Try to wait for the delay to pass. --- confluent_server/confluent/discovery/core.py | 24 ++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index 28210cb6..683c2fad 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -82,6 +82,7 @@ import confluent.util as util import eventlet import traceback import shlex +import eventlet.green.socket as socket import socket as nsocket import eventlet.green.subprocess as subprocess webclient = eventlet.import_patched('pyghmi.util.webclient') @@ -1209,8 +1210,15 @@ def discover_node(cfg, handler, info, nodename, manual): log.log({'info': 'Discovered {0} ({1})'.format(nodename, handler.devname)}) if nodeconfig: - subprocess.check_call(['/opt/confluent/bin/nodeconfig', nodename] + nodeconfig) - log.log({'info': 'Configured {0} ({1})'.format(nodename, + bmcaddr = cfg.get_node_attributes(nodename, 'hardwaremanagement.manager') + bmcaddr = bmcaddr.get(nodename, {}).get('hardwaremanagement.manager', {}).get('value', '') + if not bmcaddr: + log.log({'error': 'Unable to get BMC address for {0]'.format(nodename)}) + else: + wait_for_connection(bmcaddr) + socket.getaddrinfo(bmcaddr, 443) + subprocess.check_call(['/opt/confluent/bin/nodeconfig', nodename] + nodeconfig) + log.log({'info': 'Configured {0} ({1})'.format(nodename, handler.devname)}) info['discostatus'] = 'discovered' @@ -1236,6 +1244,18 @@ def discover_node(cfg, handler, info, nodename, manual): info['discofailure'] = 'policy' return False +def wait_for_connection(bmcaddr): + expiry = 75 + util.monotonic_time() + while util.monotonic_time() < expiry: + for addrinf in socket.getaddrinfo(bmcaddr, 443, proto=socket.IPPROTO_TCP): + try: + tsock = socket.socket(addrinf[0]) + tsock.settimeout(1) + tsock.connect(addrinf[4]) + return + except OSError: + continue + eventlet.sleep(1) def do_pxe_discovery(cfg, handler, info, manual, nodename, policies): # use uuid based scheme in lieu of tls cert, ideally only