Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser fails when cable-diagnostics tdr is running for show interface status on cisco-ios #1034

Closed
serverwrangler opened this issue Dec 2, 2021 · 1 comment

Comments

@serverwrangler
Copy link

ISSUE TYPE
  • Bug Report
TEMPLATE USING

cisco_ios_show_interfaces_status.textfsm

Value PORT (\S+)
Value NAME (.+?)
Value STATUS (err-disabled|disabled|connected|notconnect|inactive|up|down|monitoring)
Value VLAN (\S+)
Value DUPLEX (\S+)
Value SPEED (\S+)
Value TYPE (.*)
Value FC_MODE (\S+)

Start
  ^Load\s+for\s+
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Time\s+source\s+is
  ^-+\s*$$
  ^Port\s+Name\s+Status\s+Vlan\s+Duplex\s+Speed\s+Type -> Interfaces
  ^\s*$$
  ^. -> Error

Interfaces
  #Match fc...
  ^\s*${PORT}\s+is\s+${STATUS}\s+Port\s+mode\s+is\s+${FC_MODE}\s*$$ -> Record
  ^\s*${PORT}\s+is\s+${STATUS}\s+\(${TYPE}\)\s*$$ -> Record
  ^\s*${PORT}\s+${STATUS}\s+${VLAN}\s+${DUPLEX}\s+${SPEED}\s*${TYPE}$$ -> Record
  ^\s*${PORT}\s+${NAME}\s+${STATUS}\s+${VLAN}\s+${DUPLEX}\s+${SPEED}\s*${TYPE}$$ -> Record
  ^-+
  ^\s*$$
  ^. -> Error
SAMPLE COMMAND OUTPUT
show interface status | i Gi3/0/16
Gi3/0/16  No Description     notconnect:    1         a-full  a-100 10/100/1000BaseTX
SUMMARY

When an interface is currently undergoing a cable-diagnostic tdr test the show interface status output will include (connect:) or (notconnect:). This causes the template (cisco_ios_show_interfaces_status.textfsm) to fail to parse the interface status. This is a rare condition where the timing of running cable-diagnostic tdr test at the same time as running a show interface status or if you have older Cat3k switches with buggy IOS.

STEPS TO REPRODUCE
  • connect to switch and start cable diagnostics test on an interface
    test cable-diagnostics tdr interface gi3/0/16
  • At the same time connect and parse the output of the show interface status
    int_table = parse_output(platform="cisco_ios", command="show int status | exclude CPU|Trunk|Te", data=intsuck)
  • Example output
    Gi3/0/16 No Description notconnect: 1 a-full a-100 10/100/1000BaseTX
#!/usr/bin/env python3

import argparse
import ipaddress
from netaddr import *
import sys
from netmiko import ConnectHandler, ssh_exception
from netmiko.ssh_exception import AuthenticationException, SSHException
from ntc_templates.parse import parse_output

##########################################################################################################
#
#  Get arguments from the command line
#
##########################################################################################################

# determine if arguments were passed to the script and parse if so
if len(sys.argv) > 1:
    parser = argparse.ArgumentParser()
    parser.add_argument('-s', action='store', dest='switch_to_scan',
                        help='The switch to scan example 192.168.1.1', type=str, required=True)

    try:
        options = parser.parse_args()
    except:
        parser.print_help()
        sys.exit(0)

# if using script arguments
if options:
  if options.switch_to_scan:
      switch_to_scan = options.switch_to_scan

##########################################################################################################
#
#  Open connection and scan switch
#
##########################################################################################################

cisco = {
        'device_type' : 'cisco_ios',
        'host' : switch_to_scan,
        'username' : 'user',
        'password' : 'passwd',
}

try:
  print("Connecting to switch %s" %switch_to_scan)
  net_connect = ConnectHandler(**cisco)
except SSHException:
  print ("can't connect to last device")
  sys.exit(1)
except ssh_exception.NetMikoTimeoutException:
  print("  SSH Timed out")
  sys.exit(1)
