get_route_to errors out when there are no matching routes
brocoli-mountain opened this issue · comments
brocoli-mountain commented
Description of Issue/Question
I get a KeyError when I try to query a PA for a route that doesn't exist in its table (in the below it would be matched by the default route):
DEBUG:pan.xapi:query: {'cmd': u'<show><routing><route><destination>172.24.40.0/24</destination></route></routing></show>', 'type': 'op', 'key': '******'}
DEBUG:pan.xapi:URI: https://172.x.y.z/api/?cmd=<show><routing><route><destination>172.24.40.0/24</destination></route></routing></show>&type=op&key=******
DEBUG:pan.xapi:method: POST
Traceback (most recent call last):
File "<pyshell#654>", line 1, in <module>
dev.conn.get_route_to('172.24.40.0/24')
File "C:\Python27\lib\site-packages\napalm_panos\panos.py", line 430, in get_route_to
routes_table_json = json.dumps(routes_table_xml['response']['result']['entry'])
KeyError: u'entry'
Raw XML returned by the command:
<response status="success"><result>
<flags>flags: A:active, ?:loose, C:connect, H:host, S:static, ~:internal, R:rip, O:ospf, B:bgp, Oi:ospf intra-area, Oo:ospf inter-area, O1:ospf ext-type-1, O2:ospf ext-type-2, E:ecmp</flags></result></response>
Perhaps change this:
try:
self.device.op(cmd=cmd)
routes_table_xml = xmltodict.parse(self.device.xml_root())
routes_table_json = json.dumps(routes_table_xml['response']['result']['entry'])
routes_table = json.loads(routes_table_json)
except AttributeError:
routes_table = []
to:
try:
self.device.op(cmd=cmd)
routes_table_xml = xmltodict.parse(self.device.xml_root())
routes_table_json = json.dumps(routes_table_xml['response']['result']['entry'])
routes_table = json.loads(routes_table_json)
except (AttributeError, KeyError):
routes_table = []
Did you follow the steps from https://github.com/napalm-automation/napalm#faq
- [x ] Yes
- No
Setup
napalm-panos version
(Paste verbatim output from pip freeze | grep napalm-panos
between quotes below)
napalm-panos==0.4.0
PanOS version
(Paste verbatim output from show system info
between quotes below)
Nope.
sw-version: 7.1.6
Steps to Reproduce the Issue
Error Traceback
(Paste the complete traceback of the exception between quotes below)
Traceback (most recent call last):
File "<pyshell#654>", line 1, in <module>
dev.conn.get_route_to('172.24.40.0/24')
File "C:\Python27\lib\site-packages\napalm_panos\panos.py", line 430, in get_route_to
routes_table_json = json.dumps(routes_table_xml['response']['result']['entry'])
KeyError: u'entry'
David Barroso commented
Closed by #47