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

IOS-XR get_route_to fix pyIOSXR.exceptions.XMLCLIError for some versions #1267

Merged
merged 6 commits into from
Aug 19, 2020

Conversation

chonty
Copy link
Contributor

@chonty chonty commented Aug 11, 2020

See #958

On some versions of IOS-XR, get_route_to fails because the XML path (not sure what else to call it) had an element renamed from IP_RIBRoute to IP_RIBRouteTableName.

This PR fixes issue #958 and maintains backwards-compatibility using option B from my comment in the same issue.

Global variable IP_RIBRoute is used to store the default name 'IP_RIBRoute' and if the RPC call fails, it will suppress the exception (something still pops up and I don't know how to stop it), change the value of var IP_RIBRoute to 'IP_RIBRouteTableName' and try the RPC call again. Doing it this way means that we only need to fail once within the lifetime of a Napalm instance.

>>> import napalm
>>> driver = napalm.get_network_driver("iosxr")
>>> d = driver(
...     hostname="10.10.10.9",
...     username="napalm",
...     password="napalm",
... )
>>> d.open()
>>> a = d.get_route_to("10.202.0.56/29")

Original call was: <?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0"><Get><Operational><RIB><VRFTable><VRF><Naming><VRFName>default</VRFName></Naming><AFTable><AF><Naming><AFName>IPv4</AFName></Naming><SAFTable><SAF><Naming><SAFName>Unicast</SAFName></Naming><IP_RIBRouteTable><IP_RIBRoute><Naming><RouteTableName>default</RouteTableName></Naming><RouteTable><Route><Naming><Address>10.202.0.56</Address><PrefixLength>29</PrefixLength></Naming></Route></RouteTable></IP_RIBRoute></IP_RIBRouteTable></SAF></SAFTable></AF></AFTable></VRF></VRFTable></RIB></Operational></Get></Request>
>>> a
{'10.202.0.56/29': [{'current_active': True, 'last_active': False, 'age': 2460657, 'next_hop': '10.10.10.10', 'protocol': 'bgp', 'outgoing_interface': '', 'preference': 12, 'selected_next_hop': False, 'inactive_reason': '', 'routing_table': 'default', 'protocol_attributes': {}}]}
>>> a
{'10.202.0.56/29': [{'current_active': True, 'last_active': False, 'age': 2460657, 'next_hop': '10.10.10.10', 'protocol': 'bgp', 'outgoing_interface': '', 'preference': 12, 'selected_next_hop': False, 'inactive_reason': '', 'routing_table': 'default', 'protocol_attributes': {}}]}

In the above Python output, the Original call was:... will appear on the first get_route_to call if IP_RIBRoute doesn't work. I couldn't figure out how to silence it.

@coveralls
Copy link

coveralls commented Aug 11, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 4b952dc on chonty:xr-get_route_to into 14749bd on napalm-automation:develop.

@mirceaulinic mirceaulinic added this to the 3.2.0 milestone Aug 19, 2020
Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @chonty!

@mirceaulinic mirceaulinic merged commit 3604e20 into napalm-automation:develop Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants