Skip to content

hp_procurve_show_system: handle multi-word wrapped lines and Allow V2 Modules - #2371

Merged
matt852 merged 5 commits into
networktocode:masterfrom
pastoreerrante:pastoreeerrante/fix-issue-2370
Nov 17, 2026
Merged

matt852 merged 5 commits into
networktocode:masterfrom
pastoreerrante:pastoreeerrante/fix-issue-2370

Conversation

@pastoreerrante

@pastoreerrante pastoreerrante commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT

hp_procurve_show_system.textfsm — hp_procurve, show system

SUMMARY

Fixes #2370

Long System Contact / System Location lines wrap at column 78 onto indented continuation lines that can contain several words.

The existing rule ^\s+\S+$$ only matches continuation lines holding a single word (no spaces), so multi-word ones fell through to ^. -> Error and the whole parse fails.

Changes:

  • Replace the ^\s+\S+$$ rule with ^\s+(?!.*\s:\s)\S.*$$. Every field line has a label : value separator (whitespace, colon, whitespace) and continuation lines do not, so the negative lookahead skips only wrapped text. A hardcoded indentation width (e.g. ^\s{23}) would have worked as well. It was considered but rejected as too fragile (due to the weird hardcoded integer).

    The new pattern works like this:

    ^      \s+      (?!.*\s:\s)      \S.*      $$
    │      │        │                │         │
    │      │        │                │         └─ end of line
    │      │        │                └─ first non-space character, then anything after it
    │      │        └─ negative lookahead check: there is NO "space colon space" anywhere further on the line
    │      └─ one or more leading spaces (the line must be indented)
    └─ start of line
    
  • Accept Allow V2 Modules (seen on a real output) in addition to Allow V1 Modules.

  • Added hp_procurve_show_system4 fixture (sanitized real output) covering both cases. Once parsed, the contact field keeps only the first line discarding the wrapped continuation text. This is consistent with the existing hp_procurve_show_system3 fixture. Wrapped contact lines are now captured in contact_continued (see 6ff6953).

Tested locally with invoke tests --local (black, flake8, pylint, yamllint, pydocstyle, bandit, pytest): all passed, 4857 tests.

Input (excerpt of the new hp_procurve_show_system4.raw fixture):

  System Contact     : Network Infrastructure Team (network-infrastructure@exa
                       mple.com) location Site-A Building-1 Floor-2 SW-ACCESS-
                       01
  System Location    : Site-A Building-1 Rack-12 SW-ACCESS-01

  Allow V2 Modules   : Yes

Before (current master): the whole parse fails.

textfsm.parser.TextFSMError: State Error raised. Rule Line: 47. Input Line:                        mple.com) location Site-A Building-1 Floor-2 SW-ACCESS-

After (this PR): parses fine. The wrapped contact lines are collected in a new contact_continued list. contact is unchanged. The full value is contact + "".join(contact_continued) (lines wrap at a fixed column, often mid-word, so join without a separator).

- name: "SW-ACCESS-01"
  contact: "Network Infrastructure Team (network-infrastructure@exa"
  contact_continued:
    - "mple.com) location Site-A Building-1 Floor-2 SW-ACCESS-"
    - "01"
  location: "Site-A Building-1 Rack-12 SW-ACCESS-01"
  allow_mods: "Yes"
  serial: "AB12CDE3FK"
  software_version: "KB.16.10.0020"

… Modules

Long System Contact/Location values wrap at column 78 onto indented
continuation lines that can contain several words, e.g.:

  System Contact     : Network Infrastructure Team (network-infrastructure@exa
                       mple.com) location Site-A Building-1 Floor-2 SW-ACCESS-
                       01

The previous swallow rule (^\s+\S+$$) only matched a wrapped line if that was
holding exactly one word and no spaces after the indentation,
so multi-word ones fell through to `^. -> Error`, making the whole parse failed.
Replaced it with `^\s+(?!.*\s:\s)\S.*$$` because every non wrapped line
has a "label : value" separator and continuation lines do
not, so the negative lookahead skips only wrapped text.

The new pattern works like this:

^      \s+      (?!.*\s:\s)      \S.*      $$
│      │        │                │         │
│      │        │                │         └─ end of line
│      │        │                └─ first non-space character, then anything after it
│      │        └─ negative lookahead check: there is NO "space colon space" anywhere further on the line
│      └─ one or more leading spaces (the line must be indented)
└─ start of line

Also accept "Allow V2 Modules" (seen on a real show system output) in addition to
"Allow V1 Modules".

Add hp_procurve_show_system4 fixture covering both cases.

Fixes networktocode#2370

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@joewesch

joewesch commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

After (this PR): parses fine. The two wrapped contact lines are skipped, so contact holds only the text from the System Contact line (same as the existing hp_procurve_show_system3 fixture).

I would have considered this a bug, not something to replicate. Is there any way to parse the entire contact instead?

@pastoreerrante

pastoreerrante commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@joewesch fair point but, as far as I understood, TextFSM can't join text from different lines into one string value.

The only "trick" I could find for multi-line values is by using List + Continue (see NTC's parsing strategies post) but this is ideal when the value to be parsed is naturally a list, e.g. Cisco show vlan output:

  50   VLan50                           active    Fa0/1, Fa0/2, Fa0/3, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                  Fa0/10, Fa0/11, Fa0/12

Applied to this scenario, contact would change from string to list. The result would be something like: ["Network Infrastructure Team (network-infrastructure@exa", "mple.com) location Site-A Building-1 Floor-2 SW-ACCESS-", "01"].

This introduces problems:

  • it's a breaking change to an existing template's output: every consumer reading contact as a string would break, even though nautobot_device_onboarding/command_mappers/hp_procurve.yml does not read contact, so in theory nothing is going to break but there might be other users of ntc-templates...
  • contact line is cut mid-word at column 78, so consumer would have to rebuild the value with "".join(...).
  • I guess that If a cut ever falls on a space, the leading whitespace of the continuation line might be skipped, so the space would be likely lost.

That's why I'd prefer to keep this PR as the minimal fix for the parse failure in #2370 (no output type change).

pastoreerrante and others added 2 commits October 23, 2026 16:56
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
# swallow single-token wrap-continuation lines (long contact/location wrap at col 78)
^\s+\S+$$
# Skip wrapped Contact/Location continuation lines (no "label : value" separator)
^\s{20,}(?!.*\s:\s)\S.*$$

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.

Help me to understand this better, having 20 spaces as a required item here, does that really make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jvanderaa this was suggested by @joewesch:

This may be a bit too greedy. I see you rejected the hard-coded \s{23} as being fragile, but we can expect a minimum of 20 spaces at least with \s{20,} before we throw the line away.

@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.

One suggested change to capture the full multi-line contact value

@@ -1,2 +1,2 @@
Value Filldown NAME (\S+)
Value Filldown CONTACT (.+)

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.

Suggested change
Value Filldown CONTACT (.+)
Value Filldown,List CONTACT_CONTINUED (\S.*?)

Capture the full wrapped contact value. The new fixture stores contact as Network Infrastructure Team (network-infrastructure@exa, so the rest of the address is lost.

@matt852 matt852 Nov 2, 2026 •

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.

Suggested change
^\s*System\s+Contact\s+:\s+${CONTACT} -> ContactContinued

Same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. since TextFSM stops at the first match, I think we should drop the first ^\s*System\s+Contact\s+:\s+${CONTACT} otherwise ^\s*System\s+Contact\s+:\s+${CONTACT} -> Contact would never be matched.
  2. wouldn't be better to call the new Contact state something like ContactContinued? The state is entered after the first contact line is captured, so the state name should be really about capturing the possible wrapped part.

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.

@pastoreerrante Good points, and you're right on them. If just combine them into a single line:

^\s*System\s+Contact\s+:\s+${CONTACT} -> ContactContinued

that might work better.

# Skip wrapped Contact/Location continuation lines (no "label : value" separator)
^\s{20,}(?!.*\s:\s)\S.*$$
^. -> Error

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.

Suggested change
Contact
^\s{20,}${CONTACT_CONTINUED}\s*$$
^\s*System\s+Location\s+:\s+${LOCATION} -> Start
^. -> Error

This should capture the full wrapped contact value along with my other 2 suggested changes.

@pastoreerrante pastoreerrante Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@matt852 thanks! so if I understood correctly, your suggestion is to have an additional field called CONTACT_CONTINUED to capture the wrapped contact lines. The template user should then join CONTACT and CONTACT_CONTINUED when needed. If that's correct, how does the user know about this possibility?

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.

@pastoreerrante Yeah that's what I had in mind, assuming the wrapped lines contains data that may need to be captured. Maybe something like this, with a comment added to line 48, and 49 updated to the ContactContinued suggestion from above in your other comment?

# Join CONTACT and CONTACT_CONTINUED if System Contact contains wrapped lines
ContactContinued

Or something to that effect. Thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 6ff6953, thanks! As discussed, the new -> ContactContinued rule replaces the original System Contact rule. I placed CONTACT_CONTINUED last in the Value block so existing column positions don't shift for anyone reading raw TextFSM rows by index. All show_system fixtures regenerated so they only gain contact_continued.

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.

Excellent, thank you!

Long System Contact values wrap at a fixed column (often mid-word) onto
indented continuation lines which were previously skipped, so contact
held only the first line.

With this commit we now collect those lines in a new CONTACT_CONTINUED value (Filldown,List).
The System Contact rule now switches to a ContactContinued state, which
appends each wrapped line and returns to Start on System Location.
CONTACT is unchanged, so existing consumers are unaffected. The full
value is CONTACT + "".join(CONTACT_CONTINUED). The new Value is declared
last so existing column positions are unchanged for consumers whom might
be reading raw TextFSM rows by index. Wrapped System Location lines are still
skipped.

Regenerated the show_system fixtures as well so each record gains
contact_continued (empty when the contact does not wrap).

Suggested-by: matt852
@matt852
matt852 self-requested a review November 17, 2026 16:08
@matt852
matt852 merged commit d54cc44 into networktocode:master Nov 17, 2026
14 checks passed
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.

hp_procurve_show_system.textfsm template fails to parse wrapped "System Contact" line

5 participants