facts gathering raises an IndexError exception on Junos releases < 15.1
stacywsmith opened this issue · 6 comments
The fix for #33 (merged from #35) was incorrect and causes fact gathering of version information to raise an exception on Junos releases < 15.1.
Here is an example:
user@h0$ netconify --facts --telnet ts4.lab,23 --user user --passwd user123
TTY:login:connecting to TTY:ts4.lab:23 ...
TTY:login:logging in ...
TTY:login:starting NETCONF
facts:retrieving device facts...
TTY:logout:logging out ...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 233, in run
self._do_actions()
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 329, in _do_actions
self._gather_facts()
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 401, in _gather_facts
self._tty.nc.facts.gather()
File "/usr/local/lib/python2.7/dist-packages/netconify/facts.py", line 90, in gather
self.version()
File "/usr/local/lib/python2.7/dist-packages/netconify/facts.py", line 22, in version
swinfo = rsp.xpath('.//junos-version')[0].text
IndexError: list index out of range
ERROR:list index out of range
Traceback (most recent call last):
File "/usr/local/bin/netconify", line 6, in <module>
results = nc.run()
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 240, in run
self._hook_exception('action', err)
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 233, in run
self._do_actions()
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 329, in _do_actions
self._gather_facts()
File "/usr/local/lib/python2.7/dist-packages/netconify/cmdo.py", line 401, in _gather_facts
self._tty.nc.facts.gather()
File "/usr/local/lib/python2.7/dist-packages/netconify/facts.py", line 90, in gather
self.version()
File "/usr/local/lib/python2.7/dist-packages/netconify/facts.py", line 22, in version
swinfo = rsp.xpath('.//junos-version')[0].text
IndexError: list index out of range
In this case, the following XML is produced by the Junos device:
user@edge3.lab> show version | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/14.2R5/junos">
<software-information>
<host-name>edge3.lab</host-name>
<product-model>mx240</product-model>
<product-name>mx240</product-name>
<package-information>
<name>junos-version</name>
<comment>Junos: 14.2R5.8</comment>
</package-information>
<package-information>
<name>junos</name>
<comment>JUNOS Base OS boot [14.2R5.8]</comment>
</package-information>
...
Even older versions of Junos produce version information like this example:
root@fw1> show version | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X46/junos">
<software-information>
<host-name>fw1</host-name>
<product-model>srx240h2</product-model>
<product-name>srx240h2</product-name>
<jsr/>
<package-information>
<name>junos</name>
<comment>JUNOS Software Release [12.1X46-D35.1]</comment>
</package-information>
</software-information>
<cli>
<banner></banner>
</cli>
</rpc-reply>
Thanks @stacywsmith
This is still a problem on SRX boxes running 12.1X46. I had to roll back to 1.0.1 and it works fine.
@hblandford Can you provide the output of "show version | display xml" from your device?
@stacywsmith here is the output as requested. Thanks for your interest.
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X46/junos">
<software-information>
<host-name>pbtest</host-name>
<product-model>srx110h2-va</product-model>
<product-name>srx110h2-va</product-name>
<jsr/>
<package-information>
<name>junos</name>
<comment>JUNOS Software Release [12.1X46-D40.2]</comment>
</package-information>
</software-information>
<cli>
<banner></banner>
</cli>
</rpc-reply>
@hblandford What version of netconify are you using? This issue was introduced in 1.0.2, and this issue is not yet fixed in a released version. To get the fix, you need to install from the Github repository with:
sudo pip install --upgrade git+https://github.com/Juniper/py-junos-netconify.git
The show version
output of my test device matches the the structure of your output:
root@fw1> show version | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X46/junos">
<software-information>
<host-name>fw1</host-name>
<product-model>srx240h2</product-model>
<product-name>srx240h2</product-name>
<jsr/>
<package-information>
<name>junos</name>
<comment>JUNOS Software Release [12.1X46-D35.1]</comment>
</package-information>
</software-information>
<cli>
<banner></banner>
</cli>
</rpc-reply>
And netconify successfully gathers facts:
user@h0$ netconify --version
1.0.3
user@h0$ netconify --telnet 10.0.0.1,8001 --user root --passwd root123 --facts fw1
TTY:connecting to TTY:10.0.0.1:8001 ...
TTY:logging in ...
login_warn:waiting on TTY.
TTY: OK ... starting NETCONF
facts:retrieving device facts...
facts:saving: ./fw1-facts.json
inventory:saving: ./fw1-inventory.xml
logout:logging out ...
user@h0$ more ./fw1-facts.json
{"model": "SRX240H2", "version": "12.1X46-D35.1", "serialnumber": "BU1214AK0046", "hostname": "fw1"}
user@h0$
@stacywsmith Sorry, I thought the merge request had gone into 1.0.2.