networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.06k stars 698 forks source link

show etherchannel summary return raw data if no Port-channel #1700

Open andershagman opened 1 month ago

andershagman commented 1 month ago
ISSUE TYPE
TEMPLATE USING

cisco_ios_show_etherchannel_summary.textfsm

Value Required GROUP (\d+)
Value BUNDLE_NAME (\S+)
Value BUNDLE_STATUS (\D+)
Value BUNDLE_PROTOCOL (\S+)
Value List MEMBER_INTERFACE ([\w\.\/]+)
Value List MEMBER_INTERFACE_STATUS (\D+)

Start
  ^Group\s+Port-channel\s+Protocol -> PortChannel
  ^\s*$$

PortChannel
  ^\d+ -> Continue.Record
  ^${GROUP}\s+${BUNDLE_NAME}\(${BUNDLE_STATUS}\)\s+${BUNDLE_PROTOCOL}\s* -> Continue
  ^.+(-|LACP|PAgP)\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^.+(-|LACP|PAgP)\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^.+(-|LACP|PAgP)\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^.+(-|LACP|PAgP)\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+[\w\.\/\(\)]+\s+${MEMBER_INTERFACE}\(${MEMBER_INTERFACE_STATUS}\) -> Continue
  ^\d+
  ^\s+
  ^-+\++
  ^\s*$$
  ^(RU|SU)\s+-\s+L(2|3)\s+port-channel\s+UP\s+(s|S)tate
  ^(P|S)/(bndl|susp)\s+-\s+(Bundled|Suspended)
  ^. -> Error
SAMPLE COMMAND OUTPUT
2024-05-23 10:30:38,791 [INFO] --> show etherchannel summary
2024-05-23 10:30:38,918 [DEBUG] Raw data
[
  {
    "group": "1",
    "bundle_name": "Po1",
    "bundle_status": "SU",
    "bundle_protocol": "LACP",
    "member_interface": [
      "Gi1/1/1",
      "Gi1/1/2",
      "Te1/1/3",
      "Te1/1/4"
    ],
    "member_interface_status": [
      "D",
      "D",
      "P",
      "P"
    ]
  }
]
SUMMARY

When using the template with show etherchannel summary on a switch that does not have a port-channel you get the raw screen output instead of Null.

STEPS TO REPRODUCE

Just use the command show etherchannel summary with netmiko

connect.send_command("show etherchannel summary", use_textfsm=True)
EXPECTED RESULTS

Empty dict

[]
ACTUAL RESULTS
2024-05-23 10:33:34,181 [INFO] --> show etherchannel summary
2024-05-23 10:33:34,319 [DEBUG] Raw data
"Flags:  D - down        P - bundled in port-channel\n        I - stand-alone s - suspended\n        H - Hot-standby (LACP only)\n        R - Layer3      S - Layer2\n        U - in use      f - failed to allocate aggregator\n\n        M - not in use, minimum links not met\n        u - unsuitable for bundling\n        w - waiting to be aggregated\n        d - default port\n\n        A - formed by Auto LAG\n\n\nNumber of channel-groups in use: 0\nNumber of aggregators:           0\n\nGroup  Port-channel  Protocol    Ports\n------+-------------+-----------+-----------------------------------------------\n"
mjbear commented 1 week ago

Hello @andershagman Please confirm the version of NTC templates and Netmiko that you're using. What Cisco device and what version of code is that device running?

In my tests thus far TextFSM produces an empty list with the current template and some example output I have which has no etherchannels.

Thank you.

mjbear commented 1 week ago

Hello @andershagman Netmiko is supplying this behavior and Netmiko is behaving as it was coded. If there's an empty list returned then raw output is sent back (see below Github hyperlink). https://github.com/ktbyers/netmiko/blob/develop/netmiko/utilities.py#L346

You might consider type() checking of your output variable since if it's a string it is probably the raw output. Otherwise if the template has an issue textfsm would raise exceptions.

NTC templates/textfsm is sending an empty list back as my vanilla textfsm tests return []. However as noted above Netmiko tests for an empty list when it determines whether to send back the raw unstructured CLI output.

andershagman commented 1 week ago

Hi

Thanks for the explanation. I have used a workaround to not send the command if no po# interface.

MHV /Anders Hagman

22 juni 2024 kl. 22:17 skrev Michael Bear @.***>:

 Hello @andershagman Netmiko is supplying this behavior and Netmiko is behaving as it was coded. If there's an empty list returned then raw output is sent back (see below Github hyperlink). https://github.com/ktbyers/netmiko/blob/develop/netmiko/utilities.py#L346

You might consider type() checking of your output variable since if it's a string it is probably the raw output. Otherwise if the template has an issue textfsm would raise exceptions.

NTC templates/textfsm is sending an empty list back as my vanilla textfsm tests return []. However as noted above Netmiko tests for an empty list when it determines whether to send back the raw unstructured CLI output.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.