Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-vlan.yang]: Correct Pattern for VLAN. #5165

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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