-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sonic-utilities: Update config reload() to verify formatting of an in…
…put file (#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: cchoate54@gmail.com 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)
- Loading branch information
Showing
3 changed files
with
208 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"DEVICE_METADATA": { | ||
"localhost": { | ||
"docker_routing_config_mode": "split", | ||
"hostname": "sonic", | ||
"hwsku": "Seastone-DX010-25-50", | ||
"mac": "00:e0:ec:89:6e:48", | ||
"platform": "x86_64-cel_seastone-r0", | ||
"type": "ToRRouter" | ||
} | ||
} | ||
"VLAN_MEMBER": { | ||
"Vlan1000|Ethernet0": { | ||
"tagging_mode": "untagged", | ||
}, | ||
"Vlan1000|Ethernet4": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet8": { | ||
"tagging_mode": "untagged" | ||
} | ||
}, | ||
"VLAN": { | ||
"Vlan1000": { | ||
"vlanid": "1000", | ||
"dhcp_servers": [ | ||
"192.0.0.1", | ||
"192.0.0.2", | ||
"192.0.0.3", | ||
"192.0.0.4" | ||
] | ||
} | ||
}, | ||
"PORT": { | ||
"Ethernet0": { | ||
"alias": "Eth1", | ||
"lanes": "65, 66, 67, 68", | ||
"description": "Ethernet0 100G link", | ||
"speed": "100000" | ||
}, | ||
"Ethernet4": { | ||
"admin_status": "up", | ||
"alias": "fortyGigE0/4", | ||
"description": "Servers0:eth0", | ||
"index": "1", | ||
"lanes": "29,30,31,32", | ||
"mtu": "9100", | ||
"pfc_asym": "off", | ||
"speed": "40000" | ||
}, | ||
"Ethernet8": { | ||
"admin_status": "up", | ||
"alias": "fortyGigE0/8", | ||
"description": "Servers1:eth0", | ||
"index": "2", | ||
"lanes": "33,34,35,36", | ||
"mtu": "9100", | ||
"pfc_asym": "off", | ||
"speed": "40000" | ||
} | ||
} | ||
} |
This file contains 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