klish: stop auto-injecting exit/end when the view already declares one#159
Closed
eduardoterto wants to merge 1 commit into
Closed
Conversation
klish_ins_def_cmd.py auto-inserts a generic <COMMAND name="exit"/> and
<COMMAND name="end"/> into every VIEW that has not been processed yet.
The "already processed" check keys on the view name across files, not
on the view's own children — so any single-file VIEW that legitimately
ships its own exit (e.g. IOS-XR style hierarchies where exit returns
to the parent VIEW rather than nesting up) ends up with two COMMANDs
of the same name. klish then refuses to load the file with:
Error parsing XML: Duplicate COMMAND name="exit"
Error parsing XML: Node VIEW, name="config-evpn-view"
When that happens during klish startup the affected view becomes
unusable, and any clish_start invocation (interactive or batch) prints
the parser errors to stderr before the prompt. Batch stdin (e.g.
docker exec -i mgmt-framework /usr/sbin/cli/clish_start < cfg) fails
outright.
The original docstring already promises this guard:
if "exit" and "end" command are not already appended for the view,
the script will append them for the view
so this change makes the implementation match. We now check the view's
own COMMAND children for name="exit" and name="end" before inserting.
Discovered in the first end-to-end run of canonical-mpls (terto-horizon
sim/canonical-mpls): with the EVPN, OSPF, BGP, ACL, QoS, L2VPN, MPLS-LDP
and segment-routing views all shipping their own exit, the bug
silently broke 21 view files (108 dup COMMANDs total) on the running
mgmt-framework container.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
/azp run |
One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via: Supported
Alternatively, if the co-author should not be included, remove the Please update your commit message(s) by doing |
Author
|
Sorry, intended for terto-networks fork. Closing — will reopen there. |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`klish_ins_def_cmd.py` auto-inserts a generic `<COMMAND name="exit"/>` and `<COMMAND name="end"/>` into every VIEW that has not been processed yet. The "already processed" check keys on the view name across files, not on the view's own children — so any single-file VIEW that legitimately ships its own exit (e.g. IOS-XR style hierarchies where `exit` returns to the parent VIEW rather than nesting up) ends up with two COMMANDs of the same name. klish then refuses to load the file with:
```
Error parsing XML: Duplicate COMMAND name="exit".
Error parsing XML: Node VIEW, name="config-evpn-view"
```
When that happens during klish startup the affected view becomes unusable, and any `clish_start` invocation (interactive or batch) prints the parser errors to stderr before the prompt. Batch stdin (`docker exec -i mgmt-framework /usr/sbin/cli/clish_start < cfg`) fails outright.
The original docstring already promises this guard:
This change makes the implementation match. We check the view's own COMMAND children for `name="exit"` and `name="end"` before inserting.
Discovered
First end-to-end run of `canonical-mpls` (terto-horizon `sim/canonical-mpls`), 2026-05-12. With the EVPN, OSPF, BGP, ACL, QoS, L2VPN, MPLS-LDP and segment-routing views all shipping their own exit, the bug silently broke 21 view files (108 dup COMMANDs total) on the running `mgmt-framework` container.
Test plan
Out of scope (next PRs)
🤖 Generated with Claude Code