Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOS BGP IPv6 link local neighbor raises exception #1759

Closed
bewing opened this issue Sep 25, 2022 · 1 comment · Fixed by #1767
Closed

EOS BGP IPv6 link local neighbor raises exception #1759

bewing opened this issue Sep 25, 2022 · 1 comment · Fixed by #1767

Comments

@bewing
Copy link
Member

bewing commented Sep 25, 2022

Horking on trying to parse the IPv6 link local address in neighbor output

In [6]: d.get_bgp_neighbors()
---------------------------------------------------------------------------
AddrFormatError                           Traceback (most recent call last)
Cell In [6], line 1
----> 1 d.get_bgp_neighbors()

File ~/projects/napalm/napalm/eos/eos.py:720, in EOSDriver.get_bgp_neighbors(self)
    713                 is_enabled = True
    714             peer_info = {
    715                 "is_up": peer_data["peerState"] == "Established",
    716                 "is_enabled": is_enabled,
    717                 "uptime": int(time.time() - float(peer_data["upDownTime"])),
    718                 "description": peer_data.get("description", ""),
    719             }
--> 720             bgp_counters[vrf]["peers"][napalm.base.helpers.ip(peer)] = peer_info
    721 lines = []
    722 [lines.extend(x["output"].splitlines()) for x in output_neighbor_cmds]

File ~/projects/napalm/napalm/base/helpers.py:540, in ip(addr, version)
    517 def ip(addr: str, version: Optional[int] = None) -> str:
    518     """
    519     Converts a raw string to a valid IP address. Optional version argument will detect that \
    520     object matches specified version.
   (...)
    538         u'2001:db8:85a3::8a2e:370:7334'
    539     """
--> 540     addr_obj = IPAddress(addr)
    541     if version and addr_obj.version != version:
    542         raise ValueError("{} is not an ipv{} address".format(addr, version))

File ~/.pyenv/versions/3.9.1/envs/napalm/lib/python3.9/site-packages/netaddr/ip/__init__.py:305, in IPAddress.__init__(self, addr, version, flags)
    302                 break
    304     if self._module is None:
--> 305         raise AddrFormatError('failed to detect a valid IP ' \
    306             'address from %r' % addr)
    307 else:
    308     #   IP version is explicit.
    309     if _is_str(addr):

AddrFormatError: failed to detect a valid IP address from 'fe80::a8c1:abff:fe7b:247a%Et2'

Similar issue with details:

In [7]: d.get_bgp_neighbors_detail()
---------------------------------------------------------------------------
AddrFormatError                           Traceback (most recent call last)

Cell In [7], line 1
----> 1 d.get_bgp_neighbors_detail()

File ~/projects/napalm/napalm/eos/eos.py:1944, in EOSDriver.get_bgp_neighbors_detail(self, neighbor_address)
   1941 else:
   1942     # Using preset template to extract peer info
   1943     v4_peer_info = _parse_per_peer_bgp_detail(raw_output[0]["output"])
-> 1944     v6_peer_info = _parse_per_peer_bgp_detail(raw_output[1]["output"])
   1946 for peer_info in v4_peer_info:
   1948     vrf_name = peer_info["routing_table"]

File ~/projects/napalm/napalm/eos/eos.py:1865, in EOSDriver.get_bgp_neighbors_detail.<locals>._parse_per_peer_bgp_detail(peer_output)
   1859 item["export_policy"] = napalm.base.helpers.convert(
   1860     str, item["export_policy"]
   1861 )
   1862 item["last_event"] = napalm.base.helpers.convert(
   1863     str, item["last_event"]
   1864 )
-> 1865 item["remote_address"] = napalm.base.helpers.ip(item["remote_address"])
   1866 item["previous_connection_state"] = napalm.base.helpers.convert(
   1867     str, item["previous_connection_state"]
   1868 )
   1869 item["import_policy"] = napalm.base.helpers.convert(
   1870     str, item["import_policy"]
   1871 )

File ~/projects/napalm/napalm/base/helpers.py:540, in ip(addr, version)
    517 def ip(addr: str, version: Optional[int] = None) -> str:
    518     """
    519     Converts a raw string to a valid IP address. Optional version argument will detect that \
    520     object matches specified version.
   (...)
    538         u'2001:db8:85a3::8a2e:370:7334'
    539     """
--> 540     addr_obj = IPAddress(addr)
    541     if version and addr_obj.version != version:
    542         raise ValueError("{} is not an ipv{} address".format(addr, version))

File ~/.pyenv/versions/3.9.1/envs/napalm/lib/python3.9/site-packages/netaddr/ip/__init__.py:305, in IPAddress.__init__(self, addr, version, flags)
    302                 break
    304     if self._module is None:
--> 305         raise AddrFormatError('failed to detect a valid IP ' \
    306             'address from %r' % addr)
    307 else:
    308     #   IP version is explicit.
    309     if _is_str(addr):

AddrFormatError: failed to detect a valid IP address from ''
@bewing
Copy link
Member Author

bewing commented Sep 25, 2022

Possible approaches:
Refactor to use stdlib ipaddress module, which does support address scope: https://docs.python.org/3/library/ipaddress.html?highlight=ipv6%20link%20local%20addresses#ipaddress.IPv6Address

Raise issue with upstream to support scoped IPv6 addresses: https://github.com/netaddr/netaddr

bewing added a commit that referenced this issue Oct 14, 2022
refactor: replace netaddr with ipaddress
Resolves #1759
bewing added a commit that referenced this issue Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant