Skip to content

Add SROS multiline show port support#2304

Open
mjbear wants to merge 7 commits into
networktocode:masterfrom
mjbear:alc_sros_sh_port_issue2301
Open

Add SROS multiline show port support#2304
mjbear wants to merge 7 commits into
networktocode:masterfrom
mjbear:alc_sros_sh_port_issue2301

Conversation

@mjbear

@mjbear mjbear commented Apr 5, 2026

Copy link
Copy Markdown
Collaborator

resolves #2301

  • Add support for multiline show port lines
  • As a side-effect of regenerating the test data, keys in the YAML are in alphabetical order
  • Simplify states (since Port state could be collapsed into the Start state)

Example:

esat-11/1/c65 Up         Link Up                          conn   100GBASE-LR4*
esat-11/1/c65/u1
              Up    Yes  Up      9212 9212    - accs dotq cgige  

Notes:

  • We could move the two new patterns below the = sign separator pattern instead of negating the presence of an equal sign in PORT_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.

mjbear added 2 commits April 4, 2026 21:46
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!
@mjbear mjbear marked this pull request as ready for review April 9, 2026 01:59

@matt852 matt852 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ID to (\S+). The [^=] guard on PORT_ID excludes 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 wrong PORT_ID gets overwritten before Record fires 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 with alcatel_sros_show_lag_port.textfsm and alcatel_sros_ping.textfsm, which use (?:...) for in-line alternation.

    In ntc_templates/templates/alcatel_sros_show_port.textfsm, the PORT_ID Value declaration:

    -Value PORT_ID ([^=]\S+)
    +Value PORT_ID (\S+)

    And the Start state 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 EOF marker. 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!

mjbear added 3 commits May 22, 2026 21:23
After reordering rules in previous commit:

- port id regex doesn't need changed
- EOF line is no longer needed
@mjbear

mjbear commented May 23, 2026

Copy link
Copy Markdown
Collaborator Author

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_ID` to `(\S+)`.**

@matt852
I don't believe suppressor block is a term we've used.
That sentence doesn't mean anything to me.

The [^=] guard on PORT_ID excludes 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 wrong PORT_ID gets overwritten before Record fires 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.

Ok - maybe that's why I needed the EOF in earlier commits.

Also flipping (conn|anchor) to non-capturing (?:conn|anchor) lines this up with alcatel_sros_show_lag_port.textfsm and alcatel_sros_ping.textfsm, which use (?:...) for in-line alternation.

This one adds two more characters, but I suppose there's may be a performance benefit for a non-capturing pattern.

  In `ntc_templates/templates/alcatel_sros_show_port.textfsm`, the `PORT_ID` Value declaration:
  ```diff
  -Value PORT_ID ([^=]\S+)
  +Value PORT_ID (\S+)
  ```

  And the `Start` state body:
  ```diff
   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 `EOF` marker.** 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:
  ```diff
     ^. -> Error
  -
  -EOF
  ```

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.

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.

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.

@mjbear mjbear requested a review from matt852 May 23, 2026 01:56
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 this pull request may close these issues.

SROS22 multi-line issue in templates/alcatel_sros_show_port.textfsm

2 participants