except ssh_exception.NetMikoAuthenticationException:
  print("Invalid Credentials: ", switchaddress)
  sys.exit(1)

net_connect.find_prompt()
intsuck = net_connect.send_command("show int status | e CPU|Trunk|Te")
net_connect.disconnect()
int_table = parse_output(platform="cisco_ios", command="show int status | exclude CPU|Trunk|Te", data=intsuck)
EXPECTED RESULTS

Template parser to parse the interface status

ACTUAL RESULTS

Template parser failed to parse the output due to the status field containing an unexpected state.

File "/opt/homebrew/lib/python3.9/site-packages/textfsm/parser.py", line 1026, in _Operations
    raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 27. Input Line: Gi3/0/16  No Description            notconnect:  1            auto   auto 10/100/1000BaseTX
FIX

Fixed issue by adding two additional status values to template (cisco_ios_show_interfaces_status.textfsm)

<!---
Please paste the entire template that you are using
-->
cisco_ios_show_interfaces_status.textfsm 

Value PORT (\S+)
Value NAME (.+?)
Value STATUS (err-disabled|disabled|connected|connected:|notconnect|notconnect:|inactive|up|down|monitoring)
Value VLAN (\S+)
Value DUPLEX (\S+)
Value SPEED (\S+)
Value TYPE (.*)
Value FC_MODE (\S+)

Start
^Load\s+for\s+

Capture time-stamp if vty line has command time-stamping turned on

^Time\s+source\s+is
^-+\s*$$
^Port\s+Name\s+Status\s+Vlan\s+Duplex\s+Speed\s+Type -> Interfaces
^\s*$$
^. -> Error

Interfaces
#Match fc...
^\s*${PORT}\s+is\s+${STATUS}\s+Port\s+mode\s+is\s+${FC_MODE}\s*$$ -> Record
^\s*${PORT}\s+is\s+${STATUS}\s+(${TYPE})\s*$$ -> Record
^\s*${PORT}\s+${STATUS}\s+${VLAN}\s+${DUPLEX}\s+${SPEED}\s*${TYPE}$$ -> Record
^\s*${PORT}\s+${NAME}\s+${STATUS}\s+${VLAN}\s+${DUPLEX}\s+${SPEED}\s*${TYPE}$$ -> Record
^-+
^\s*$$
^. -> Error

serverwrangler added a commit to serverwrangler/ntc-templates that referenced this issue Dec 2, 2021
Template update to fix compatibility issues with show interface status on interfaces that are undergoing cable-diagnostics tdr testing.
@itdependsnetworks
Copy link
Contributor

Will Track in #1035

itdependsnetworks added a commit to itdependsnetworks/ntc-templates that referenced this issue Dec 25, 2022
Fix for issue networktocode#1034

Template update to fix compatibility issues with show interface status on interfaces that are undergoing cable-diagnostics tdr testing.

update

Co-Authored-By: Carlos Latorre <[email protected]>
itdependsnetworks added a commit that referenced this issue Dec 25, 2022
Fix for issue #1034

Template update to fix compatibility issues with show interface status on interfaces that are undergoing cable-diagnostics tdr testing.

update

Co-Authored-By: Carlos Latorre <[email protected]>

Co-authored-by: Carlos Latorre <[email protected]>
pszulczewski pushed a commit that referenced this issue Apr 12, 2023
Fix for issue #1034

Template update to fix compatibility issues with show interface status on interfaces that are undergoing cable-diagnostics tdr testing.

update

Co-Authored-By: Carlos Latorre <[email protected]>

Co-authored-by: Carlos Latorre <[email protected]>
cppmonkey pushed a commit to cppmonkey/ntc-templates that referenced this issue Oct 25, 2023
Fix for issue networktocode#1034

Template update to fix compatibility issues with show interface status on interfaces that are undergoing cable-diagnostics tdr testing.

update

Co-Authored-By: Carlos Latorre <[email protected]>

Co-authored-by: Carlos Latorre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants