Repository navigation
hp_procurve_show_system: handle multi-word wrapped lines and Allow V2 Modules - #2371
pastoreerrante wants to merge 3 commits into
Conversation
… 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
I would have considered this a bug, not something to replicate. Is there any way to parse the entire contact instead? |
|
@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 Applied to this scenario, This introduces problems:
That's why I'd prefer to keep this PR as the minimal fix for the parse failure in #2370 (no output type change). |
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com>
ISSUE TYPE
COMPONENT
hp_procurve_show_system.textfsm— hp_procurve,show systemSUMMARY
Fixes #2370
Long
System Contact/System Locationlines 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^. -> Errorand the whole parse fails.Changes:
Replace the
^\s+\S+$$rule with^\s+(?!.*\s:\s)\S.*$$. Every field line has alabel : valueseparator (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:
Accept
Allow V2 Modules(seen on a real output) in addition toAllow V1 Modules.Added
hp_procurve_show_system4fixture (sanitized real output) covering both cases. Once parsed, thecontactfield keeps only the first line discarding the wrapped continuation text. This is consistent with the existinghp_procurve_show_system3fixture.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.rawfixture):Before (current
master): the whole parse fails.After (this PR): parses fine. The two wrapped contact lines are skipped, so
contactholds only the text from theSystem Contactline (same as the existinghp_procurve_show_system3fixture).