Commit c225725
authored
Fix invalid JSON output for 'show ip route <protocol> json' commands (sonic-net#4111)
* Fix invalid JSON output for 'show ip route <protocol> json' commands
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 <davidfeng@uchicago.edu>
* Add test for 'show ip route bgp json' command
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 <davidfeng@uchicago.edu>
* misc: fix new line at end of file
Signed-off-by: Bojun Feng <davidfeng@uchicago.edu>
---------
Signed-off-by: Bojun Feng <davidfeng@uchicago.edu>1 parent 4e9080d commit c225725
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
| 432 | + | |
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
0 commit comments