-
Notifications
You must be signed in to change notification settings - Fork 753
Fix invalid JSON output for 'show ip route <protocol> json' commands #4111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bojun-Feng
wants to merge
3
commits into
sonic-net:master
Choose a base branch
from
Bojun-Feng:correct-json-formatting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
e8debf2 to
0467615
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Commands like 'show ip route bgp json' were producing invalid JSON
with a namespace prefix (': '), breaking JSON parsers and automation.
The issue occurred because protocol filters (bgp, static, etc.) triggered
the namespace-prefix output path even when JSON was requested. On
single-ASIC systems where namespace is empty, this resulted in ': '
being printed before the JSON output.
Fixed by skipping the namespace-prefix path when JSON output is
requested, allowing proper JSON processing and formatting.
Signed-off-by: Bojun Feng <[email protected]>
0467615 to
86d7fb6
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Adds test_show_ip_route_bgp_json to verify protocol-filtered route
commands with JSON output work correctly.
Test validates:
- Command executes successfully
- Output is valid parseable JSON
- No namespace prefix bug (': ' at start)
- Output starts with '{'
- BGP routes present in filtered output
This test covers the bug fix in show/bgp_common.py where protocol
filters (bgp, static, etc.) with JSON output were producing invalid
JSON with namespace prefix on single-ASIC systems.
Signed-off-by: Bojun Feng <[email protected]>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Bojun Feng <[email protected]>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
What I did
Fixed
show ip route <protocol> jsoncommands producing invalid JSON output with namespace prefix.Fix sonic-net/sonic-buildimage#24398
Fix #3687
How I did it
The root cause is
show/bgp_common.pyhave a special if clause for protocol filters (bgp, static, etc.), triggering namespace-prefix output path even when JSON is requested.Current logic:
Solution:
We simply skip namespace-prefix path when JSON output is requested.
This allows JSON requests to fall through to proper JSON processing later at line 413.
How to verify it
Test protocol-filtered route commands with JSON output:
Verify output starts with
{and is valid JSON (parseable withjqorpython -m json.tool).Verify non-JSON commands still work:
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)