Skip to content

Commit

Permalink
[sonic-vlan.yang]: Correct Pattern for VLAN. (#5165)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Praveen Chaudhary committed Aug 15, 2020
1 parent df11f17 commit 32539a1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
54 changes: 51 additions & 3 deletions src/sonic-yang-models/tests/yang_model_tests/yangModelTesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -224,14 +239,47 @@ 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:
printExceptionDetails()
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

"""
Expand Down
35 changes: 35 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/yangTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -484,6 +516,7 @@
"PORT_LIST": [{
"port_name": "Ethernet8",
"alias": "eth8",
"lanes": "65",
"description": "Ethernet8",
"speed": 25000,
"mtu": 9000,
Expand All @@ -492,6 +525,7 @@
{
"port_name": "Ethernet9",
"alias": "eth9",
"lanes": "71",
"description": "Ethernet9",
"speed": 25000,
"mtu": 9000,
Expand Down Expand Up @@ -520,6 +554,7 @@
"PORT_LIST": [{
"port_name": "Ethernet8",
"alias": "eth8",
"lanes": "65",
"description": "Ethernet8",
"speed": 25000,
"mtu": 9000,
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-yang-models/yang-models/sonic-vlan.yang
Original file line number Diff line number Diff line change
Expand Up @@ -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])';
}
}

Expand Down

0 comments on commit 32539a1

Please sign in to comment.