Open jeffbrl opened 8 years ago
I'll start by thanking @geoffrhodes for pointing out that debugging with pdb is simple using the Jaide class rather than the CLI.
Here's some test code I wrote that borrows the logic from py-junos-eznc.
# try looking for 'junos-version' for >= 15.1
for element in tree.xpath('//software-information'):
software_version = element.findtext('junos-version')
# try looking for version in "junos" package
if not software_version:
try:
package_info = tree.xpath(
'//software-information/package-information[normalize-space(name)="junos"]/comment'
)[0].text
software_version = re.findall(r'\[(.*)\]', package_info)[0]
except IndexError:
software_version = "unknown"
I'll integrate this code into core.py. I suspect other XML emission changes will break device_info
for newer junos versions. I'll report back on what I find.
Wasn't the issue present on code version >=14.2 as well? Might want to update the comment if this fixes it down to that version
Yes, the comment should be >= 14.2. The pyez code comment is inaccurate based on what I'm observing. On Apr 30, 2016 2:58 PM, "Nathan Printz" notifications@github.com wrote:
Wasn't the issue present on code version >=14.2 as well? Might want to update the comment if this fixes it down to that version
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/NetworkAutomation/jaide/issues/27#issuecomment-215987299
I'm observing three different XML emissions for 'get-software-information()'. I converted to xpath as I trust its syntax. I could combine my 2 and your 3 at the danger of making the logic harder to follow.
Here is what I have now.
version = 'Unknown'
if resp.xpath('//junos-version'):
""" case 1:
<junos-version>15.1</junos-version>
"""
try:
version = resp.xpath('//junos-version')[0].text
except IndexError:
pass
elif resp.xpath("//package-information[name = 'junos-version']"):
""" case 2:
<package-information>
<name>junos-version</name>
<comment>Junos: 14.2R4</comment>
</package-information>
"""
try:
version = (resp.xpath("//package-information[name = 'junos-version']/comment")[0].text).split()[1]
except IndexError:
pass
else:
""" case 3:
<package-information>
<name>junos</name>
<comment>JUNOS Base OS boot [12.3R5]</comment>
</package-information>
"""
try:
version = ((resp.xpath(
'//software-information/package-information/comment')
[0].text.split('[')[1].split(']')[0]))
except IndexError:
pass
I'll pep8-ify this and submit a PR unless anyone has comments or suggestions.
Using the 'info' command line parameter yields no information for devices running 14.2. I see that the XML has changed.
13.3
14.2
I suspect that the break occurs in core.py:498. The first package-information does not have square brackets in the comment.
I was hoping to write the fix myself but I'm having problems debugging. When I add "import pdb; pdb.set_trace()" to the code, the pdb prompt is displayed before the program exits.
If anyone can provide debugging tips, I can probably fix this and submit a PR.