Skip to content

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rodnymolina
Copy link
Contributor

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:~$

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:~$
@lguohan
Copy link
Collaborator

lguohan commented Aug 7, 2018

@taoyl-ms , to review

@qiluo-msft
Copy link
Collaborator

Thanks @rodnymolina for the contribution! Would you like to merge the latest master and resolve the conflict?

@qiluo-msft
Copy link
Collaborator

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants