networktocode/ntc-templates

Type 4 show mac address-table _ Parsing error when using the pip installed package

Closed this issue · 2 comments

ISSUE TYPE
  • Bug Report
TEMPLATE USING
Value DESTINATION_ADDRESS ([0-9a-fA-F]{4}\.[0-9a-fA-F]{4}\.[0-9a-fA-F]{4})
Value TYPE (\S+)
Value VLAN (\S+)
Value List DESTINATION_PORT ([^,\s]+)

Start
  ^Destination\s+Address\s+Address\s+Type\s+VLAN\s+Destination\s+Port -> TYPE1
  ^\s+vlan\s+mac address\s+type\s+learn\s+age\s+ports -> TYPE2
  ^\s+vlan\s+mac address\s+type\s+protocols\s+port -> TYPE3
  ^Vlan\s+Mac Address\s+Type\s+Ports -> TYPE4
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Load\s+for\s+
  ^Time\s+source\s+is

TYPE1
  ^${DESTINATION_ADDRESS}\s+${TYPE}\s+${VLAN}\s+${DESTINATION_PORT}$$ -> Record
  ^-+\s+-+
  ^Displaying\s+entries
  ^Destination\s+Address\s+Address\s+Type\s+VLAN\s+Destination\s+Port
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE2
  # Order of the group in brackets here matters
  ^\s*(\*\s+R|\*|R|\s)\s*(\d+|-+|[Nn]/[Aa]) -> Continue.Record
  # using 20 spaces should ensure that lines only match destination port flowing to next line
  ^\s{20}\s+${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+${DESTINATION_PORT},*\s*$$
  ^\s{20}\s+[^,\s]+(\s+|,\s*)${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+[^,\s]+(\s+|,\s*)${DESTINATION_PORT},*\s*$$
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){2}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){2}${DESTINATION_PORT},*\s*$$
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){3}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){3}${DESTINATION_PORT},*\s*$$
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){4}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){4}${DESTINATION_PORT},*\s*$$
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){5}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s{20}\s+([^,\s]+(\s+|,\s*)){5}${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+[^,\s]+(\s+|,\s*)${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+[^,\s]+?(\s+|,\s*)${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){2}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){2}${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){3}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){3}${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){4}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){4}${DESTINATION_PORT},*\s*$$
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){5}${DESTINATION_PORT}(\s+|,\s*)\S -> Continue
  ^\s*(\*\s+R|\*|R|\s)\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+\S+\s+([^,\s]+(\s+|,\s*)){5}${DESTINATION_PORT},*\s*$$
  ^-+\+-+
  ^Displaying\s+entries
  ^\s+vlan\s+mac address\s+type\s+learn\s+age\s+ports
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE3
  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+\S+\s+${DESTINATION_PORT}$$ -> Record
  ^-+\+-+
  ^Displaying\s+entries
  ^\s+vlan\s+mac address\s+type\s+protocols\s+port
  ^\s*$$
  ^Multicast\s+Entries -> End
  ^. -> Error

TYPE4
  ^\s*${VLAN}\s+${DESTINATION_ADDRESS}\s+${TYPE}\s+${DESTINATION_PORT}$$ -> Record
  ^-+\s+-+
  ^Displaying\s+entries
  ^Vlan\s+Mac Address\s+Type\s+Ports
  ^\s*$$
  ^Total\s+Mac\s+Addresses
  ^MultiCast\s+Entries -> End
  ^. -> Error
SAMPLE COMMAND OUTPUT
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
 All    0100.0ccc.cccc    STATIC      CPU
 All    0100.0ccc.cccd    STATIC      CPU
 All    0180.c200.0000    STATIC      CPU
 All    0180.c200.0001    STATIC      CPU
 All    0180.c200.0002    STATIC      CPU
 All    0180.c200.0003    STATIC      CPU
 All    0180.c200.0004    STATIC      CPU
 All    0180.c200.0005    STATIC      CPU
 All    0180.c200.0006    STATIC      CPU
 All    0180.c200.0007    STATIC      CPU
 All    0180.c200.0008    STATIC      CPU
 All    0180.c200.0009    STATIC      CPU
 All    0180.c200.000a    STATIC      CPU
 All    0180.c200.000b    STATIC      CPU
 All    0180.c200.000c    STATIC      CPU
 All    0180.c200.000d    STATIC      CPU
 All    0180.c200.000e    STATIC      CPU
 All    0180.c200.000f    STATIC      CPU
 All    0180.c200.0010    STATIC      CPU
 All    0180.c200.0021    STATIC      CPU
 All    ffff.ffff.ffff    STATIC      CPU
   1    9077.ee7d.6bc3    DYNAMIC     Po1
   1    9077.ee7d.84c3    DYNAMIC     Po1
 300    7cad.4f42.b6ff    DYNAMIC     Po1
 300    9077.ee67.48c7    STATIC      Vl300
 300    9077.ee7d.6c5f    DYNAMIC     Po1
 300    9077.ee7d.73df    DYNAMIC     Po1
 300    9077.ee7d.84c3    DYNAMIC     Po1
Total Mac Addresses for this criterion: 28
SUMMARY

Parsing with the pip installed package failed (3.0.0) on the line " 300 9077.ee67.48c7 STATIC Vl300 " (maybe because of the ending space) while it's working with the git package (3.0.0 installed with poetry)

STEPS TO REPRODUCE

Both tests can be found here :
(https://gist.github.com/froggylab/7aceb770adbeb790ab27d8336d36cb0f)

As far as I understand, two packages have differents versions between the two tests (the newest ones are failing) :
six -> 1.16.0 vs 1.15.0
textfsm -> 1.1.2 vs 1.1.0

EXPECTED RESULTS

Parsing the line " 300 9077.ee67.48c7 STATIC Vl300 " succeed

ACTUAL RESULTS
    raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 77. Input Line:  300    9077.ee67.48c7    STATIC      Vl300

Same problem here. Any way to fix this?

Will track in #1098