napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.23k stars 551 forks source link

get_bgp_neighbors() Fails for Arista Software image version: 4.28.5M #1862

Closed oshobu closed 1 year ago

oshobu commented 1 year ago

Description of Issue/Question

The get_bgp_method() fails for Arista EOS version 4.28.5M. I dug into the code, and found what the Problem is. This is because the show command used to gather the information from the Arista box now returns additional lines compared to the older EOS Versions.

See below output from the command : show ip bgp neighbors vrf all | include remote AS | remote router ID |IPv[46] (Unicast|6PE):.*[0-9]+|^Local AS|Desc|BGP state

Sample old version output:

BGP neighbor is 23.x.x.1, remote AS 20006, internal link
 Description: Hostname_1
  BGP version 4, remote router ID 23.x.x.x, VRF default
  BGP state is Established, up for 298d22h
    IPv4 Unicast:                     1         9              2                   0
    IPv6 Unicast:                     0         0              0                   0
Local AS is 20006, local router ID 66.x.x.x

Sample output from Newer versions: -> Notice this now has additional Lines IPv4 and IPv6 Unicast (last 2 lines)

BGP neighbor is 54.x.x.106, remote AS 20006, internal link
 Description: Host_2
  BGP version 4, remote router ID 100.x.x.x, VRF default
  BGP state is Established, up for 13d05h
    IPv4 Unicast:                881093         0              0                   0
    IPv6 Unicast:                155144         0              0                   0
Local AS is 2906, local router ID 66.x.x.x
  IPv4 Unicast: 66.x.x.x
  IPv6 Unicast: 2a00:x::x

To fix the issue I basically added about 5 lines of code in the eos.py as shown below in my local environment to Pop those lines from the List if they exist.

    def get_bgp_neighbors(self):
       <SNIP>
            v4_stats = re.match(self._RE_BGP_PREFIX, lines.pop(0))
            v6_stats = re.match(self._RE_BGP_PREFIX, lines.pop(0))
            local_as = re.match(self._RE_BGP_LOCAL, lines.pop(0))

            # newer version, show commands have IPV4 UNicast in them
            if lines:  #my code
                if "  IPv4 Unicast:" in lines[0]:   # my code
                    lines.pop(0)  # my code
                if "  IPv6 Unicast:" in lines[0]:  # my code
                    lines.pop(0)  # my code

            data = {
                "remote_as": napalm.base.helpers.as_number(neighbor_info.group("as")),
                "remote_id": napalm.base.helpers.ip(
                    get_re_group(rid_info, "rid", "0.0.0.0")

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==4.0.0
nornir-napalm==0.3.0

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Arista DCS-7280SR-48C6-M-F
Hardware version: 11.05
Software image version: 4.28.5M
Architecture: x86_64
Internal build version: 4.28.5M-29792660.4285M
Internal build ID: 1814c374-a4c3-4bd4-b7d3-ea4f68b1c4ec
Image format version: 3.0
Image optimization: Sand-4GB

Steps to Reproduce the Issue

import json
from napalm.base import get_network_driver

optional_args = {'transport': 'https'}
driver = get_network_driver('eos')
dev = driver(hostname='host1', username='username', password='pwd')
dev.open()
dev_info = dev.get_bgp_neighbors()
dev.close()
print(json.dumps(dev_info, sort_keys=True, indent=4))

Error Traceback

(Paste the complete traceback of the exception between quotes below)

"/Users/firene/git/mpls_backbone/./mpls_backbone_router.py", line 422, in get_snapshot
    bgp_neigh = device_conn.get_bgp_neighbors()
  File "/Users/firene/git/mpls_backbone/venv/lib/python3.9/site-packages/napalm/eos/eos.py", line 748, in get_bgp_neighbors
    "remote_as": napalm.base.helpers.as_number(neighbor_info.group("as")),
AttributeError: 'NoneType' object has no attribute 'group'
forkwhilefork commented 1 year ago

I ran into this as well. Looks like it was reported in #1743 and fixed in #1746 but there hasn't been another release since then.