[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
This commit is contained in:
Praveen Chaudhary 2020-08-15 12:38:15 -07:00 committed by GitHub
parent df11f17843
commit 32539a1bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 4 deletions

View File

@ -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
"""

View File

@ -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,

View File

@ -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])';
}
}