CiscoTestAutomation / genieparser

sub-component of Genie that parse the device output into structured datastructure
Apache License 2.0
248 stars 385 forks source link

iosxr 'show inventory' parser can not parse empty description field #29

Closed ghost closed 5 years ago

ghost commented 5 years ago

Aloha, The "show inventory" parser fails, if the description field is empty: CLI Output:

NAME: "module 0/0/0", DESCR: "ASR 9000 20-port 1GE Modular Port Adapter"
PID: A9K-MPA-20X1GE, VID: V03, SN: FOC19286666

NAME: "module mau 0/0/0/0", DESCR: ""
PID: N/A, VID: N/A, SN: FNS66661UTW

Parser output:

 "module 0/0/0": {
      "descr": "ASR 9000 20-port 1GE Modular Port Adapter",
      "pid": "N/A",
      "vid": "N/A",
      "sn": "FNS66661UTW"
    },

This fix helped: in: show_platform.py line 746: ' +DESCR: +\"(?P<descr>[\w\-\.\:\/\s,&]+)\"$')" change the + with `' +DESCR: +\"(?P[\w-.\:\/\s,&])\"$')`

Then it works:

"module 0/0/0": {
      "descr": "ASR 9000 20-port 1GE Modular Port Adapter",
      "pid": "A9K-MPA-20X1GE",
      "vid": "V03",
      "sn": "FOC196666"
    },
    "module mau 0/0/0/0": {
      "descr": "",
      "pid": "N/A",
      "vid": "N/A",
      "sn": "FNS66661UTW"
    },

Im just learning programming and this is my first issue report in Github. So forgive me, if I missed anything Cheers Marcel

jeaubin commented 5 years ago

Thanks for the proposed fix!

Are you interested to do a pull request with this fix ?

https://help.github.com/en/articles/creating-a-pull-request

Otherwise we can take care of it

Let us know!

ghost commented 5 years ago

Hi Jeaubin, Yes, good Idea. I will do a pull request for this fix. Can I learn something more.
:-)

ghost commented 5 years ago

Hi, one stupid question regarding pull request: Which branch should I use to create the pull request? Thanks Marcel

PatrickFrederiksen commented 5 years ago

Would the same problem exist if the PID field is empty ?

ghost commented 5 years ago

Hi Patrick, thats a good point! Im not a programmer, just a beginner, but when I look into the code, it looks for me, that for all,

it would happen, because the Regular expression does not match on an empty string, If I understand it correctly:

 p2 = re.compile(r'\s*PID: +(?P<pid>[a-zA-Z0-9\/\-\s]+),'
                             ' +VID: +(?P<vid>[a-zA-Z0-9\.\/\s]+),'
                             ' +SN: +(?P<sn>[a-zA-Z0-9\/\s]+)$')

So probably we should change the: + with *

at least for description and probably SN?

Cheers Marcel

jeaubin commented 5 years ago

Hi,

Thats right;

image

You can create your own branch. Usually though you would fork the project, fix the code, and from the fork you can click on creating a new Pull request,

https://help.github.com/en/articles/creating-a-pull-request-from-a-fork

jeaubin commented 5 years ago

As we are getting ready for the release; we've done this fix and it will be part of the next official release (next week)

Thanks to both of you for finding it and proposing fix!