-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Adding some sanity-checking to configdb.json parsing logic #1891
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
Open
rodnymolina
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
rodnymolina:configdb_parsing_protection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding some sanity-checking to configdb.json parsing logic #1891
rodnymolina
wants to merge
1
commit into
sonic-net:master
from
rodnymolina:configdb_parsing_protection
Conversation
This file contains hidden or 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
I'm adding some sanity-checking logic to prevent semantically-incorrect entries, present in any given config_db.json file, from being able to make it to sonic backends. This should tackle various issues observed in the past where a user could easily bring a system down or to an inconsistent state by introducing erroneous configuration while manually editing a config_db.json file. To exercise this logic, user can either make use of the "--check-json" parameter offered by 'sonic-cfggen' (see examples below), or rely on the typical "config load/reload" CLI instructions. The changes associated to the second option will come as part of a different PR (in sonic-utilities repo). Find some examples below of how this code operates: <—- Tescase 1) Adding ‘interface’ associated to invalid ‘port’: "INTERFACE": { "Ethernet0|10.2.2.1/24": {}, "Ethernet0|fc00:2:1::1/64": {}, "Ethernet4|10.2.1.1/24": {}, "Ethernet4|fc00:2:2::1/64": {}, "Ethernet121|20.20.20.1/24": {} <<<<——— inexistent interface }, admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json Interface Ethernet121 not found in PORT table. Invalid configuration detected. No configuration changes processed. Exiting... <—- Problem fixed after eliminating invalid config entry: admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json admin@lnos-x1-a-csw02:~$ <-— Testcase 2) Adding an inexistent port as a VLAN member: "VLAN": { "Vlan100": { "vlanid": "100", "admin_status": "up", "description": "Data Traffic", "members": [ "Ethernet16", "Ethernet17" <<<<—— inexistent port ], "mtu": "9100" } }, admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json VLAN member Ethernet17 not found in PORT table. Invalid configuration detected. No configuration changes processed. Exiting... <—- Problem fixed after eliminating invalid config entry: admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json admin@lnos-x1-a-csw02:~$ <—- Testcase 3) Adding a VLAN_INTERFACE for an inexistent VLAN: "VLAN_INTERFACE": { "Vlan100|9.1.1.2/24": { "scope": "global", "family": "IPv4" }, "Vlan100|fc00:9:2::2/64": { "scope": "global", "family": "IPv6" }, "Vlan101|9.1.1.2/24": { <<<<—— VLAN101 not defined in VLANS section "scope": "global", "family": "IPv4" } }, admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json Vlan interface Vlan101 not found in VLAN table. Invalid configuration detected. No configuration changes processed. Exiting... <—- Problem fixed after eliminating invalid config entry: admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json admin@lnos-x1-a-csw02:~$ <—- Testcase 4) Adding inexistent port for an neighbor entry: "DEVICE_NEIGHBOR": { "Ethernet0": { "name": "ARISTA01T2", "port": "Ethernet1" }, "Ethernet2": { "name": "ARISTA02T2", "port": "Ethernet1" }, "Ethernet4": { "name": "ARISTA03T2", "port": "Ethernet1" }, "Ethernet5": { <<<<—— Inexistent port "name": "ARISTA04T2", "port": "Ethernet1" } }, admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json DEVICE_NEIGHBOR port Ethernet5 not found in PORT table. Invalid configuration detected. No configuration changes processed. Exiting... <—- Problem fixed after eliminating invalid config entry: admin@lnos-x1-a-csw02:~$ /usr/local/bin/sonic-cfggen -j ~/config_db.json --check-json admin@lnos-x1-a-csw02:~$
@taoyl-ms , to review |
taoyl-ms
approved these changes
Aug 7, 2018
Thanks @rodnymolina for the contribution! Would you like to merge the latest master and resolve the conflict? |
It's better to validate by SONiC Yang models. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I'm adding some sanity-checking logic to prevent semantically-incorrect entries, present in any given config_db.json file, from being able to make it to sonic backends. This should tackle various issues observed in the past where a user could easily bring a system down or to an inconsistent state by introducing erroneous configuration while manually editing a config_db.json file.
To exercise this logic, user can either make use of the "--check-json" parameter offered by 'sonic-cfggen' (see examples below), or rely on the typical "config load/reload" CLI instructions. The changes associated to the second option will come as part of a different PR (in sonic-utilities repo).
Find some examples below of how this code operates:
<—- Tescase 1) Adding ‘interface’ associated to invalid ‘port’:
<—- Problem fixed after eliminating invalid config entry:
<-— Testcase 2) Adding an inexistent port as a VLAN member:
<—- Problem fixed after eliminating invalid config entry:
<—- Testcase 3) Adding a VLAN_INTERFACE for an inexistent VLAN:
<—- Problem fixed after eliminating invalid config entry:
<—- Testcase 4) Adding inexistent port for an neighbor entry:
<—- Problem fixed after eliminating invalid config entry: