Skip to content

Commit

Permalink
[yang] Fix yang validation failure when table contains empty value (#…
Browse files Browse the repository at this point in the history
…10431)

Why I did it
Fix #9746

How I did it
Split the check condition based on non-exist and zero length.

How to verify it
Run verification script when table contains empty value
  • Loading branch information
wen587 authored Apr 7, 2022
1 parent 8cd346d commit d83ae1e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/sonic-yang-mgmt/sonic_yang_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,23 @@ def _xlateListInContainer(self, model, yang, configC, table, exceptionList):
"""
def _xlateContainerInContainer(self, model, yang, configC, table):
ccontainer = model
#print(ccontainer['@name'])
yang[ccontainer['@name']] = dict()
if not configC.get(ccontainer['@name']):
ccName = ccontainer['@name']
yang[ccName] = dict()
if ccName not in configC:
# Inner container doesn't exist in config
return
self.sysLog(msg="xlateProcessListOfContainer: {}".format(ccontainer['@name']))
self._xlateContainer(ccontainer, yang[ccontainer['@name']], \
configC[ccontainer['@name']], table)
if len(configC[ccName]) == 0:
# Empty container, clean config and return
del configC[ccName]
return
self.sysLog(msg="xlateProcessListOfContainer: {}".format(ccName))
self._xlateContainer(ccontainer, yang[ccName], \
configC[ccName], table)
# clean empty container
if len(yang[ccontainer['@name']]) == 0:
del yang[ccontainer['@name']]
if len(yang[ccName]) == 0:
del yang[ccName]
# remove copy after processing
del configC[ccontainer['@name']]
del configC[ccName]

return

Expand Down
15 changes: 15 additions & 0 deletions src/sonic-yang-mgmt/tests/libyang-python-tests/test_sonic_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,20 @@ def test_table_with_no_yang(self, sonic_yang_data):

return

def test_special_json_with_yang(self, sonic_yang_data):
# in this test, we validate unusual json config and check if
# loadData works successfully
test_file = sonic_yang_data['test_file']
syc = sonic_yang_data['syc']

# read config
jIn = self.readIjsonInput(test_file, 'SAMPLE_CONFIG_DB_SPECIAL_CASE')
jIn = json.loads(jIn)

# load config and create Data tree
syc.loadData(jIn)

return

def teardown_class(self):
pass
8 changes: 7 additions & 1 deletion src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"switch_id": "2",
"switch_type": "voq",
"max_cores": "8",
"sub_role": "FrondEnd",
"sub_role": "FrontEnd",
"dhcp_server": "disabled"
}
},
Expand Down Expand Up @@ -1694,5 +1694,11 @@
"UNKNOWN_TABLE": {
"Error": "This Table is for testing, This Table does not have YANG models."
}
},
"SAMPLE_CONFIG_DB_SPECIAL_CASE": {
"TACPLUS": {
"global": {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"TACPLUS_INVALID_TIMEOUT_TEST": {
"desc": "Tacplus global configuration with invalid timeout value in TACPLUS table.",
"eStr": "TACACS timeout must be 1..60"
"eStr": "TACACS timeout must be 1..60"
},
"TACPLUS_NOT_PRESENT_SRC_INTF_TEST": {
"desc": "Tacplus global configuration with a non existent port in TACPLUS table.",
Expand All @@ -15,7 +15,7 @@
},
"TACPLUS_SERVER_INVALID_PRIORITY_TEST": {
"desc": "Tacplus server configuration with invalid priority value in TACPLUS_SERVER table.",
"eStr": "TACACS server priority must be 1..64"
"eStr": "TACACS server priority must be 1..64"
},
"TACPLUS_SERVER_INVALID_TIMEOUT_TEST" : {
"desc": "Tacplus server configuration with invalid timeout value in TACPLUS_SERVER table.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module sonic-device_metadata {

leaf sub_role {
type string;
description "sub_role indicates if ASIC is FrondEnd or BackEnd.";
description "sub_role indicates if ASIC is FrontEnd or BackEnd.";
}

leaf downstream_subrole {
Expand Down

0 comments on commit d83ae1e

Please sign in to comment.