networktocode/ntc-templates

Bug in Template cisco_xr_admin_show_inventory

Closed this issue ยท 8 comments

ISSUE TYPE
  • Template Issue with error and raw data
TEMPLATE USING
Value Required NAME (.*?)
Value DESCR (.*)
Value PID (\S+)
Value VID (\S+)
Value SN (\S*)

Start
  ^NAME:\s+"${NAME}",\s+DESCR:\s+"${DESCR}"\s*$$
  ^\s*Name:\s+${NAME}\s+Descr:\s+${DESCR}\s*$$
  ^\s*PID:\s+${PID}\s*,\s+VID:\s+${VID}\s*,\s+SN:\s*${SN}$$ -> Record
  ^\s*PID:\s+${PID}\s+VID:\s+${VID}\s+SN:\s+${SN}$$ -> Record
  #
  ^\s*$$ 
  ^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s\S{3}\s+\d
  ^. -> Error
SAMPLE COMMAND OUTPUT
$ python sh_ver_test.py 
Traceback (most recent call last):
  File "/test_scripts/sh_ver_test.py", line 45, in <module>
    output = net_connect.send_command('admin show inventory', use_textfsm=True)
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/netmiko/utilities.py", line 592, in wrapper_decorator
    return func(self, *args, **kwargs)
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/netmiko/base_connection.py", line 1798, in send_command
    return_val = structured_data_converter(
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/netmiko/utilities.py", line 556, in structured_data_converter
    structured_output_tfsm = get_structured_data_textfsm(
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/netmiko/utilities.py", line 379, in get_structured_data_textfsm
    output = _textfsm_parse(textfsm_obj, raw_output, attrs)
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/netmiko/utilities.py", line 343, in _textfsm_parse
    tfsm_parse(raw_output, attrs)
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/textfsm/clitable.py", line 282, in ParseCmd
    self.table = self._ParseCmdItem(self.raw, template_file=template_files[0])
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/textfsm/clitable.py", line 315, in _ParseCmdItem
    for record in fsm.ParseText(cmd_input):
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/textfsm/parser.py", line 895, in ParseText
    self._CheckLine(line)
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/textfsm/parser.py", line 944, in _CheckLine
    if self._Operations(rule, line):
  File "/Users/rafi/netbot_env/lib/python3.10/site-packages/textfsm/parser.py", line 1024, in _Operations
    raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 15. Input Line:  PID: R-IOSXRV9000-CC        VID: V01                   SN: 767D97E4B21 
SUMMARY

Every time I ran this command with netmiko along with ntc-template, I get above error regardless the version of iosxr, I looked into it and seen that this parser was fixed recently, even though it was improvised but yet it is broken. I can fix this via following changes in the template

Value Required NAME (.*?)
Value DESCR (.*?)
Value PID (\S+)
Value VID (\S+)
Value SN (\S*)

Start
  ^NAME:\s+"${NAME}",\s+DESCR:\s+"${DESCR}"\s*$$
  ^\s*Name:\s+${NAME}\s+Descr:\s+${DESCR}\s*$$
  ^\s*PID:\s+${PID}\s*,\s+VID:\s+${VID}\s*,\s+SN:\s*${SN} -> Record
  ^\s*PID:\s+${PID}\s+VID:\s+${VID}\s+SN:\s+${SN} -> Record
  #
  ^\s*$$
  ^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s\S{3}\s+\d
  ^. -> Error
STEPS TO REPRODUCE

You can use following simple python script to reproduce it

from ntc_templates.parse import parse_output
from pprint import pprint

data1 = """
Thu Jul  6 08:36:32.002 UTC
  
 Name: Rack 0                Descr: Cisco IOS-XRv 9000 Centralized Virtual Router               
 PID: R-IOSXRV9000-CC        VID: V01                   SN: FOC1234PA56 
 
 Name: 0/0                   Descr: Cisco IOS-XRv 9000 Centralized Line Card                    
 PID: R-IOSXRV9000-LC-C      VID: V01                   SN: FOC4321PA6D 
 
 Name: 0/RP0                 Descr: Cisco IOS-XRv 9000 Centralized Route Processor              
 PID: R-IOSXRV9000-RP-C      VID: V01                   SN: FOC7085NP2K 
"""

data2 = """
Thu Jul  6 08:36:19.119 UTC
NAME: "module 0/RP0/CPU0", DESCR: "ASR 9900 Route Processor for Service Edge"
PID: ASR-9900-RP-SE, VID: V04, SN: FOC1234PA56

NAME: "module 0/RP1/CPU0", DESCR: "ASR 9900 Route Processor for Service Edge"
PID: ASR-9900-RP-SE, VID: V04, SN: FOC4321PA6D

NAME: "fantray 0/FT0/SP", DESCR: "ASR 9912 Fan Tray"
PID: ASR-9912-FAN, VID: V02, SN: FOC7085NP2K

NAME: "fan0 0/FT0/SP", DESCR: "ASR9K Generic Fan"
PID: N/A, VID: N/A, SN: 

"""

output1 = parse_output(platform="cisco_xr", 
                      command=f"admin show inventory", 
                      data=data1)

output2 = parse_output(platform="cisco_xr", 
                      command=f"admin show inventory", 
                      data=data2)


print('*'*80)
pprint(output1)
print('*'*80)
print('*'*80)
pprint(output2)
print('*'*80)
EXPECTED RESULTS
********************************************************************************
[{'descr': 'Cisco IOS-XRv 9000 Centralized Virtual Router',
  'name': 'Rack 0',
  'pid': 'R-IOSXRV9000-CC',
  'sn': 'FOC1234PA56',
  'vid': 'V01'},
 {'descr': 'Cisco IOS-XRv 9000 Centralized Line Card',
  'name': '0/0',
  'pid': 'R-IOSXRV9000-LC-C',
  'sn': 'FOC4321PA6D',
  'vid': 'V01'},
 {'descr': 'Cisco IOS-XRv 9000 Centralized Route Processor',
  'name': '0/RP0',
  'pid': 'R-IOSXRV9000-RP-C',
  'sn': 'FOC7085NP2K',
  'vid': 'V01'}]
********************************************************************************
********************************************************************************
[{'descr': 'ASR 9900 Route Processor for Service Edge',
  'name': 'module 0/RP0/CPU0',
  'pid': 'ASR-9900-RP-SE',
  'sn': 'FOC1234PA56',
  'vid': 'V04'},
 {'descr': 'ASR 9900 Route Processor for Service Edge',
  'name': 'module 0/RP1/CPU0',
  'pid': 'ASR-9900-RP-SE',
  'sn': 'FOC4321PA6D',
  'vid': 'V04'},
 {'descr': 'ASR 9912 Fan Tray',
  'name': 'fantray 0/FT0/SP',
  'pid': 'ASR-9912-FAN',
  'sn': 'FOC7085NP2K',
  'vid': 'V02'},
 {'descr': 'ASR9K Generic Fan',
  'name': 'fan0 0/FT0/SP',
  'pid': 'N/A',
  'sn': '',
  'vid': 'N/A'}]
********************************************************************************
ACTUAL RESULTS

textfsm.parser.TextFSMError: State Error raised. Rule Line: 15. Input Line: PID: R-IOSXRV9000-CC VID: V01 SN: FOC1234PA56


#1396 raised the pull request

I'm looking from the outside in...
There's a bunch of work maintaining these templates and plenty of extra messages/emails so it's easy to miss something.

@muhammad-rafi
Does the XRv 9000 still have all the trailing whitespace on the description?
Thank you!

I'm looking from the outside in... There's a bunch of work maintaining these templates and plenty of extra messages/emails so it's easy to miss something.

@muhammad-rafi Does the XRv 9000 still have all the trailing whitespace on the description? Thank you!

The one I worked with, they both version have same results, feel free to try XRv 9k with 7.5.2 and 7.3.2 if you like. I tried to raised pull request but does seem get much traction. I assume people are happy with it and it may be only me who is experiencing this issue.

The one I worked with, they both version have same results, feel free to try XRv 9k with 7.5.2 and 7.3.2 if you like. I tried to raised pull request but does seem get much traction. I assume people are happy with it and it may be only me who is experiencing this issue.

I'm neutral on the topic of traction or delays -- people get busy and sometimes the timing just doesn't line up. I understand and found I too had to be patient with the community project. With my PRs, I've found polite reminders and follow up helps move things along. (They're good people that are busy.)

I contribute back for all that this project has helped me accomplish. So while I don't have any cisco_xr gear in production it's a challenge that helps others.

I have access to an install of CML2 so I should be able to get an XRv in there. From what I'm seeing this will be IOS XR 9000v 7.7.1 and IOS XRv 6.3.1 (for the non-9000v).

I understand and appreciate your time to look into it.

You can try on the Cisco IOSXR Sandbox which is running 7.3.2, I just tried there and get same results

RP/0/RP0/CPU0:sandbox-iosxr-1#show version
Sat Jul 27 12:17:34.745 AST
Cisco IOS XR Software, Version 7.3.2
Copyright (c) 2013-2021 by Cisco Systems, Inc.

Build Information:
 Built By     : ingunawa
 Built On     : Wed Oct 13 20:00:36 PDT 2021
 Built Host   : iox-ucs-017
 Workspace    : /auto/srcarchive17/prod/7.3.2/xrv9k/ws
 Version      : 7.3.2
 Location     : /opt/cisco/XR/packages/
 Label        : 7.3.2-0

cisco IOS-XRv 9000 () processor
System uptime is 1 day 53 minutes

Here is the actual output from Cisco sandbox


RP/0/RP0/CPU0:sandbox-iosxr-1#admin show inventory
Sat Jul 27 12:20:31.302 AST
  
 Name: Rack 0                Descr: Cisco IOS-XRv 9000 Centralized Virtual Router               
 PID: R-IOSXRV9000-CC        VID: V01                   SN: B550ED1D0D9 
 
 Name: 0/0                   Descr: Cisco IOS-XRv 9000 Centralized Line Card                    
 PID: R-IOSXRV9000-LC-C      VID: V01                   SN: 86E4A261046 
 
 Name: 0/RP0                 Descr: Cisco IOS-XRv 9000 Centralized Route Processor              
 PID: R-IOSXRV9000-RP-C      VID: V01                   SN: F2E02123A63 
RP/0/RP0/CPU0:Agg1#

and here is the output using ntc template

[
  {
    "name": "Rack 0",
    "descr": "Cisco IOS-XRv 9000 Centralized Virtual Router               ",
    "pid": "R-IOSXRV9000-CC",
    "vid": "V01",
    "sn": "B550ED1D0D9"
  },
  {
    "name": "0/0",
    "descr": "Cisco IOS-XRv 9000 Centralized Line Card                    ",
    "pid": "R-IOSXRV9000-LC-C",
    "vid": "V01",
    "sn": "86E4A261046"
  },
  {
    "name": "0/RP0",
    "descr": "Cisco IOS-XRv 9000 Centralized Route Processor              ",
    "pid": "R-IOSXRV9000-RP-C",
    "vid": "V01",
    "sn": "F2E02123A63"
  }
]

@muhammad-rafi
The XR 9000v and XRv in CML2 take quite a while to boot up, haha.
The output from the 9000v output was similar to yours, but I also snagged a copy of the XRv Chassis to add to test cases.

I added your repo as a remote so I could fetch your branch and work off of that so you get credit for your contributions.

I submitted PR #1789

thanks a bunch @mjbear , appreciated.

I know CML2 take quite some time to bring up the XR devices specially, last time, I turn them on probably 5 month ago and left them running :)

RP/0/RP0/CPU0:cml-core-rtr01#show version
Sat Jul 27 16:31:14.987 UTC
Cisco IOS XR Software, Version 7.5.2
Copyright (c) 2013-2022 by Cisco Systems, Inc.

Build Information:
 Built By     : ingunawa
 Built On     : Tue Apr 26 18:04:31 PDT 2022
 Built Host   : iox-ucs-061
 Workspace    : /auto/srcarchive14/prod/7.5.2/xrv9k/ws
 Version      : 7.5.2
 Location     : /opt/cisco/XR/packages/
 Label        : 7.5.2-0

cisco IOS-XRv 9000 () processor
System uptime is 19 weeks 4 days 14 hours 54 minutes

I understand and appreciate your time to look into it.

You can try on the Cisco IOSXR Sandbox which is running 7.3.2, I just tried there and get same results

The sandbox (demo cloud / dcloud?) would have been easier - I'll have to keep that in mind to the next time.

The CML2 install I have access to has a topology running so spare memory is bloody scarce to turn up any other nodes. 64 GBytes is hardly enough. ๐Ÿ˜†