genieparser icon indicating copy to clipboard operation
genieparser copied to clipboard

Initiate empty dict before referencing variable

Open Kani999 opened this issue 3 years ago • 3 comments

Fixes: #515

Description

Variable address_family_dict was referenced before assignment;

Motivation and Context

Parser causes error:

Traceback (most recent call last):
  File "junos_show_interfaces_sample.py", line 11, in <module>
    res = dev.parse("show interfaces", output=output)
  File "src/genie/conf/base/device.py", line 524, in genie.conf.base.device.Device.parse
  File "src/genie/conf/base/device.py", line 557, in genie.conf.base.device.Device._get_parser_output
  File "src/genie/metaparser/_metaparser.py", line 272, in genie.metaparser._metaparser.MetaParser.parse
  File "/home/jankrupa/genie_fix/genieparser/src/genie/libs/parser/junos/show_interface.py", line 1963, in cli
    address_family_flags_dict = address_family_dict.setdefault('address-family-flags', {})

After assigning an empty dict to address_family_dict the output is return in proper JSON format.

Checklist:

  • [x] I have updated the changelog.
  • [x] I have updated the documentation (If applicable).
  • [x] I have added tests to cover my changes (If applicable).
  • [ ] All new and existing tests passed.
  • [ ] All new code passed compilation.

Kani999 avatar Sep 03 '21 13:09 Kani999

Hi @Kani999

Looks like these changes are causing existing parser tests to fail image

You can run these tests yourself using the folder_parsing_job.py script in the tests folder. Docs are here for that

Please adjust the code so that these tests pass. If you need to remove my suggested change, then so be it 👍

Thanks

LukasMcClelland avatar Sep 09 '21 14:09 LukasMcClelland

Hi @Kani999

Looks like these changes are causing existing parser tests to fail

Please adjust the code so that these tests pass. If you need to remove my suggested change, then so be it 👍

Thanks

I've looked at the tests but I cannot find what causes the problem. I've changed the junos/show_interface.py:1934 line back to its original state and the tests pass fine.

Kani999 avatar Sep 17 '21 10:09 Kani999

Looks like the tests are passing 👍

Even though this is a very small change, it would still be great to have a test for it. It will help to ensure that the parser will continue to parse your devices output when any future changes are made to the file.

Please add a test and feel free to use the output from the issue you created

Physical interface: ge-0/0/0, Enabled, Physical link is Up
  Interface index: 130, SNMP ifIndex: 502
.
.   Interfaces output
.

Physical interface: vme, Enabled, Physical link is Down
.
.   Interfaces output
.
{master:0}

Link to documentation for writing parser tests -> https://pubhub.devnetcloud.com/media/pyats-development-guide/docs/writeparser/writeparser.html#folder-based-testing-asa-ios-and-iosxe

LukasMcClelland avatar Sep 28 '21 22:09 LukasMcClelland