From 55ee2039747bed68a37f151f5b4a12dcf7a5a853 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 9 Jul 2020 10:56:09 -0400 Subject: [PATCH] Improve error handling in pxe If a name resolution error happens, put an event in events for the cleaner error. --- .../confluent/discovery/protocols/pxe.py | 3 +++ confluent_server/confluent/netutil.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/confluent_server/confluent/discovery/protocols/pxe.py b/confluent_server/confluent/discovery/protocols/pxe.py index 0e8d0a2f..f60f26e5 100644 --- a/confluent_server/confluent/discovery/protocols/pxe.py +++ b/confluent_server/confluent/discovery/protocols/pxe.py @@ -475,6 +475,9 @@ def check_reply(node, info, packet, sock, cfg, reqview): gateway = None netmask = None niccfg = netutil.get_nic_config(cfg, node, ifidx=info['netinfo']['ifidx']) + nicerr = niccfg.get('error_msg', False) + if nicerr: + log.log({'error': nicerr}) if niccfg.get('ipv4_broken', False): # Received a request over a nic with no ipv4 configured, ignore it return diff --git a/confluent_server/confluent/netutil.py b/confluent_server/confluent/netutil.py index a81e43bc..106d0c15 100644 --- a/confluent_server/confluent/netutil.py +++ b/confluent_server/confluent/netutil.py @@ -202,13 +202,16 @@ def get_nic_config(configmanager, node, ip=None, mac=None, ifidx=None, continue candgw = cfgbyname[candidate].get('ipv4_gateway', None) if candip: - if ip_on_same_subnet(net, candip, prefix): - cfgdata['ipv4_address'] = candip - cfgdata['ipv4_method'] = 'static' - cfgdata['ipv4_gateway'] = cfgbyname[candidate].get( - 'ipv4_gateway', None) - cfgdata['prefix'] = prefix - return cfgdata + try: + if ip_on_same_subnet(net, candip, prefix): + cfgdata['ipv4_address'] = candip + cfgdata['ipv4_method'] = 'static' + cfgdata['ipv4_gateway'] = cfgbyname[candidate].get( + 'ipv4_gateway', None) + cfgdata['prefix'] = prefix + return cfgdata + except Exception as e: + cfgdata['error_msg'] = 'Error trying to evaluate "{0}" for {1}: {2}'.format(candip, node, str(e)) elif candgw: if ip_on_same_subnet(net, candgw, prefix): candgws.append(candgw)