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
sonic-net#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 [email protected]

* [yang_model_tests/yangModelTesting.py]: Adding Description.

Signed-off-by: Praveen Chaudhary [email protected]
RB=
G=lnos-reviewers
R=pchaudhary,pmao,rmolina,samaity,sfardeen,zxu
A=
  • Loading branch information
Praveen Chaudhary authored Jun 29, 2020
1 parent 2a2705a commit 0f85026
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
40 changes: 38 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 @@ -43,6 +43,8 @@ def __init__(self, tests, yangDir, jsonFile):
'LeafRef': ['Leafref', 'non-existing'],
'When': ['When condition', 'not satisfied'],
'Pattern': ['pattern', 'does not satisfy'],
'Mandatory': ['required element', 'Missing'],
'Verify': ['verified'],
'None': ['']
}

Expand Down Expand Up @@ -118,6 +120,18 @@ def __init__(self, tests, yangDir, jsonFile):
'LOOPBACK_IPPREFIX_PORT_MUST_CONDITION_FALSE': {
'desc': 'Loopback Ip-prefix port-name must condition failure.',
'eStr': self.defaultYANGFailure['Must']
},
'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 @@ -201,12 +215,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 @@ -221,7 +257,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 (sum(1 for str in eStr if str not in s) == 0):
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 @@ -577,6 +577,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 @@ -1116,7 +1140,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 @@ -256,6 +256,7 @@ module sonic-acl {
}

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

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

leaf-list ports {
Expand Down

0 comments on commit 0f85026

Please sign in to comment.