Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
42 changes: 40 additions & 2 deletions src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ def initTest(self):
'None': []
}

<<<<<<< HEAD
self.ExceptionTests = { }

for test_file in glob("./tests/yang_model_tests/tests/*.json"):
try:
with open(test_file) as fp:
log.info("Loading file " + test_file)
data = json.load(fp)
for key, test in data.items():
eStr = []
if 'eStrKey' in test:
eStr = list(self.defaultYANGFailure[test['eStrKey']])
if 'eStr' in test:
eStr += list(test['eStr'])
test['eStr'] = eStr
log.debug("estr for " + key + " is " + str(eStr))
self.ExceptionTests[key] = test
except Exception as e:
log.error("Failed to load file " + test_file)
raise(e)
=======
self.ExceptionTests = {
Comment thread
joyas-joseph marked this conversation as resolved.
'WRONG_FAMILY_WITH_IP_PREFIX': {
'desc': 'Configure Wrong family with ip-prefix for VLAN_Interface Table',
Expand Down Expand Up @@ -347,6 +368,7 @@ def initTest(self):
'eStr': self.defaultYANGFailure['Pattern'] + ['wrong']
}
}
>>>>>>> d3fae0080e229b8026ce7adfcf58f5bbfb55d1bb

self.SpecialTests = {
'ALL_VLAN_TEST': {
Expand All @@ -357,7 +379,19 @@ def initTest(self):

self.tests = list(self.ExceptionTests.keys())+list(self.SpecialTests.keys())
self.yangDir = './yang-models/'
self.jsonFile = './tests/yang_model_tests/yangTest.json'
self.testFile = {}

for test_file in glob("./tests/yang_model_tests/tests_config/*.json"):
try:
with open(test_file) as fp:
log.info("Loading file " + test_file)
data = json.load(fp)
Comment thread
joyas-joseph marked this conversation as resolved.
for key in data:
self.testFile[key] = test_file
except Exception as e:
log.error("Failed to load file " + test_file)
raise(e)

self.testNum = 1
# other class vars
# self.ctx
Expand Down Expand Up @@ -397,7 +431,8 @@ def readJsonInput(self, test):
# this is to avoid loading very large JSON in memory
log.debug(" Read JSON Section: " + test)
jInput = ""
with open(self.jsonFile, 'rb') as f:
test_file = self.testFile[test]
Comment thread
joyas-joseph marked this conversation as resolved.
with open(test_file, 'rb') as f:
jInst = ijson.items(f, test)
for it in jInst:
jInput = jInput + json.dumps(it)
Expand Down Expand Up @@ -463,8 +498,11 @@ def runExceptionTest(self, test):
jInput = self.readJsonInput(test)
# load the data, expect a exception with must condition failure
s = self.loadConfigData(jInput, self.ExceptionTests[test].get('verify'))

eStr = self.ExceptionTests[test]['eStr']
log.debug("eStr: {}".format(eStr))
log.debug("s: {}".format(s))

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):
Expand Down
65 changes: 65 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/acl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"ACL_RULE_UNDEFINED_PACKET_ACTION": {
"desc": "Configure undefined packet_action in ACL_RULE table.",
"eStrKey" : "InvalidValue",
"eStr": ["PACKET_ACTION"]
},
"ACL_TABLE_EMPTY_PORTS": {
"desc": "Configure ACL_TABLE with empty ports."
},
"ACL_TABLE_UNDEFINED_TABLE_TYPE": {
"desc": "Configure undefined acl_table_type in ACL_TABLE table.",
"eStrKey" : "InvalidValue",
"eStr": ["type"]
},
"ACL_RULE_WITH_NON_EXIST_ACL_TABLE": {
"desc": "Configure non-existing ACL_TABLE in ACL_RULE.",
"eStrKey" : "LeafRef"
},
"ACL_RULE_IP_TYPE_SRC_IPV6_MISMATCH": {
"desc": "Configure IP_TYPE as ipv4any and SRC_IPV6 in ACL_RULE.",
"eStrKey" : "When",
"eStr": ["IP_TYPE"]
},
"ACL_RULE_ARP_TYPE_DST_IPV6_MISMATCH": {
"desc": "Configure IP_TYPE as ARP and DST_IPV6 in ACL_RULE.",
"eStrKey" : "When",
"eStr": ["IP_TYPE"]
},
"ACL_RULE_WRONG_L4_SRC_PORT_RANGE": {
"desc": "Configure l4_src_port_range as 99999-99999 in ACL_RULE",
"eStrKey" : "Pattern"
},
"ACL_RULE_ARP_TYPE_ICMPV6_CODE_MISMATCH": {
"desc": "Configure IP_TYPE as ARP and ICMPV6_CODE in ACL_RULE.",
"eStrKey" : "When",
"eStr": ["IP_TYPE"]
},
"ACL_RULE_WRONG_INNER_ETHER_TYPE": {
"desc": "Configure INNER_ETHER_TYPE as 0x080C in ACL_RULE.",
"eStrKey" : "Pattern"
},
"ACL_TABLE_MANDATORY_TYPE": {
"desc": "ACL_TABLE MANDATORY TYPE FIELD.",
"eStrKey" : "Mandatory",
"eStr": ["ACL_TABLE"]
},
"ACL_TABLE_DEFAULT_VALUE_STAGE": {
"desc": "ACL_TABLE DEFAULT VALUE FOR STAGE FIELD.",
"eStrKey" : "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"
}
},
"ACL_TABLE_STAGE_SERVICES": {
"desc": "ACL_TABLE LOAD STAGE SERVICES SUCCESSFULLY.",
"eStrKey" : "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"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"BREAKOUT_CFG_CORRECT_MODES": {
"desc": "BREAKOUT_CFG correct breakout modes"
},
"BREAKOUT_CFG_INCORRECT_MODES": {
"desc": "BREAKOUT_CFG wrong breakout modes",
"eStr": ["pattern", "does not satisfy"]
},
"CRM_BRK_CFG_FLEX_TABLE": {
"desc": "CRM BREAKOUT CFG FLEX COUNTER TABLE."
}
}
81 changes: 81 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/crm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"CRM_WITH_CORRECT_FREE_VALUE": {
Comment thread
joyas-joseph marked this conversation as resolved.
"desc": "CRM_WITH_CORRECT_FREE_VALUE no failure."
},
"CRM_WITH_CORRECT_USED_VALUE": {
"desc": "CRM_WITH_CORRECT_USED_VALUE no failure."
},
"CRM_WITH_WRONG_THRESHOLD_TYPE": {
"desc": "CRM_WITH_WRONG_THRESHOLD_TYPE pattern failure.",
"eStrKey": "Pattern",
"eStr": ["wrong" ]
},
"CRM_WITH_WRONG_PERCENTAGE": {
"desc": "CRM_WITH_WRONG_PERCENTAGE must condition failure.",
"eStrKey": "Must"
},
"CRM_WITH_HIGH_THRESHOLD_ERR": {
"desc": "CRM_WITH_HIGH_THRESHOLD_ERR must condition failure about high threshold being lower than low threshold.",
"eStr": ["high_threshold should be more than low_threshold"]
},
"CRM_WITH_CORRECT_USED_VALUE": {
"desc": "CRM_WITH_CORRECT_USED_VALUE no failure."
},
"SNAT_WITH_WRONG_PERCENTAGE": {
"desc": "SNAT_WITH_WRONG_PERCENTAGE must condition failure.",
"eStrKey": "Must"
},
"SNAT_WITH_HIGH_THRESHOLD_ERR": {
"desc": "SNAT_WITH_HIGH_THRESHOLD_ERR must condition failure about high threshold being lower than low threshold.",
"eStr": [ "high_threshold should be more than low_threshold" ]
},
"SNAT_WITH_CORRECT_FREE_VALUE": {
"desc": "SNAT_WITH_CORRECT_FREE_VALUE no failure."
},
"SNAT_WITH_CORRECT_USED_VALUE": {
"desc": "SNAT_WITH_CORRECT_USED_VALUE no failure."
},
"SNAT_WITH_WRONG_THRESHOLD_TYPE": {
"desc": "SNAT_WITH_WRONG_THRESHOLD_TYPE pattern failure.",
"eStrKey": "Pattern",
"eStr": ["wrong" ]
},
"DNAT_WITH_WRONG_PERCENTAGE": {
"desc": "DNAT_WITH_WRONG_PERCENTAGE must condition failure.",
"eStrKey": "Must"
},
"DNAT_WITH_HIGH_THRESHOLD_ERR": {
"desc": "DNAT_WITH_HIGH_THRESHOLD_ERR must condition failure about high threshold being lower than low threshold.",
"eStr": [ "high_threshold should be more than low_threshold" ]
},
"DNAT_WITH_CORRECT_FREE_VALUE": {
"desc": "DNAT_WITH_CORRECT_FREE_VALUE no failure."
},
"DNAT_WITH_CORRECT_USED_VALUE": {
"desc": "DNAT_WITH_CORRECT_USED_VALUE no failure."
},
"DNAT_WITH_WRONG_THRESHOLD_TYPE": {
"desc": "DNAT_WITH_WRONG_THRESHOLD_TYPE pattern failure.",
"eStrKey": "Pattern",
"eStr": ["wrong" ]
},
"IPMC_WITH_WRONG_PERCENTAGE": {
"desc": "IPMC_WITH_WRONG_PERCENTAGE must condition failure.",
"eStrKey": "Must"
},
"IPMC_WITH_HIGH_THRESHOLD_ERR": {
"desc": "IPMC_WITH_HIGH_THRESHOLD_ERR must condition failure about high threshold being lower than low threshold.",
"eStr": [ "high_threshold should be more than low_threshold" ]
},
"IPMC_WITH_CORRECT_FREE_VALUE": {
"desc": "IPMC_WITH_CORRECT_FREE_VALUE no failure."
},
"IPMC_WITH_CORRECT_USED_VALUE": {
"desc": "IPMC_WITH_CORRECT_USED_VALUE no failure."
},
"IPMC_WITH_WRONG_THRESHOLD_TYPE": {
"desc": "IPMC_WITH_WRONG_THRESHOLD_TYPE pattern failure.",
"eStrKey": "Pattern",
"eStr": ["wrong" ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"DEV_META_DEV_NEIGH_VERSION_TABLE": {
"desc": "DEVICE_METADATA DEVICE_NEIGHBOR VERSION TABLE."
},
"DEVICE_METADATA_DEFAULT_BGP_STATUS": {
"desc": "DEVICE_METADATA DEFAULT VALUE FOR BGP_STATUS FIELD.",
"eStrKey" : "Verify",
"verify": {
"xpath": "/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname",
"key": "sonic-device_metadata:default_bgp_status",
"value": "up"
}
},
"DEVICE_METADATA_DEFAULT_DOCKER_ROUTING_CONFIG_MODE": {
"desc": "DEVICE_METADATA DEFAULT VALUE FOR DOCKER_ROUTING_CONFIG_MODE FIELD.",
"eStrKey" : "Verify",
"verify": {
"xpath": "/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname",
"key": "sonic-device_metadata:docker_routing_config_mode",
"value": "unified"
}
},
"DEVICE_METADATA_DEFAULT_PFCWD_STATUS": {
"desc": "DEVICE_METADATA DEFAULT VALUE FOR PFCWD FIELD.",
"eStrKey" : "Verify",
"verify": {
"xpath": "/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname",
"key": "sonic-device_metadata:default_pfcwd_status",
"value": "disable"
}
},
"DEVICE_METADATA_TYPE_INCORRECT_PATTERN": {
"desc": "DEVICE_METADATA_TYPE_INCORRECT_PATTERN pattern failure.",
"eStrKey" : "Pattern"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE": {
"desc": "FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE no failure."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"INTERFACE_IP_PREFIX_EMPTY_STRING": {
"desc": "Configure empty string as ip-prefix in INTERFACE table.",
"eStrKey": "InvalidValue",
"eStr": ["ip-prefix"]
},
"INTERFACE_IPPREFIX_PORT_MUST_CONDITION_FALSE": {
"desc": "Interface Ip-prefix port-name must condition failure.",
"eStrKey": "Must"
},
"INTERFACE_IPPREFIX_PORT_MUST_CONDITION_TRUE": {
"desc": "Interface Ip-prefix port-name must condition pass."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"LOOPBACK_IPPREFIX_PORT_MUST_CONDITION_FALSE": {
"desc": "Loopback Ip-prefix port-name must condition failure.",
"eStrKey" : "Must"
}
}
27 changes: 27 additions & 0 deletions src/sonic-yang-models/tests/yang_model_tests/tests/port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"PORT_TEST": {
"desc": "LOAD PORT TABLE WITH FEC AND PFC_ASYM SUCCESSFULLY. VERIFY PFC_ASYM.",
"eStrKey" : "Verify",
"verify": {
"xpath": "/sonic-port:sonic-port/PORT/PORT_LIST[name='Ethernet8']/name",
"key": "sonic-port:pfc_asym",
"value": "on"
}
},
"PORT_NEG_TEST": {
"desc": "LOAD PORT TABLE FEC PATTERN FAILURE",
"eStrKey" : "Pattern",
"eStr": ["rc"]
},
"PORT_VALID_AUTONEG_TEST_1": {
"desc": "PORT_VALID_AUTONEG_TEST_1 no failure."
},
"PORT_VALID_AUTONEG_TEST_2": {
"desc": "PORT_VALID_AUTONEG_TEST_2 no failure."
},
"PORT_INVALID_AUTONEG_TEST": {
"desc": "PORT_INVALID_AUTONEG_TEST must condition failure.",
"eStrKey" : "Pattern",
"eStr": ["on|off"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"PORT_CHANNEL_TEST": {
"desc": "Configure a member port in PORT_CHANNEL table."
},
"PORT_CHANNEL_WRONG_PATTERN": {
"desc": "INCORRECT PORTCHANNEL_NAME IN PORT_CHANNEL TABLE.",
"eStrKey" : "Pattern",
"eStr": ["PortChannel"]
},
"PORTCHANNEL_INTERFACE_IP_ADDR_TEST": {
"desc": "Configure IP address on PORTCHANNEL_INTERFACE table."
},
"PORTCHANNEL_INTERFACE_IP_ADDR_ON_NON_EXIST_PO": {
"desc": "Configure IP address on a non existent PortChannel.",
"eStrKey": "LeafRef"
},
"PORTCHANNEL_MEMBER_WITH_NON_EXIST_PORTCHANNEL": {
"desc": "Configure PortChannel in PORTCHANNEL_MEMEBER table which does not exist in PORTCHANNEL table.",
"eStrKey": "LeafRef",
"eStr": ["portchannel", "name"]
},
"PORTCHANNEL_MEMBER_WITH_NON_EXIST_PORT": {
"desc": "Configure Port in PORTCHANNEL_MEMEBER table which does not exist in PORT table.",
"eStrKey": "LeafRef",
"eStr": ["port", "name"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"VERSIONS_WITH_INCORRECT_PATTERN": {
"desc": "VERSIONS_WITH_INCORRECT_PATTERN pattern failure.",
"eStrKey" : "Pattern"
},
"VERSIONS_WITH_INCORRECT_PATTERN2": {
"desc": "VERSIONS_WITH_INCORRECT_PATTERN pattern failure.",
"eStrKey" : "Pattern"
}
}
Loading