[DRAFT] sonic-utilities: Validate input files to config reload #2673
+258
−25
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.
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)