napalm
napalm copied to clipboard
IOS get_bgp_neighbors_detail(): ValueError: invalid literal for int() with base 10: ''
Description of Issue/Question
When we try to get a detailed view of the BGP neighbors by calling get_bgp_neighbors_detail(), we receive the error:
ValueError: invalid literal for int() with base 10: ''
However, get_bgp_neighbors() works fine.
Did you follow the steps from https://github.com/napalm-automation/napalm#faq
(Place an x
between the square brackets where applicable)
- [x] Yes
- [] No
Setup
napalm version
(Paste verbatim output from pip freeze | grep napalm
between quotes below)
napalm==3.0.0
Network operating system version
(Paste verbatim output from show version
- or equivalent - between quotes below)
Cisco IOS XE Software, Version 16.09.04
Steps to Reproduce the Issue
We used this code for testing:
#!/usr/bin/python3.6
import napalm
import pprint
driver = napalm.get_network_driver("ios")
device = driver(
hostname="123.123.123.123",
username="username",
password="password",
optional_args={'port':1234, 'secret':'secret'}
)
device.open()
a = device.get_bgp_neighbors_detail()
pprint.pprint(a)
device.close()
Error Traceback
(Paste the complete traceback of the exception between quotes below)
Traceback (most recent call last):
File "napalm_test.py", line 18, in <module>
a = device.get_bgp_neighbors_detail()
File "/usr/lib/python3.6/site-packages/napalm/ios/ios.py", line 2004, in get_bgp_neighbors_detail
bgp_neigh_afi["flap_count"]
File "/usr/lib/python3.6/site-packages/napalm/base/helpers.py", line 375, in as_number
return int(as_number_str)
ValueError: invalid literal for int() with base 10: ''
FYI: I have tried to "quickfix" it by adding this on line 375 in "napalm/base/helpers.py":
return int(as_number_str) if as_number_str.isdigit() else None
However, got the next error then:
Traceback (most recent call last):
File "napalm_test.py", line 18, in <module>
a = device.get_bgp_neighbors_detail()
File "/usr/lib/python3.6/site-packages/napalm/ios/ios.py", line 1913, in get_bgp_neighbors_detail
"remote_address": napalm.base.helpers.ip(bgp_neigh["neighbor"]),
File "/usr/lib/python3.6/site-packages/napalm/base/helpers.py", line 362, in ip
addr_obj = IPAddress(addr)
File "/usr/lib/python3.6/site-packages/netaddr/ip/__init__.py", line 306, in __init__
'address from %r' % addr)
netaddr.core.AddrFormatError: failed to detect a valid IP address from ''
@smaxx1337 the way I usually debug this sort of things is adding another test case for the impacted method (i.e., a new directory under https://github.com/napalm-automation/napalm/tree/develop/test/ios/mocked_data/test_get_bgp_neighbors_detail, say issue_1213
) where I dump the data that's causing the trouble. Then, I start crafting around that. tox
is your friend in this case. :-)
Feel free to open a PR with what you have so far (including the mock data), even if WIP, and maybe we can help / guide you. Cheers. :wink: