From 32539a1bda748c729f23f43788861fea18450c10 Mon Sep 17 00:00:00 2001 From: Praveen Chaudhary Date: Sat, 15 Aug 2020 12:38:15 -0700 Subject: [PATCH] [sonic-vlan.yang]: Correct Pattern for VLAN. (#5165) Changes: -- Correct Pattern for VLAN. -- Add Special Test support. -- Add first special test to load VLAN 1-4094. -- Add lanes in ports. -- Make Sure None test gets no output from libyang while config load. [yangModelTesting.py]: INCORRECT VLAN_NAME FIELD IN VLAN TABLE test. Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com --- .../yang_model_tests/yangModelTesting.py | 54 +++++++++++++++++-- .../tests/yang_model_tests/yangTest.json | 35 ++++++++++++ .../yang-models/sonic-vlan.yang | 2 +- 3 files changed, 87 insertions(+), 4 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 d36416adca..e1b106a17a 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py +++ b/src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py @@ -43,7 +43,9 @@ class YangModelTesting: 'LeafRef': ['Leafref', 'non-existing'], 'When': ['When condition', 'not satisfied'], 'Pattern': ['pattern', 'does not satisfy'], - 'None': [''] + 'Mandatory': ['required element', 'Missing'], + 'Verify': ['verified'], + 'None': [] } self.ExceptionTests = { @@ -118,12 +120,23 @@ class YangModelTesting: 'LOOPBACK_IPPREFIX_PORT_MUST_CONDITION_FALSE': { 'desc': 'Loopback Ip-prefix port-name must condition failure.', 'eStr': self.defaultYANGFailure['Must'] + }, + 'INCORRECT_VLAN_NAME': { + 'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.', + 'eStr': self.defaultYANGFailure['Pattern'] + } + } + + self.SpecialTests = { + 'ALL_VLAN_TEST': { + 'desc': 'VLAN TEST.', + 'eStr': self.defaultYANGFailure['None'] } } self.tests = tests if (self.tests == None): - self.tests = self.ExceptionTests.keys() + self.tests = self.ExceptionTests.keys()+self.SpecialTests.keys() self.yangDir = yangDir self.jsonFile = jsonFile self.testNum = 1 @@ -166,6 +179,8 @@ class YangModelTesting: test = test.strip() if test in self.ExceptionTests: ret = ret + self.runExceptionTest(test); + elif test in self.SpecialTests: + ret = ret + self.runSpecialTest(test); except Exception as e: printExceptionDetails() raise e @@ -224,7 +239,9 @@ class YangModelTesting: s = self.loadConfigData(jInput) eStr = self.ExceptionTests[test]['eStr'] log.debug(eStr) - if (sum(1 for str in eStr if str not in s) == 0): + if len(eStr) == 0 and s != "": + raise Exception("{} in not empty".format(s)) + elif (sum(1 for str in eStr if str not in s) == 0): log.info(desc + " Passed\n") return PASS except Exception as e: @@ -232,6 +249,37 @@ class YangModelTesting: log.info(desc + " Failed\n") return FAIL + """ + Run Special Tests + """ + def runSpecialTest(self, test): + try: + if test == 'ALL_VLAN_TEST': + return self.runVlanSpecialTest(test); + except Exception as e: + printExceptionDetails() + log.info(desc + " Failed\n") + return FAIL + + def runVlanSpecialTest(self, test): + try: + desc = self.SpecialTests[test]['desc'] + self.logStartTest(desc) + jInput = json.loads(self.readJsonInput(test)) + # check all Vlan from 1 to 4094 + for i in xrange(4095): + vlan = 'Vlan'+str(i) + jInput["sonic-vlan:sonic-vlan"]["sonic-vlan:VLAN"]["VLAN_LIST"]\ + [0]["vlan_name"] = vlan + log.debug(jInput) + s = self.loadConfigData(json.dumps(jInput)) + if s!="": + raise Exception("{} in not empty".format(s)) + return PASS + except Exception as e: + printExceptionDetails() + log.info(desc + " Failed\n") + return FAIL # End of Class """ 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 2f85d0259b..b42d1cf24c 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/yangTest.json +++ b/src/sonic-yang-models/tests/yang_model_tests/yangTest.json @@ -37,6 +37,38 @@ } }, + "ALL_VLAN_TEST": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [{ + "vlan_name": "Vlan1-4094", + "description": "server_vlan", + "dhcp_servers": [ + "10.186.72.56" + ], + "mtu": "9100", + "admin_status": "up" + }] + } + } + }, + + "INCORRECT_VLAN_NAME": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [{ + "vlan_name": "Vlan8090", + "description": "server_vlan", + "dhcp_servers": [ + "10.186.72.56" + ], + "mtu": "9100", + "admin_status": "up" + }] + } + } + }, + "VLAN_WITH_NON_EXIST_PORT": { "sonic-vlan:sonic-vlan": { "sonic-vlan:VLAN_MEMBER": { @@ -484,6 +516,7 @@ "PORT_LIST": [{ "port_name": "Ethernet8", "alias": "eth8", + "lanes": "65", "description": "Ethernet8", "speed": 25000, "mtu": 9000, @@ -492,6 +525,7 @@ { "port_name": "Ethernet9", "alias": "eth9", + "lanes": "71", "description": "Ethernet9", "speed": 25000, "mtu": 9000, @@ -520,6 +554,7 @@ "PORT_LIST": [{ "port_name": "Ethernet8", "alias": "eth8", + "lanes": "65", "description": "Ethernet8", "speed": 25000, "mtu": 9000, diff --git a/src/sonic-yang-models/yang-models/sonic-vlan.yang b/src/sonic-yang-models/yang-models/sonic-vlan.yang index 4c3aecaf81..d05d2a39e6 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan.yang @@ -128,7 +128,7 @@ module sonic-vlan { leaf vlan_name { type string { - pattern 'Vlan([0-9]{1,3}|[0-3][0-9]{4}|[4][0][0-8][0-9]|[4][0][9][0-4])'; + pattern 'Vlan([0-9]{1,3}|[1-3][0-9]{3}|[4][0][0-8][0-9]|[4][0][9][0-4])'; } }