CiscoTestAutomation / genieparser

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

Parsing of "show l2vpn xconnect" fails on IOS XR 7.2.2 #657

Open AlexLardschneider opened 2 years ago

AlexLardschneider commented 2 years ago

Parsing of the output of "show l2vpn xconnect" on IOS XR 7.2.2 fails with the following error using PyATS & Genie 22.4:

Traceback (most recent call last):
  File "test.py", line 39, in <module>
    print(f"722: {genie_device.parse('show l2vpn xconnect', output=content_722)}")
  File "src/genie/conf/base/device.py", line 527, in genie.conf.base.device.Device.parse
  File "src/genie/conf/base/device.py", line 573, in genie.conf.base.device.Device._get_parser_output
  File "src/genie/metaparser/_metaparser.py", line 279, in genie.metaparser._metaparser.MetaParser.parse
  File "venv/lib/python3.9/site-packages/genie/libs/parser/iosxr/show_xconnect.py", line 1285, in cli
    name_dict['status'] = str(group['status_group'])
UnboundLocalError: local variable 'name_dict' referenced before assignment

It looks like the issue is the changing header format between IOS XR 7.1.2 (where parsing works as expected) and IOS XR 7.2.2. Unfortunately, I have no device running XR > 7.2.2 to confirm that newer versions experience the same issue.

Following sample code reproduces this issue:

import importlib

output_722 = """
Legend: ST = State, UP = Up, DN = Down, AD = Admin Down, UR = Unresolved,
        SB = Standby, SR = Standby Ready, (PP) = Partially Programmed,
        LU = Local Up, RU = Remote Up, CO = Connected

XConnect                   Segment 1                       Segment 2                
Group      Name       ST   Description            ST       Description            ST    
------------------------   -----------------------------   -----------------------------
PW_XG      PW_TEST
                      UP   Te0/0/0/0.1234         UP       10.60.1.1       12345  UP    
----------------------------------------------------------------------------------------
"""

output_712 = """
Legend: ST = State, UP = Up, DN = Down, AD = Admin Down, UR = Unresolved,
        SB = Standby, SR = Standby Ready, (PP) = Partially Programmed

XConnect                   Segment 1                       Segment 2                
Group      Name       ST   Description            ST       Description            ST    
------------------------   -----------------------------   -----------------------------
PW_XG      PW_TEST
                      UP   Te0/0/0/0.1234         UP       10.60.1.1       12345  UP    
----------------------------------------------------------------------------------------
"""

Device = getattr(importlib.import_module(name=".conf.base", package="genie"), "Device")

get_parser = getattr(
    importlib.import_module(name=".libs.parser.utils", package="genie"), "get_parser"
)

genie_device = Device("test", custom={"abstraction": {"order": ["os"]}}, os="iosxr")

get_parser("show l2vpn xconnect", genie_device)

print(f"712: {genie_device.parse('show l2vpn xconnect', output=output_712)}")
print(f"722: {genie_device.parse('show l2vpn xconnect', output=output_722)}")
sjpatel21 commented 2 years ago

Hello Alex, Thanks for opening this issue. This issue has been resolved and will be available in the 22.6 release.

AlexLardschneider commented 2 years ago

Appreciate it!

ZacharyPuls commented 10 months ago

FYI - this regression has been re-introduced somewhere between IOS-XR 7.4.1 and 7.7.21 (I noticed it after upgrading one of our routers from 7.4.1 to 7.7.21, I don't have any other intermediate loads readily available to test). In 7.7.21, this fails:

>>> with open('test.txt', 'r') as file:
...     print(dev.parse('show l2vpn xconnect', output=file.read()))
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "src/genie/conf/base/device.py", line 531, in genie.conf.base.device.Device.parse
  File "src/genie/conf/base/device.py", line 581, in genie.conf.base.device.Device._get_parser_output
  File "src/genie/metaparser/_metaparser.py", line 308, in genie.metaparser._metaparser.MetaParser.parse
  File "/home/kfn.local/zpuls/pyats-tests/.venv/lib/python3.10/site-packages/genie/libs/parser/iosxr/show_xconnect.py", line 1339, in cli
    name_dict['status'] = str(group['status_group'])
UnboundLocalError: local variable 'name_dict' referenced before assignment

test.txt:

RP/0/RP0/CPU0:UDLLNCS61#show l2vpn xconnect
Thu Nov  2 00:43:19.928 CDT
Legend: ST = State, UP = Up, DN = Down, AD = Admin Down, UR = Unresolved,
        SB = Standby, SR = Standby Ready, (PP) = Partially Programmed,
        LU = Local Up, RU = Remote Up, CO = Connected, (SI) = Seamless Inactive

XConnect                   Segment 1                       Segment 2
Group      Name       ST   Description            ST       Description            ST
------------------------   -----------------------------   -----------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/1.1982         UP       10.9.1.186      1051982
                                                                                  UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/1.2982         UP       10.9.1.186      1052982
                                                                                  UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/2.20           UP       10.9.1.189      1100020
                                                                                  UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/2.2020         UP       10.9.1.189      1102020
                                                                                  UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/0.1            UP       10.9.1.21       2210001
                                                                                  UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/1.2712         UP       10.9.1.26       252712 UP
----------------------------------------------------------------------------------------
[omitted]
           [omitted]
                      UP   Gi0/0/0/2.3269         UP       10.9.1.26       253269 UP
----------------------------------------------------------------------------------------
ajackson79 commented 1 month ago

Just wanted to bump this and say it is still broken with the same outputs as the Original case running 7.7.21