Skip to content

Commit

Permalink
[sonic-yang-models/yang-models/sonic-acl.yang]: Make type mandatory a… (
Browse files Browse the repository at this point in the history
zhenggen-xu#80)

* [sonic-yang-models/yang-models/sonic-acl.yang]: Make type mandatory and add default value of stage.

Changes:
-- Make type mandatory and add default value of stage.
-- Test case.
-- Support for Verification in data tree.
Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
  • Loading branch information
Praveen Chaudhary committed Oct 9, 2020
1 parent f7ee983 commit 8bb9864
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ def __init__(self, tests, yangDir, jsonFile):
'INCORRECT_VLAN_NAME': {
'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.',
'eStr': self.defaultYANGFailure['Pattern']
},
'ACL_TABLE_MANDATORY_TYPE': {
'desc': 'ACL_TABLE MANDATORY TYPE FIELD.',
'eStr': self.defaultYANGFailure['Mandatory'] + ['type'] + ['ACL_TABLE']
},
'ACL_TABLE_DEFAULT_VALUE_STAGE': {
'desc': 'ACL_TABLE DEFAULT VALUE FOR STAGE FIELD.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4']/stage",
'key': 'sonic-acl:stage',
'value': 'INGRESS'
}
}
}

Expand Down Expand Up @@ -216,12 +228,34 @@ def logStartTest(self, desc):

"""
Load Config Data and return Exception as String
Parameters:
jInput (dict): input config to load.
verify (dict): contains xpath, key and value. This is used to verify,
that node tree at xpath contains correct key and value.
Example:
'verify': {'xpath': "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST\
[ACL_TABLE_NAME='NO-NSW-PACL-V4']/stage",
'key': 'sonic-acl:stage',
'value': 'INGRESS'
}
"""
def loadConfigData(self, jInput):
def loadConfigData(self, jInput, verify=None):
s = ""
try:
node = self.ctx.parse_data_mem(jInput, ly.LYD_JSON, \
ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT)
# verify the data tree if asked
if verify is not None:
xpath = verify['xpath']
set = node.find_path(xpath)
for dnode in set.data():
if (xpath == dnode.path()):
data = dnode.print_mem(ly.LYD_JSON, ly.LYP_WITHSIBLINGS \
| ly.LYP_FORMAT | ly.LYP_WD_ALL)
data = json.loads(data)
assert (data[verify['key']] == verify['value'])
s = 'verified'
except Exception as e:
s = str(e)
log.debug(s)
Expand All @@ -236,7 +270,7 @@ def runExceptionTest(self, test):
self.logStartTest(desc)
jInput = self.readJsonInput(test)
# load the data, expect a exception with must condition failure
s = self.loadConfigData(jInput)
s = self.loadConfigData(jInput, self.ExceptionTests[test].get('verify'))
eStr = self.ExceptionTests[test]['eStr']
log.debug(eStr)
if len(eStr) == 0 and s != "":
Expand Down
27 changes: 26 additions & 1 deletion src/sonic-yang-models/tests/yang_model_tests/yangTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,30 @@
}
},

"ACL_TABLE_MANDATORY_TYPE": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_TABLE": {
"ACL_TABLE_LIST": [{
"ACL_TABLE_NAME": "NO-NSW-PACL-V4",
"policy_desc": "Filter IPv4",
"stage": "EGRESS"
}]
}
}
},

"ACL_TABLE_DEFAULT_VALUE_STAGE": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_TABLE": {
"ACL_TABLE_LIST": [{
"ACL_TABLE_NAME": "NO-NSW-PACL-V4",
"policy_desc": "Filter IPv4",
"type": "L3"
}]
}
}
},

"ACL_RULE_WRONG_INNER_ETHER_TYPE": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_RULE": {
Expand Down Expand Up @@ -1196,7 +1220,8 @@
"Ethernet26",
"Ethernet27",
"Ethernet24"
]
],
"stage": "INGRESS"
},
"V6-ACL-TBLE": {
"type": "L3V6",
Expand Down
2 changes: 2 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-acl.yang
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ module sonic-acl {
}

leaf type {
mandatory true;
type stypes:acl_table_type;
}

Expand All @@ -260,6 +261,7 @@ module sonic-acl {
enum INGRESS;
enum EGRESS;
}
default INGRESS;
}

leaf-list ports {
Expand Down

0 comments on commit 8bb9864

Please sign in to comment.