Skip to content
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

Fix yang validation failure when table contains empty value #10431

Merged
merged 5 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Collaborator

@praveen-li praveen-li Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFMI: Inner container does not exist in config.

# 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
2 changes: 1 addition & 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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[10:18 PM] Praveen Chaudhary
in this file: src/sonic-yang-models/tests/files/sample_config_db.json

[10:18 PM] Praveen Chaudhary
we need global {} config for test to exercise this code

[10:18 PM] Praveen Chaudhary
plz add that and we are good

"sub_role": "FrontEnd",
"dhcp_server": "disabled"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
},
"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.",
"eStrKey": "InvalidValue"
},
"TACPLUS_VERIFY_VALID_EMPTY_GLOBAL": {
"desc": "Tacplus valid empty global configuration in TACPLUS table."
},
"TACPLUS_SERVER_TEST" : {
"desc": "Tacplus server configuration in TACPLUS_SERVER table."
},
"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 @@ -52,6 +52,16 @@
}
},

"TACPLUS_VERIFY_VALID_EMPTY_GLOBAL": {
"sonic-system-tacacs:sonic-system-tacacs": {
"sonic-system-tacacs:TACPLUS": {
"global": {
}
}
}

},

"TACPLUS_SERVER_TEST": {
"sonic-system-tacacs:sonic-system-tacacs": {
"sonic-system-tacacs:TACPLUS_SERVER": {
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