Juniper / py-junos-eznc

Python library for Junos automation
https://www.juniper.net/documentation/en_US/junos-pyez/information-products/pathway-pages/junos-pyez-developer-guide.html
Apache License 2.0
668 stars 342 forks source link

request support information CLI command does not work #558

Closed spidercensus closed 7 years ago

spidercensus commented 8 years ago

dev.cli("request support information") /usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:652: RuntimeWarning: CLI command is for debug use only! warnings.warn("CLI command is for debug use only!", RuntimeWarning) /usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:573: RuntimeWarning: An unknown exception occured - please report. warnings.warn("An unknown exception occured - please report.", RuntimeWarning) 'invalid command: request support information'

vnitinv commented 8 years ago

@spidercensus Hi Jason,

Which version of PyEZ are you using? I tested with 1.3.1 and latest github code. For both its working fine. Also on which junos you are running this?

spidercensus commented 8 years ago

Nitin,

I'm using PyEZ 1.3.1. I've discovered that I am able to run .cli('request support information') on other, smaller devices successfully. It may be because this is a production service provider router with such a long output for the RSI command that PyEZ is generating an exception. Is there a limit to the buffer length for a CLI command?

>>> d.cli('request support information', warning=False)
/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:573: RuntimeWarning: An unknown exception occured - please report.
  warnings.warn("An unknown exception occured - please report.", RuntimeWarning)
'invalid command: request support information'
>>> import jnpr.junos
>>> jnpr.junos.__version__
'1.3.1'
>>> d.facts
{'domain': 'REDACTED', 'RE1': {'status': 'OK', 'last_reboot_reason': 'Router rebooted after a normal shutdown.', 'model': 'RE-S-1800x4', 'up_time': '961 days, 14 hours, 35 minutes, 33 seconds', 'mastership_state': 'backup'}, 'ifd_style': 'CLASSIC', 'version_RE1': '11.4R7.5', 'version_RE0': '11.4R7.5', '2RE': True, 'serialnumber': 'JN122DA43AFA', 'fqdn': 'REDACTED', 'version_info': junos.version_info(major=(11, 4), type=R, minor=7, build=5), 'switch_style': 'BRIDGE_DOMAIN', 'version': '11.4R7.5', 'master': 'RE0', 'hostname': 'REDACTED', 'HOME': '/var/home/readonly', 'model': 'MX960', 'RE0': {'status': 'OK', 'last_reboot_reason': 'Router rebooted after a normal shutdown.', 'model': 'RE-S-1800x4', 'up_time': '961 days, 14 hours, 33 minutes, 20 seconds', 'mastership_state': 'master'}, 'vc_capable': False, 'personality': 'MX'}
spidercensus commented 8 years ago

I added a print statement for the exception at line 573 of device.py:

        # Something unexpected happened - raise it up
        except Exception as err:
            print err.message
            warnings.warn("An unknown exception occured - please report.", RuntimeWarning)
            raise

I got the exception message : "error parsing attribute name, line 1054, column 26".

Let me see if I can get the text of the RSI output from the command line for analysis.

spidercensus commented 8 years ago

On closer inspection the problematic lines appear as part of RSI executing the command "show system boot-messages no-forwarding".

I can get PyEZ to throw the exception when requesting just this command from .cli()

The exception says the parser is choking on the following lines:

Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0x9ce3bd<SSE3,RSVD2,MON,DS_CPL,VMX,EST,TM2,<b9>,CX16,<b14>,<b15>,<b18>,<b19>,<b20>,<b23>>
  AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>
stacywsmith commented 8 years ago

@spidercensus can you please execute "show system boot-messages | display xml | match Features2" on the problem device?

The output should show that < and >characters are escaped as &lt and &gt like this:

Features2=0x9ce3bd&lt;SSE3,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,DCA,SSE4.1,SSE4.2,POPCNT&gt;
AMD Features2=0x1&lt;LAHF&gt;

If they are not escaped, that's a Junos bug and the cause of your problem.

spidercensus commented 8 years ago
...@...> show system boot-messages | display xml | match Features2        

Features2=0x9ce3bd&lt;SSE3,RSVD2,MON,DS_CPL,VMX,EST,TM2,&lt;b9&gt;,CX16,&lt;b14&gt;,&lt;b15&gt;,&lt;b18&gt;,&lt;b19&gt;,&lt;b20&gt;,&lt;b23&gt;&gt;
          AMD Features2=0x1&lt;LAHF&gt;

See, the problem isn't the XML output, though. It's the CLI output.

