Skip to content

Hosts with IPv6 primary address only fail discovery #295

@mathiaswegner

Description

@mathiaswegner

Environment

  • Python version: 3.10.9
  • Network Importer version: 3.1.0
  • Nautobot version: 1.5.6
  • pynautobot: 1.2.2

Steps to Reproduce

  1. select a device in Nautobot with an IPv6 primary address and no IPv4 address
  2. 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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions