[minigraph.py]: Don't create mux table entries for servers w/o loopbacks (#6457)

Avoid sonic-cfggen crashing when a server does not have a configured loopback address in the minigraph

Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
This commit is contained in:
Lawrence Lee 2021-01-17 00:23:11 -08:00 committed by Guohan Lu
parent 0d93b233d2
commit c7058a6d15

View File

@ -1506,14 +1506,17 @@ def get_mux_cable_entries(mux_cable_ports, neighbors, devices):
neighbor = neighbors[intf]['name'] neighbor = neighbors[intf]['name']
entry['state'] = 'auto' entry['state'] = 'auto'
# Always force a /32 prefix for server IPv4 loopbacks if devices[neighbor]['lo_addr'] is not None:
server_ipv4_lo_addr = devices[neighbor]['lo_addr'].split("/")[0] # Always force a /32 prefix for server IPv4 loopbacks
server_ipv4_lo_prefix = ipaddress.ip_network(UNICODE_TYPE(server_ipv4_lo_addr)) server_ipv4_lo_addr = devices[neighbor]['lo_addr'].split("/")[0]
entry['server_ipv4'] = str(server_ipv4_lo_prefix) server_ipv4_lo_prefix = ipaddress.ip_network(UNICODE_TYPE(server_ipv4_lo_addr))
entry['server_ipv4'] = str(server_ipv4_lo_prefix)
if 'lo_addr_v6' in devices[neighbor]: if 'lo_addr_v6' in devices[neighbor]:
entry['server_ipv6'] = devices[neighbor]['lo_addr_v6'] entry['server_ipv6'] = devices[neighbor]['lo_addr_v6']
mux_cable_table[intf] = entry mux_cable_table[intf] = entry
else:
print("Warning: no server IPv4 loopback found for {}, skipping mux cable table entry".format(neighbor))
return mux_cable_table return mux_cable_table