Make bgp_route hand-only for divergent IN/OUT CLI layouts.

Skip TextFSM for neighbor route tables (status vs plain, From, RD+VRF, heavy wraps); parse via callback and cover with live RR/VRF fixtures.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-23 15:36:25 +08:00
parent ac53af4a5d
commit c18c9afa2e
6 changed files with 354 additions and 194 deletions

View file

@ -29,3 +29,34 @@ def prefer_fsm(
if mapped:
return mapped
return hand_fn(raw_text=raw_text, **kw)
def prefer_hand(
fsm_tables: Mapping[str, list[dict[str, Any]]] | None,
keys: Sequence[str],
map_rows: MapRowsFn,
hand_fn: HandFn,
*,
raw_text: str,
**kw: Any,
) -> list[dict[str, Any]]:
"""Hand-first dual path: callback when non-empty; else first mapped FSM table.
Use when one TextFSM cannot cover divergent CLI layouts (e.g. BGP neighbor
in vs out, status vs plain, heavy wraps). Empty ``keys`` / ``RULE_KEYS=()``
makes this hand-only.
"""
hand = hand_fn(raw_text=raw_text, **kw)
if hand:
return hand
tables = fsm_tables or {}
for key in keys or ():
k = str(key or "").strip()
if not k:
continue
rows = tables.get(k) or []
if rows:
mapped = map_rows(rows)
if mapped:
return mapped
return hand