vnitinv commented 8 years ago

@spidercensus Jason, can you share the file config.xml, generated by "show system boot-messages | display xml | save config.xml" You can unicast to me or @stacywsmith

spidercensus commented 8 years ago
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4R7/junos">
    <output>
        Copyright (c) 1996-2013, Juniper Networks, Inc.
        All rights reserved.
        Copyright (c) 1992-2006 The FreeBSD Project.
        Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
            The Regents of the University of California. All rights reserved.
        JUNOS 11.4R7.5 #0: 2013-03-01 08:49:11 UTC
            builder@evenath.juniper.net:/volume/build/junos/11.4/release/11.4R7.5/obj-amd64/bsd/kernels/JUNIPER64/kernel
        Timecounter "i8254" frequency 1193182 Hz quality 0
        CPU: Intel(R) Xeon(R) CPU           C5518  @ 1.73GHz (1729.11-MHz K8-class CPU)
          Origin = "GenuineIntel"  Id = 0x106e4  Stepping = 4
          Features=0xbfebfbff&lt;FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE&gt;
          Features2=0x9ce3bd&lt;SSE3,RSVD2,MON,DS_CPL,VMX,EST,TM2,&lt;b9&gt;,CX16,&lt;b14&gt;,&lt;b15&gt;,&lt;b18&gt;,&lt;b19&gt;,&lt;b20&gt;,&lt;b23&gt;&gt;
          AMD Features=0x28100800&lt;SYSCALL,NX,RDTSCP,LM&gt;
          AMD Features2=0x1&lt;LAHF&gt;
          Cores per package: 8
          Logical CPUs per core: 2
        real memory  = 17985175552 (17152 MB)
        avail memory = 16609046528 (15839 MB)
        Security policy loaded: JUNOS MAC/runasnonroot (mac_runasnonroot)
        Security policy loaded: JUNOS MAC/pcap (mac_pcap)
        Initializing M/T platform properties ..
        cpu0 on motherboard
        pcib0: &lt;Host to PCI bridge&gt; pcibus 0 on motherboard
        pci0: &lt;PCI bus&gt; on pcib0
        pcib1: &lt;PCI-PCI bridge&gt; mem 0xfb900000-0xfb90ffff irq 11 at device 3.0 on pci0
        pci3: &lt;PCI bus&gt; on pcib1
        em0: &lt;Intel(R) PRO/1000 Network Connection Version - 3.2.18&gt; port 0x4000-0x401f mem 0xfbd00000-0xfbd1ffff,0xfbd20000-0xfbd23fff irq 11 at device 0.0 on pci3
        pcib2: &lt;PCI-PCI bridge&gt; irq 11 at device 4.0 on pci0
        pci4: &lt;PCI bus&gt; on pcib2
        em1: &lt;Intel(R) PRO/1000 Network Connection Version - 3.2.18&gt; port 0x3000-0x301f mem 0xfbc00000-0xfbc1ffff,0xfbc20000-0xfbc23fff irq 11 at device 0.0 on pci4
        pcib3: &lt;PCI-PCI bridge&gt; irq 11 at device 5.0 on pci0
        pci5: &lt;PCI bus&gt; on pcib3
        em2: &lt;Intel(R) PRO/1000 Network Connection Version - 3.2.18&gt; port 0x2000-0x201f mem 0xfbb00000-0xfbb1ffff,0xfbb20000-0xfbb23fff irq 11 at device 0.0 on pci5
        pcib4: &lt;PCI-PCI bridge&gt; irq 11 at device 6.0 on pci0
        pci6: &lt;PCI bus&gt; on pcib4
        pcib5: &lt;PCI-PCI bridge&gt; irq 11 at device 0.0 on pci6
        pci7: &lt;PCI bus&gt; on pcib5
        acb0: &lt;Atlas Enhanced Control Subsystem&gt; mem 0xfba10000-0xfba103ff irq 11 at device 13.0 on pci7
        acb0: acb: softc at 0xffffff00010914c0, fpga regs at 0xffffff00fba10000
        spi: zl30143 clock initialized to 19.44 MHz
        pci7: &lt;network&gt; at device 14.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 8.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 8.1 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 8.2 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 8.3 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 9.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.1 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.2 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.3 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.4 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.5 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.6 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 10.7 (no driver attached)
        pci0: &lt;base peripheral, interrupt controller&gt; at device 11.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 16.0 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 16.1 (no driver attached)
        pci0: &lt;base peripheral&gt; at device 17.0 (no driver attached)
        ehci0: &lt;EHCI (generic) USB 2.0 controller&gt; mem 0xfbe21000-0xfbe213ff irq 11 at device 29.0 on pci0
        usb0: waiting for BIOS to give up control
        usb0: EHCI version 1.0
        usb0: &lt;EHCI (generic) USB 2.0 controller&gt; on ehci0
        usb0: USB revision 2.0
        uhub0: Intel EHCI root hub, class 9/0, rev 2.00/1.00, addr 1
        uhub0: 1 port with 1 removable, self powered
        uhub1: vendor 0x8087 product 0x0020, class 9/0, rev 2.00/0.00, addr 2
        uhub1: single transaction translator
        uhub1: 6 ports with 6 removable, self powered
        pcib6: &lt;PCI-PCI bridge&gt; at device 30.0 on pci0
        pci25: &lt;PCI bus&gt; on pcib6
        isab0: &lt;PCI-ISA bridge&gt; at device 31.0 on pci0
        isa0: &lt;ISA bus&gt; on isab0
        atapci0: &lt;GENERIC ATA controller&gt; port 0x1f0-0x1f7,0x3f6,0x170-0x177,0x376,0x5090-0x509f,0x5080-0x508f irq 11 at device 31.2 on pci0
        ata0: &lt;ATA channel 0&gt; on atapci0
        ata1: &lt;ATA channel 1&gt; on atapci0
        ichsmb0: &lt;Intel Ibexpeak (PCH) SMBus controller&gt; port 0x5000-0x501f mem 0xfbe20000-0xfbe200ff irq 11 at device 31.3 on pci0
        atapci1: &lt;GENERIC ATA controller&gt; port 0x5070-0x5077,0x5060-0x5063,0x5050-0x5057,0x5040-0x5043,0x5030-0x503f,0x5020-0x502f irq 11 at device 31.5 on pci0
        ata2: &lt;ATA channel 0&gt; on atapci1
        ata3: &lt;ATA channel 1&gt; on atapci1
        orm0: &lt;ISA Option ROMs&gt; at iomem 0xc0000-0xc0fff,0xc1000-0xc1fff on isa0
        sio0 at port 0x3f8-0x3ff irq 4 flags 0x90 on isa0
        sio0: type 16550A, console
        sio1 at port 0x3e8-0x3ef irq 5 on isa0
        sio1: type 16550A
        sio2 at port 0x2f8-0x2ff irq 3 on isa0
        sio2: type 16550A
        sio3 at port 0x2e8-0x2ef irq 7 on isa0
        sio3: type 16550A
        virtual chassis member-id = 255
        virtual chassis mode      = 0
        Initializing product: 21 ..
        Setting up M/T interface operations and attributes
        bmeb: bmeb_lib_init done 0xffffff040fc7a000, addr 0xffffffff80bd1ca8
        fxp0: bus=5, device=0, func=0, Ethernet address 00:a0:a5:7e:9b:f2
        em1: bus=4, device=0, func=0, Ethernet address 02:00:01:00:00:04
        em0: bus=3, device=0, func=0, Ethernet address 02:00:00:00:00:04
        Timecounter "TSC" frequency 1729112384 Hz quality 800
        ad1: Device does not support APM
        ad1: 28496MB &lt;StorFly - VSFA18PI032G-1A0 0605-1A0&gt; at ata0-master UDMA33
        ad0: Device does not support APM
        ad0: 3998MB &lt;Virtium - TuffDrive VCF300 101130&gt; at ata0-slave UDMA33
        Kernel thread "devrt_kernel_thread" (pid 40) exited prematurely.
        Trying to mount root from ufs:/dev/ad0s1a
        WARNING: / was not properly dismounted
    </output>
    <cli>
        <banner>{master}</banner>
    </cli>
</rpc-reply>
mirceaulinic commented 8 years ago

Hi @spidercensus Can you run the following RPC request from your router's CLI? (junoscript interactive netconf):

<?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:command format="xml">request support information</nc:command></nc:rpc>

For a better understanding of the exact output provided by the device.

Also, it would be useful if you'd display the type of the exception (inside the except Exception as err: block). E.g.:

type, value, traceback = sys.exc_info()

and print all these values.

I suspect ncclient is unable process properly the XML returned by the device.

vnitinv commented 8 years ago

@spidercensus This should be fixed in latest code. Can you please confirm?

stacywsmith commented 7 years ago

@spidercensus Closing this for now. If this is still an issue, please reopen. In that case, please manually execute the RPC as @mirceaulinic suggested and provide the output from the problem device.