Commit 42f51c2
authored
sonic-utilities: Update config reload() to verify formatting of an input file (sonic-net#2529)
sonic-utilities: bugfix-9499
Update config/main.py to verify if a config input file is properly formatted before writing it into confib_db
Update tests/config_test.py to include test cases for invalid input file
Add tests/config_reload_input/config_db_invalid.json as invalid input file used in tests/config_test.py
Signed-off-by: [email protected]
What I did
Include a check to validate if all input files are properly formatted before trying to write them to config_db to resolve bug 9499 in sonic-buildimage.
How I did it
Include a check to validate if all input files are properly formatted before trying to write them to config_db.
How to verify it
Run tests/config_test.py.
With the change added in main.py, run 'config reload' with an inproperly formatted input file.
Previous command output (if the output of a command-line utility has changed)
crystalnet@ibr02:~$ sudo config reload conf_db.json
Clear current config and reload config in config_db from the file(s) conf_db.json ? [y/N]: y
Disabling container monitoring ...
Stopping SONiC target ...
Running command: /usr/local/bin/sonic-cfggen -j /etc/sonic/init_cfg.json -j conf_db.json --write-to-db
Traceback (most recent call last):
File "/usr/local/bin/sonic-cfggen", line 452, in
main()
File "/usr/local/bin/sonic-cfggen", line 322, in main
_process_json(args, data)
File "/usr/local/bin/sonic-cfggen", line 236, in _process_json
deep_update(data, FormatConverter.to_deserialized(json.load(stream)))
File "/usr/lib/python3.9/json/init.py", line 293, in load
return loads(fp.read(),
File "/usr/lib/python3.9/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 713 column 5 (char 21870)
*Then the terminal becomes unusable until the device is reloaded.
New command output (if the output of a command-line utility has changed)
crystalnet@ibr02:~$ sudo config reload conf_db.json
Clear current config and reload config in config_db from the file(s) conf_db.json ? [y/N]: y
Bad format: json file broken. Expecting ',' delimiter: line 713 column 5 (char 21870)1 parent a5e1e2b commit 42f51c2
3 files changed
Lines changed: 208 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
1192 | 1203 | | |
1193 | 1204 | | |
1194 | 1205 | | |
| |||
1567 | 1578 | | |
1568 | 1579 | | |
1569 | 1580 | | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
| 1581 | + | |
| 1582 | + | |
1574 | 1583 | | |
1575 | 1584 | | |
1576 | 1585 | | |
| |||
1595 | 1604 | | |
1596 | 1605 | | |
1597 | 1606 | | |
1598 | | - | |
1599 | | - | |
| 1607 | + | |
| 1608 | + | |
1600 | 1609 | | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
1601 | 1628 | | |
1602 | 1629 | | |
1603 | 1630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
107 | 123 | | |
108 | 124 | | |
109 | 125 | | |
| |||
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
| 214 | + | |
198 | 215 | | |
199 | 216 | | |
200 | 217 | | |
| |||
206 | 223 | | |
207 | 224 | | |
208 | 225 | | |
209 | | - | |
| 226 | + | |
| 227 | + | |
210 | 228 | | |
211 | 229 | | |
212 | 230 | | |
| |||
479 | 497 | | |
480 | 498 | | |
481 | 499 | | |
| 500 | + | |
| 501 | + | |
482 | 502 | | |
483 | 503 | | |
484 | 504 | | |
485 | 505 | | |
486 | 506 | | |
487 | 507 | | |
488 | 508 | | |
489 | | - | |
| 509 | + | |
| 510 | + | |
490 | 511 | | |
491 | 512 | | |
492 | 513 | | |
| |||
507 | 528 | | |
508 | 529 | | |
509 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
510 | 552 | | |
511 | 553 | | |
512 | 554 | | |
| |||
549 | 591 | | |
550 | 592 | | |
551 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
552 | 642 | | |
553 | 643 | | |
554 | 644 | | |
| |||
568 | 658 | | |
569 | 659 | | |
570 | 660 | | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
571 | 682 | | |
572 | 683 | | |
573 | 684 | | |
| |||
0 commit comments