Add SROS multiline show port support#2304
Conversation
Rather than add an Error directive to a simple Start state and also have duplicate regex in the other state, collapse them into one (only have a Start state).
Remove the unnecessary Filldown keyword I added a couple commits ago. Phew!
matt852
left a comment
There was a problem hiding this comment.
Review written by AI PR reviewer agent:
Recommendation: Changes Suggested
Breaking Change: No
Thanks @mjbear — nice fixture coverage on the multiline / anchor / satellite cases. Two suggestions before merge:
-
Move the new rules below the suppressor block and revert
PORT_IDto(\S+). The[^=]guard onPORT_IDexcludes the===separator, but^${PORT_ID}$$still matches-----------(a 79-char dash run is happily captured by[^=]\S+). Today's fixtures always have a full port-data line immediately after the separator, so the wrongPORT_IDgets overwritten beforeRecordfires and tests pass — but it's the kind of latent fragility your PR description anticipated. Reordering the two new rules to sit after the suppressors is the alternative you mentioned, and once they're there the[^=]workaround isn't doing anything: I ran the scoped pytest against the combined diff below and all 8 cases pass. Also flipping(conn|anchor)to non-capturing(?:conn|anchor)lines this up withalcatel_sros_show_lag_port.textfsmandalcatel_sros_ping.textfsm, which use(?:...)for in-line alternation.In
ntc_templates/templates/alcatel_sros_show_port.textfsm, thePORT_IDValue declaration:-Value PORT_ID ([^=]\S+) +Value PORT_ID (\S+)
And the
Startstate body:Start - ^${PORT_ID}\s+${ADMIN_STATE}\s+${PORT_STATE}\s+(conn|anchor)\s*${C_QS_S_XFP_MDIMDX} -> Record + ^${PORT_ID}\s+${ADMIN_STATE}\s+${PORT_STATE}\s+(?:conn|anchor)\s*${C_QS_S_XFP_MDIMDX} -> Record ^${PORT_ID}\s+${ADMIN_STATE}\s+${LINK}\s+${PORT_STATE}\s+${CFG_MTU}\s+${OPER_MTU}\s+${LAG}\s+${PORT_MODE}\s+${PORT_ENCP}\s+${PORT_TYPE}\s*${C_QS_S_XFP_MDIMDX} -> Record - ^${PORT_ID}$$ - ^\s+${ADMIN_STATE}\s+${LINK}\s+${PORT_STATE}\s+${CFG_MTU}\s+${OPER_MTU}\s+${LAG}\s+${PORT_MODE}\s+${PORT_ENCP}\s+${PORT_TYPE}\s*${C_QS_S_XFP_MDIMDX} -> Record ^\s*$$ ^----------- ^=========== ^Port ^Id ^\*\sindicates + ^${PORT_ID}$$ + ^\s+${ADMIN_STATE}\s+${LINK}\s+${PORT_STATE}\s+${CFG_MTU}\s+${OPER_MTU}\s+${LAG}\s+${PORT_MODE}\s+${PORT_ENCP}\s+${PORT_TYPE}\s*${C_QS_S_XFP_MDIMDX} -> Record ^. -> Error
-
Drop the trailing
EOFmarker. None of the other 25 alcatel_sros templates use one — the convention is to omit it. The two-line addition at the end of the file:^. -> Error - -EOF
FYI on the YAML side: the ~2.4k-line show_port.yml diff is purely per-entry key alphabetization (verified data-equivalent via yaml.safe_load), so no breaking-change implications there — might be worth one line in the description noting that, to save the next reviewer the same check.
Thanks!
After reordering rules in previous commit: - port id regex doesn't need changed - EOF line is no longer needed
@matt852
Ok - maybe that's why I needed the EOF in earlier commits.
This one adds two more characters, but I suppose there's may be a performance benefit for a non-capturing pattern.
It's not relevant whether other templates use EOF -- it is relevant if it's functionally necessary. At one point there was a reason for the EOF or I wouldn't have added it. However after shifting things around I find the EOF isn't needed at this point.
In the case of my PRs, I mention when the changes are breaking otherwise they're backwards compatible (or non-breaking). For contributor clarity, we should come up with a formal definition of what is a breaking change for ntc-templates and add these details/examples to the documentation. And we may need a PR template so contributors are forced to acknowledge whether the PR includes a breaking change or not and what made the change a breaking change. But even then we always have to check. |
resolves #2301
show portlinesExample:
Notes:
We could move the two new patterns below the=sign separator pattern instead of negating the presence of an equal sign inPORT_ID. The equal sign negation will continue to function even if pattern lines are moved around in future template edits, so the negation pattern is probably most ideal.