Hosts with IPv6 primary address only fail discovery
mathiaswegner opened this issue · 0 comments
mathiaswegner commented
Environment
- Python version: 3.10.9
- Network Importer version: 3.1.0
- Nautobot version: 1.5.6
- pynautobot: 1.2.2
Steps to Reproduce
- select a device in Nautobot with an IPv6 primary address and no IPv4 address
- run network-importer apply --check-configs
Expected Behavior
I expected that the device would be discovered and the configuration saved.
Observed Behavior
The device was not discovered due to not being reachable.
2023-02-01 16:02:20,148 - network-importer - INFO - Updating configuration from devices ..
2023-02-01 16:02:20,149 - nornir.core - WARNING - Task 'check_if_reachable' has not been run – 0 hosts selected
2023-02-01 16:02:20,149 - nornir.core - WARNING - Task 'warning_not_reachable' has not been run – 0 hosts selected
2023-02-01 16:02:20,149 - nornir.core - WARNING - Task 'dispatcher' has not been run – 0 hosts selected
2023-02-01 16:02:20,149 - network-importer - INFO - Import SOT Model
2023-02-01 16:02:24,076 - network-importer - INFO - Import Network Model
2023-02-01 16:02:25,311 - network-importer - ERROR - Unable to load the SOT Adapter : No valid configurations found in snapshot
The issue appears to be that when a socket is opened to tcp ping the device, it is opened as an ipv4 socket without first checking what ip version the primary ip is.
I was able to resolve it with this patch.
16d15
< import ipaddress
107,114d105
< isipv6 = False
< try:
< ipaddr = ipaddress.ip_address(host)
< if ipaddr.version == 6:
< isipv6 = True
< except ValueError:
< pass
<
117,120d107
< if isipv6:
< skt = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
< else:
< skt = socket.socket()
124,128c111
< if isipv6:
< hostargs = (host, port, 0, 0)
< else:
< hostargs = (host, port)
< status = skt.connect_ex(hostargs)
---
> status = skt.connect_ex((host, port))