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..e1b106a17a3f 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 @@ def __init__(self, tests, yangDir, jsonFile): '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 @@ 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'] + }, + '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 @@ def run(self): 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 @@ def runExceptionTest(self, test): 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 @@ def runExceptionTest(self, test): 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 2f85d0259bfa..b42d1cf24cf2 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 4c3aecaf8106..d05d2a39e6d8 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])'; } }