Skip to content
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

[DRAFT] sonic-utilities: Validate input files to config reload #2673

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cchoate54
Copy link
Contributor

  • Update config/main.py to verify if a config input file is properly formatted before writing it into confib_db. Support /dev/stdin as an input that can be validated
  • 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 sonic-net/sonic-buildimage#9499.

How I did it

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)

@cchoate54 cchoate54 force-pushed the bugfix_9499_and_stdin branch 3 times, most recently from 95273e7 to f3941ab Compare February 14, 2023 18:39
@cchoate54
Copy link
Contributor Author

cchoate54 commented Feb 15, 2023

/AzurePipelines run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 2673 in repo sonic-net/sonic-utilities

1 similar comment
@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 2673 in repo sonic-net/sonic-utilities

* Update config/main.py to verify if a config input file is properly formatted before writing it into confib_db. Support /dev/stdin as an input that can be validated
* 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]
@cchoate54 cchoate54 force-pushed the bugfix_9499_and_stdin branch from f3941ab to 026d3e4 Compare March 14, 2023 21:14
@cchoate54 cchoate54 force-pushed the bugfix_9499_and_stdin branch 2 times, most recently from 2bd7e71 to da1e757 Compare March 24, 2023 21:21
@cchoate54 cchoate54 force-pushed the bugfix_9499_and_stdin branch 18 times, most recently from 1d01028 to eb911fb Compare March 30, 2023 22:51
@cchoate54 cchoate54 force-pushed the bugfix_9499_and_stdin branch 2 times, most recently from 9e0167f to e71be0d Compare March 31, 2023 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant