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

[sonic-yang-models/yang-models/sonic-acl.yang]: Make type mandatory a… #80

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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 = ""
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
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'
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
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):
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
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