From 0f85026d1ee87dbe39be3163e53984a73518f55a Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Sun, 28 Jun 2020 21:07:07 -0700 Subject: [PATCH] =?UTF-8?q?[sonic-yang-models/yang-models/sonic-acl.yang]:?= =?UTF-8?q?=20Make=20type=20mandatory=20a=E2=80=A6=20(#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 * [yang_model_tests/yangModelTesting.py]: Adding Description. Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com RB= G=lnos-reviewers R=pchaudhary,pmao,rmolina,samaity,sfardeen,zxu A= --- .../yang_model_tests/yangModelTesting.py | 40 ++++++++++++++++++- .../tests/yang_model_tests/yangTest.json | 27 ++++++++++++- .../yang-models/sonic-acl.yang | 2 + 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py b/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py index d36416adcae7..286eefcc6fac 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py +++ b/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py @@ -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': [''] } @@ -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' + } } } @@ -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) @@ -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): diff --git a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json index 668559649803..c4221d169c71 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -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": { @@ -1116,7 +1140,8 @@ "Ethernet26", "Ethernet27", "Ethernet24" - ] + ], + "stage": "INGRESS" }, "V6-ACL-TBLE": { "type": "L3V6", diff --git a/src/sonic-yang-models/yang-models/sonic-acl.yang b/src/sonic-yang-models/yang-models/sonic-acl.yang index a0155e69e417..3709f81a2250 100644 --- a/src/sonic-yang-models/yang-models/sonic-acl.yang +++ b/src/sonic-yang-models/yang-models/sonic-acl.yang @@ -256,6 +256,7 @@ module sonic-acl { } leaf type { + mandatory true; type head:acl_table_type; } @@ -264,6 +265,7 @@ module sonic-acl { enum INGRESS; enum EGRESS; } + default INGRESS; } leaf-list ports {