[sonic-yang]: Yang model update fields (#5577)

Changes:
-- ACL stage allow lower and upper.
-- ACL include services leaf-list.
-- PORT include pfc_asym leaf.
-- PORT fec alloe none as per code.
-- 3 Tests for above changes.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
This commit is contained in:
Praveen Chaudhary 2020-11-05 00:25:33 -08:00 committed by GitHub
parent ce6286eb84
commit 1f9132db60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 227 additions and 12 deletions

View File

@ -61,6 +61,10 @@ class YangModelTesting:
'desc': 'Configure a member port in VLAN_MEMBER table which does not exist.', 'desc': 'Configure a member port in VLAN_MEMBER table which does not exist.',
'eStr': self.defaultYANGFailure['LeafRef'] 'eStr': self.defaultYANGFailure['LeafRef']
}, },
'PORT_CHANNEL_TEST': {
'desc': 'Configure a member port in PORT_CHANNEL table.',
'eStr': self.defaultYANGFailure['None']
},
'VLAN_MEMEBER_WITH_NON_EXIST_VLAN': { 'VLAN_MEMEBER_WITH_NON_EXIST_VLAN': {
'desc': 'Configure vlan-id in VLAN_MEMBER table which does not exist in VLAN table.', 'desc': 'Configure vlan-id in VLAN_MEMBER table which does not exist in VLAN table.',
'eStr': self.defaultYANGFailure['LeafRef'] 'eStr': self.defaultYANGFailure['LeafRef']
@ -123,7 +127,47 @@ class YangModelTesting:
}, },
'INCORRECT_VLAN_NAME': { 'INCORRECT_VLAN_NAME': {
'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.', 'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.',
'eStr': self.defaultYANGFailure['Pattern'] 'eStr': self.defaultYANGFailure['Pattern'] + ["Vlan"]
},
'ACL_TABLE_MANDATORY_TYPE': {
'desc': 'ACL_TABLE MANDATORY TYPE FIELD.',
'eStr': self.defaultYANGFailure['Mandatory'] + ['type'] + ['ACL_TABLE']
},
'ACL_TABLE_DEFAULT_VALUE_STAGE': {
'desc': 'ACL_TABLE DEFAULT VALUE FOR STAGE FIELD.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4']/ACL_TABLE_NAME",
'key': 'sonic-acl:stage',
'value': 'INGRESS'
}
},
'INCORRECT_VLAN_NAME': {
'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.',
'eStr': self.defaultYANGFailure['Pattern'] + ["Vlan"]
},
'PORT_CHANNEL_WRONG_PATTERN': {
'desc': 'INCORRECT PORTCHANNEL_NAME IN PORT_CHANNEL TABLE.',
'eStr': self.defaultYANGFailure['Pattern'] + ["PortChannel"]
},
'ACL_TABLE_STAGE_SERVICES': {
'desc': 'ACL_TABLE LOAD STAGE SERVICES SUCCESSFULLY.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4']/ACL_TABLE_NAME",
'key': 'sonic-acl:services',
'value': ["SNMP"]
}
},
'PORT_TEST': {
'desc': 'LOAD PORT TABLE WITH FEC AND PFC_ASYM SUCCESSFULLY. VERIFY PFC_ASYM.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': "/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet8']/port_name",
'key': 'sonic-port:pfc_asym',
'value': 'on'
}
},
'PORT_NEG_TEST': {
'desc': 'LOAD PORT TABLE FEC PATTERN FAILURE',
'eStr': self.defaultYANGFailure['Pattern'] + ['rc']
} }
} }
@ -200,7 +244,7 @@ class YangModelTesting:
jInst = ijson.items(f, test) jInst = ijson.items(f, test)
for it in jInst: for it in jInst:
jInput = jInput + json.dumps(it) jInput = jInput + json.dumps(it)
log.debug(jInput) log.debug("Read json JIn: {}".format(jInput))
except Exception as e: except Exception as e:
printExceptionDetails() printExceptionDetails()
return jInput return jInput
@ -216,12 +260,37 @@ class YangModelTesting:
""" """
Load Config Data and return Exception as String Load Config Data and return Exception as String
Parameters:
jInput (dict): input config to load.
verify (dict): contains xpath, key and value. This is used to verify,
that node tree at xpath contains correct key and value.
Example:
'verify': {'xpath': "/sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST\
[ACL_TABLE_NAME='NO-NSW-PACL-V4']/stage",
'key': 'sonic-acl:stage',
'value': 'INGRESS'
}
""" """
def loadConfigData(self, jInput): def loadConfigData(self, jInput, verify=None):
s = "" s = ""
try: try:
node = self.ctx.parse_data_mem(jInput, ly.LYD_JSON, \ node = self.ctx.parse_data_mem(jInput, ly.LYD_JSON, \
ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT)
# verify the data tree if asked
if verify is not None:
xpath = verify['xpath']
log.debug("Verify xpath: {}".format(xpath))
set = node.find_path(xpath)
for dnode in set.data():
if (xpath == dnode.path()):
log.debug("Verify dnode: {}".format(dnode.path()))
data = dnode.print_mem(ly.LYD_JSON, ly.LYP_WITHSIBLINGS \
| ly.LYP_FORMAT | ly.LYP_WD_ALL)
data = json.loads(data)
log.debug("Verify data: {}".format(data))
assert (data[verify['key']] == verify['value'])
s = 'verified'
except Exception as e: except Exception as e:
s = str(e) s = str(e)
log.debug(s) log.debug(s)
@ -236,9 +305,9 @@ class YangModelTesting:
self.logStartTest(desc) self.logStartTest(desc)
jInput = self.readJsonInput(test) jInput = self.readJsonInput(test)
# load the data, expect a exception with must condition failure # load the data, expect a exception with must condition failure
s = self.loadConfigData(jInput) s = self.loadConfigData(jInput, self.ExceptionTests[test].get('verify'))
eStr = self.ExceptionTests[test]['eStr'] eStr = self.ExceptionTests[test]['eStr']
log.debug(eStr) log.debug("eStr: {}".format(eStr))
if len(eStr) == 0 and s != "": if len(eStr) == 0 and s != "":
raise Exception("{} in not empty".format(s)) raise Exception("{} in not empty".format(s))
elif (sum(1 for str in eStr if str not in s) == 0): elif (sum(1 for str in eStr if str not in s) == 0):

View File

@ -108,6 +108,47 @@
} }
}, },
"PORT_CHANNEL_TEST": {
"sonic-portchannel:sonic-portchannel": {
"sonic-portchannel:PORTCHANNEL": {
"PORTCHANNEL_LIST": [{
"portchannel_name": "PortChannel0001",
"admin_status": "up",
"members": [
"Ethernet0"
],
"min_links": "1",
"mtu": "9100"
}]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"port_name": "Ethernet0",
"alias": "eth0",
"description": "Ethernet0",
"speed": 25000,
"mtu": 9000,
"lanes": "65",
"admin_status": "up"
}]
}
}
},
"PORT_CHANNEL_WRONG_PATTERN": {
"sonic-portchannel:sonic-portchannel": {
"sonic-portchannel:PORTCHANNEL": {
"PORTCHANNEL_LIST": [{
"portchannel_name": "PortChannel11001",
"admin_status": "up",
"mtu": "9100"
}]
}
}
},
"VLAN_MEMEBER_WITH_NON_EXIST_VLAN": { "VLAN_MEMEBER_WITH_NON_EXIST_VLAN": {
"sonic-vlan:sonic-vlan": { "sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN_MEMBER": { "sonic-vlan:VLAN_MEMBER": {
@ -557,6 +598,7 @@
"lanes": "65", "lanes": "65",
"description": "Ethernet8", "description": "Ethernet8",
"speed": 25000, "speed": 25000,
"fec": "rs",
"mtu": 9000, "mtu": 9000,
"admin_status": "up" "admin_status": "up"
}] }]
@ -564,6 +606,42 @@
} }
}, },
"PORT_TEST": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"port_name": "Ethernet8",
"alias": "eth8",
"lanes": "65",
"description": "Ethernet8",
"speed": 25000,
"fec": "rs",
"mtu": 9000,
"admin_status": "up",
"pfc_asym": "on"
}]
}
}
},
"PORT_NEG_TEST": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"port_name": "Ethernet8",
"alias": "eth8",
"lanes": "65",
"description": "Ethernet8",
"speed": 25000,
"fec": "rc",
"mtu": 9000,
"admin_status": "up",
"pfc_asym": "off"
}]
}
}
},
"ACL_RULE_ARP_TYPE_ICMPV6_CODE_MISMATCH": { "ACL_RULE_ARP_TYPE_ICMPV6_CODE_MISMATCH": {
"sonic-acl:sonic-acl": { "sonic-acl:sonic-acl": {
"sonic-acl:ACL_RULE": { "sonic-acl:ACL_RULE": {
@ -612,6 +690,43 @@
} }
}, },
"ACL_TABLE_MANDATORY_TYPE": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_TABLE": {
"ACL_TABLE_LIST": [{
"ACL_TABLE_NAME": "NO-NSW-PACL-V4",
"policy_desc": "Filter IPv4",
"stage": "EGRESS"
}]
}
}
},
"ACL_TABLE_DEFAULT_VALUE_STAGE": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_TABLE": {
"ACL_TABLE_LIST": [{
"ACL_TABLE_NAME": "NO-NSW-PACL-V4",
"policy_desc": "Filter IPv4",
"type": "L3"
}]
}
}
},
"ACL_TABLE_STAGE_SERVICES": {
"sonic-acl:sonic-acl": {
"sonic-acl:ACL_TABLE": {
"ACL_TABLE_LIST": [{
"ACL_TABLE_NAME": "NO-NSW-PACL-V4",
"policy_desc": "Filter IPv4",
"type": "L3",
"stage": "ingress",
"services": ["SNMP"]
}]
}
}
},
"ACL_RULE_WRONG_INNER_ETHER_TYPE": { "ACL_RULE_WRONG_INNER_ETHER_TYPE": {
"sonic-acl:sonic-acl": { "sonic-acl:sonic-acl": {
"sonic-acl:ACL_RULE": { "sonic-acl:ACL_RULE": {
@ -661,6 +776,24 @@
}, },
"SAMPLE_CONFIG_DB_JSON": { "SAMPLE_CONFIG_DB_JSON": {
"PORTCHANNEL": {
"PortChannel0003": {
"admin_status": "up",
"min_links": "1",
"members": [
"Ethernet1"
],
"mtu": "9100"
},
"PortChannel0004": {
"admin_status": "up",
"min_links": "1",
"members": [
"Ethernet2"
],
"mtu": "9100"
}
},
"VLAN_INTERFACE": { "VLAN_INTERFACE": {
"Vlan111": {}, "Vlan111": {},
"Vlan777": {}, "Vlan777": {},
@ -1196,7 +1329,9 @@
"Ethernet26", "Ethernet26",
"Ethernet27", "Ethernet27",
"Ethernet24" "Ethernet24"
] ],
"stage": "INGRESS",
"services": ["SNMP", "SSH"]
}, },
"V6-ACL-TBLE": { "V6-ACL-TBLE": {
"type": "L3V6", "type": "L3V6",

View File

@ -252,14 +252,19 @@ module sonic-acl {
} }
leaf type { leaf type {
mandatory true;
type stypes:acl_table_type; type stypes:acl_table_type;
} }
leaf stage { leaf stage {
type enumeration { type string {
enum INGRESS; pattern "ingress|egress|INGRESS|EGRESS";
enum EGRESS;
} }
default "INGRESS";
}
leaf-list services {
type string;
} }
leaf-list ports { leaf-list ports {

View File

@ -93,7 +93,13 @@ module sonic-port{
leaf fec { leaf fec {
type string { type string {
pattern "rc|fc|None"; pattern "rs|fc|none";
}
}
leaf pfc_asym {
type string {
pattern "on|off";
} }
} }
} /* end of list PORT_LIST */ } /* end of list PORT_LIST */

View File

@ -43,9 +43,9 @@ module sonic-portchannel {
key "portchannel_name"; key "portchannel_name";
ext:key-regex-configdb-to-yang "^(Ethernet[0-9]+)$"; ext:key-regex-configdb-to-yang "^(PortChannel[0-9]{1,4})$";
ext:key-regex-yang-to-configdb "<port_name>"; ext:key-regex-yang-to-configdb "<portchannel_name>";
leaf portchannel_name { leaf portchannel_name {
type string { type string {