[yang] Fix yang validation failure when table contains empty value (#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
This commit is contained in:
parent
8cd346d80b
commit
d83ae1e3dc
@ -591,18 +591,23 @@ class SonicYangExtMixin:
|
|||||||
"""
|
"""
|
||||||
def _xlateContainerInContainer(self, model, yang, configC, table):
|
def _xlateContainerInContainer(self, model, yang, configC, table):
|
||||||
ccontainer = model
|
ccontainer = model
|
||||||
#print(ccontainer['@name'])
|
ccName = ccontainer['@name']
|
||||||
yang[ccontainer['@name']] = dict()
|
yang[ccName] = dict()
|
||||||
if not configC.get(ccontainer['@name']):
|
if ccName not in configC:
|
||||||
|
# Inner container doesn't exist in config
|
||||||
return
|
return
|
||||||
self.sysLog(msg="xlateProcessListOfContainer: {}".format(ccontainer['@name']))
|
if len(configC[ccName]) == 0:
|
||||||
self._xlateContainer(ccontainer, yang[ccontainer['@name']], \
|
# Empty container, clean config and return
|
||||||
configC[ccontainer['@name']], table)
|
del configC[ccName]
|
||||||
|
return
|
||||||
|
self.sysLog(msg="xlateProcessListOfContainer: {}".format(ccName))
|
||||||
|
self._xlateContainer(ccontainer, yang[ccName], \
|
||||||
|
configC[ccName], table)
|
||||||
# clean empty container
|
# clean empty container
|
||||||
if len(yang[ccontainer['@name']]) == 0:
|
if len(yang[ccName]) == 0:
|
||||||
del yang[ccontainer['@name']]
|
del yang[ccName]
|
||||||
# remove copy after processing
|
# remove copy after processing
|
||||||
del configC[ccontainer['@name']]
|
del configC[ccName]
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -364,5 +364,20 @@ class Test_SonicYang(object):
|
|||||||
|
|
||||||
return
|
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):
|
def teardown_class(self):
|
||||||
pass
|
pass
|
||||||
|
@ -304,7 +304,7 @@
|
|||||||
"switch_id": "2",
|
"switch_id": "2",
|
||||||
"switch_type": "voq",
|
"switch_type": "voq",
|
||||||
"max_cores": "8",
|
"max_cores": "8",
|
||||||
"sub_role": "FrondEnd",
|
"sub_role": "FrontEnd",
|
||||||
"dhcp_server": "disabled"
|
"dhcp_server": "disabled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1694,5 +1694,11 @@
|
|||||||
"UNKNOWN_TABLE": {
|
"UNKNOWN_TABLE": {
|
||||||
"Error": "This Table is for testing, This Table does not have YANG models."
|
"Error": "This Table is for testing, This Table does not have YANG models."
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"SAMPLE_CONFIG_DB_SPECIAL_CASE": {
|
||||||
|
"TACPLUS": {
|
||||||
|
"global": {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ module sonic-device_metadata {
|
|||||||
|
|
||||||
leaf sub_role {
|
leaf sub_role {
|
||||||
type string;
|
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 {
|
leaf downstream_subrole {
|
||||||
|
Loading…
Reference in New Issue
Block a user