diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py new file mode 100644 index 000000000000..f753d0019a9d --- /dev/null +++ b/dump/plugins/vlan.py @@ -0,0 +1,69 @@ +from .executor import Executor +from dump.match_infra import MatchRequest +from dump.helper import create_template_dict + +class Vlan(Executor): + + ARG_NAME = "vlan_name" + + def __init__(self, match_engine=None): + super().__init__(match_engine) + self.ret_temp = {} + self.ns = '' + + def get_all_args(self, ns=""): + req = MatchRequest(db="CONFIG_DB", table="VLAN", key_pattern="*", ns=ns) + ret = self.match_engine.fetch(req) + all_vlans = ret["keys"] + return [key.split("|")[-1] for key in all_vlans] + + def execute(self, params_dict): + self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + vlan_name = params_dict[Vlan.ARG_NAME] + self.ns = params_dict["namespace"] + self.init_vlan_config_info(vlan_name) + self.init_vlan_appl_info(vlan_name) + self.init_state_vlan_info(vlan_name) + self.init_asic_vlan_info(vlan_name) + return self.ret_temp + + def init_vlan_config_info(self, vlan_name): + req = MatchRequest(db="CONFIG_DB", table="VLAN", key_pattern=vlan_name, ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + self.ret_temp[req.db]["keys"] = ret["keys"] + else: + self.ret_temp[req.db]["tables_not_found"] = [req.table] + + def init_vlan_appl_info(self, vlan_name): + req = MatchRequest(db="APPL_DB", table="VLAN_TABLE", key_pattern=vlan_name, ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + self.ret_temp[req.db]["keys"] = ret["keys"] + else: + self.ret_temp[req.db]["tables_not_found"] = [req.table] + + def init_state_vlan_info(self, vlan_name): + req = MatchRequest(db="STATE_DB", table="VLAN_TABLE", key_pattern=vlan_name, ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + self.ret_temp[req.db]["keys"] = ret["keys"] + else: + self.ret_temp[req.db]["tables_not_found"] = [req.table] + + def init_asic_vlan_info(self, vlan_name): + # Convert 'Vlanxxx' to 'xxx' + if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric(): + self.ret_temp["ASIC_DB"]["tables_not_found"] =["ASIC_STATE:SAI_OBJECT_TYPE_VLAN"] + return {}, {} + vlan_num = int(vlan_name[4:]) + + # Find the table named "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:*" in which SAI_VLAN_ATTR_VLAN_ID = vlan_num + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN", key_pattern="*", field="SAI_VLAN_ATTR_VLAN_ID", + value=str(vlan_num), ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + self.ret_temp[req.db]["keys"] = ret["keys"] + else: + self.ret_temp[req.db]["tables_not_found"] = [req.table] + diff --git a/dump/plugins/vlan_member.py b/dump/plugins/vlan_member.py new file mode 100644 index 000000000000..1518ac4bd73b --- /dev/null +++ b/dump/plugins/vlan_member.py @@ -0,0 +1,144 @@ +from .executor import Executor +from dump.match_infra import MatchRequest +from dump.helper import create_template_dict + +class Vlan_Member(Executor): + + ARG_NAME = "vlan_member_name" + + def __init__(self, match_engine=None): + super().__init__(match_engine) + self.ret_temp = {} + self.ns = '' + + def get_all_args(self, ns=""): + req = MatchRequest(db="CONFIG_DB", table="VLAN_MEMBER", key_pattern="*", ns=ns) + ret = self.match_engine.fetch(req) + all_vlans = ret["keys"] + return [key.split("|",1)[-1] for key in all_vlans] + + def execute(self, params_dict): + self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + vlan_member_name = params_dict[Vlan_Member.ARG_NAME] + vlan_member_name_list = vlan_member_name.split('|', 1) + if len(vlan_member_name_list) < 2: + self.ret_temp["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + self.ret_temp["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + self.ret_temp["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + return self.ret_temp + vlan_name = vlan_member_name_list[0] + member_name = vlan_member_name_list[1] + self.ns = params_dict["namespace"] + self.init_vlan_member_config_info(vlan_name, member_name) + self.init_vlan_member_appl_info(vlan_name, member_name) + self.init_state_vlan_member_info(vlan_name, member_name) + self.init_asic_vlan_member_info(vlan_name, member_name) + return self.ret_temp + + def init_vlan_member_config_info(self, vlan_name, member_name): + req = MatchRequest(db="CONFIG_DB", table="VLAN_MEMBER", key_pattern=vlan_name+'|'+member_name+"*", ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + for mem in ret["keys"]: + self.ret_temp[req.db]["keys"].append(mem) + else: + self.ret_temp[req.db]["tables_not_found"].append(req.table) + + def init_vlan_member_appl_info(self, vlan_name, member_name): + req = MatchRequest(db="APPL_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_name+':'+member_name+"*", ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + for mem in ret["keys"]: + self.ret_temp[req.db]["keys"].append(mem) + else: + self.ret_temp[req.db]["tables_not_found"].append(req.table) + + def init_state_vlan_member_info(self, vlan_name, member_name): + req = MatchRequest(db="STATE_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_name+'|'+member_name+"*", ns=self.ns) + ret = self.match_engine.fetch(req) + if not ret["error"] and len(ret["keys"]) != 0: + for mem in ret["keys"]: + self.ret_temp[req.db]["keys"].append(mem) + else: + self.ret_temp[req.db]["tables_not_found"].append(req.table) + + def init_asic_vlan_member_info(self, vlan_name, member_name): + + bridge_ret = {} + member_ret = {} + + # Convert 'Vlanxxx' to 'xxx' + if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric(): + self.ret_temp["ASIC_DB"]["tables_not_found"] =["ASIC_STATE:SAI_OBJECT_TYPE_VLAN"] + return + vlan_num = int(vlan_name[4:]) + + # Find the table named "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:*" in which SAI_VLAN_ATTR_VLAN_ID = vlan_num and store OID part of table name + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN", key_pattern="*", field="SAI_VLAN_ATTR_VLAN_ID", + value=str(vlan_num), ns=self.ns) + vlan_ret = self.match_engine.fetch(req) + # Example contents of vlan_ret: + # {'error': '', 'keys': ['ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000618'], 'return_values': {}} + if not vlan_ret["error"] and len(vlan_ret["keys"]) != 0: + vlan_oid=vlan_ret['keys'][0].split(':',2)[2] + else: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + return + + # Find OID of vlan member - find a table named ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:* whose SAI_HOSTIF_ATTR_NAME is the member name, + # and read the member OID from SAI_HOSTIF_ATTR_OBJ_ID in that table + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF", key_pattern="*", field="SAI_HOSTIF_ATTR_NAME", + value=member_name, return_fields=["SAI_HOSTIF_ATTR_OBJ_ID"], ns=self.ns) + hostif_ret = self.match_engine.fetch(req) + # Example contents of hostif_ret: + # {'error': '', 'keys': ['ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c1'], + # 'return_values': {'ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c1': {'SAI_HOSTIF_ATTR_OBJ_ID': 'oid:0x10000000002f6'}}} + member_oid = "" + if not hostif_ret["error"] and len(hostif_ret["keys"]) != 0: + sai_hostif_obj_key = hostif_ret["keys"][-1] + if sai_hostif_obj_key in hostif_ret["return_values"] and "SAI_HOSTIF_ATTR_OBJ_ID" in hostif_ret["return_values"][sai_hostif_obj_key]: + member_oid = hostif_ret["return_values"][sai_hostif_obj_key]["SAI_HOSTIF_ATTR_OBJ_ID"] + + # Find the table named "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:*" in which field SAI_BRIDGE_PORT_ATTR_PORT_ID = vlan member OID + if member_oid: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT", key_pattern="*", + field="SAI_BRIDGE_PORT_ATTR_PORT_ID", value=member_oid, ns=self.ns) + bridge_ret = self.match_engine.fetch(req) + # Example contents of bridge_ret: + # {'error': '', 'keys': ['ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061b'], 'return_values': {}} + + # Find the tables named "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:*" in which field SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID = SAI object bridge port OID. + # There should be one of these for each vlan in which the port is a member. + if bridge_ret and not bridge_ret["error"] and len(bridge_ret["keys"]) != 0: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER", key_pattern="*", + field="SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID", value=bridge_ret['keys'][0].split(':',2)[2], ns=self.ns) + member_ret = self.match_engine.fetch(req) + # Example contents of member_ret: + # {'error': '', 'keys': ['ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061c', 'ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061d'], 'return_values': {}} + + # Since this function is invoked for a given vlan and member, we expect that member_ret contains exactly one entry describing the port's + # membership in that vlan if it is a member, and zero if it is not. Only output the vlan member and bridge port tables + # if this port is a member of this vlan. + if member_ret and not member_ret["error"] and len(member_ret["keys"]) != 0: + is_member = False + for member_with_vlan in member_ret["keys"]: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER", key_pattern=member_with_vlan.split(":",2)[2], + field="SAI_VLAN_MEMBER_ATTR_VLAN_ID", value=vlan_oid, ns=self.ns) + vlan_bridge_ret = self.match_engine.fetch(req) + # Example contents of vlan_bridge_ret: + # {'error': '', 'keys': ['ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061c'], 'return_values': {}} + if not vlan_bridge_ret["error"] and len(vlan_bridge_ret["keys"]) != 0: + self.ret_temp[req.db]["keys"].append(vlan_bridge_ret["keys"][0]) + self.ret_temp[req.db]["keys"].append(bridge_ret["keys"][0]) + is_member = True + if not is_member: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + else: + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + self.ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + + diff --git a/tests/dump_input/vlan/appl_db.json b/tests/dump_input/vlan/appl_db.json new file mode 100644 index 000000000000..cc9d9916d302 --- /dev/null +++ b/tests/dump_input/vlan/appl_db.json @@ -0,0 +1,56 @@ +{ + "VLAN_TABLE:Vlan2": { + "admin_status": "up", + "host_ifname": "", + "mac": "7c:fe:90:f5:36:40", + "mtu": "9100" + }, + "VLAN_TABLE:Vlan3": { + "admin_status": "up", + "host_ifname": "", + "mac": "7c:fe:90:f5:36:40", + "mtu": "9100" + }, + "VLAN_MEMBER_TABLE:Vlan3:Ethernet8": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER_TABLE:Vlan3:Ethernet0": { + "tagging_mode": "tagged" + }, + "VLAN_TABLE:Vlan4": { + "admin_status": "up", + "host_ifname": "", + "mac": "7c:fe:90:f5:36:40", + "mtu": "9100" + }, + "VLAN_MEMBER_TABLE:Vlan4:Ethernet16": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER_TABLE:Vlan4:Ethernet24": { + "tagging_mode": "tagged" + }, + "VLAN_TABLE:Vlan7": { + "admin_status": "up", + "host_ifname": "", + "mac": "7c:fe:90:f5:36:40", + "mtu": "9100" + }, + "VLAN_MEMBER_TABLE:Vlan7:Ethernet48": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER_TABLE:Vlan7:Ethernet56": { + "tagging_mode": "tagged" + }, + "VLAN_TABLE:Vlan8": { + "admin_status": "up", + "host_ifname": "", + "mac": "7c:fe:90:f5:36:40", + "mtu": "9100" + }, + "VLAN_MEMBER_TABLE:Vlan8:Ethernet64": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER_TABLE:Vlan8:Ethernet72": { + "tagging_mode": "tagged" + } +} diff --git a/tests/dump_input/vlan/asic_db.json b/tests/dump_input/vlan/asic_db.json new file mode 100644 index 000000000000..8511cefbd9a2 --- /dev/null +++ b/tests/dump_input/vlan/asic_db.json @@ -0,0 +1,161 @@ +{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000617":{ + "SAI_VLAN_ATTR_VLAN_ID": "2" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000618":{ + "SAI_VLAN_ATTR_VLAN_ID": "3" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061e": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000061d", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000618", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000620": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000061f", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000618", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061d": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x100000000037a", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061f": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x10000000002f6", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003bf": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x100000000037a", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet0", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c1": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x10000000002f6", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet8", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000619":{ + "SAI_VLAN_ATTR_VLAN_ID": "4" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000624": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000623", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000619", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000622": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000621", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000619", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000623": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000272", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000621": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000338", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c3": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x1000000000338", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet16", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c5": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x1000000000272", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet24", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061a":{ + "SAI_VLAN_ATTR_VLAN_ID": "6" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000626": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000625", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061a", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000628": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000627", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061a", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000625": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x10000000002b4", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000627": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x10000000001ee", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c7": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x10000000002b4", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet32", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003c9": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x10000000001ee", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet40", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061b":{ + "SAI_VLAN_ATTR_VLAN_ID": "7" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062c": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000062b", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061b", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062a": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000629", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061b", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000062b": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x10000000000e6", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061a": { + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true", + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE": "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000230", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003cb": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x1000000000230", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet48", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000003cd": { + "SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV", + "SAI_HOSTIF_ATTR_OBJ_ID" : "oid:0x10000000000e6", + "SAI_HOSTIF_ATTR_NAME" : "Ethernet56", + "SAI_HOSTIF_ATTR_OPER_STATUS" : "true", + "SAI_HOSTIF_ATTR_VLAN_TAG" : "SAI_HOSTIF_VLAN_TAG_KEEP" + } +} diff --git a/tests/dump_input/vlan/config_db.json b/tests/dump_input/vlan/config_db.json new file mode 100644 index 000000000000..4e034b85b4ab --- /dev/null +++ b/tests/dump_input/vlan/config_db.json @@ -0,0 +1,56 @@ +{ + "VLAN|Vlan2": { + "vlanid" : "2" + }, + "VLAN|Vlan3": { + "vlanid" : "3" + }, + "VLAN_MEMBER|Vlan3|Ethernet0": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER|Vlan3|Ethernet8": { + "tagging_mode": "tagged" + }, + "VLAN|Vlan4": { + "vlanid" : "4" + }, + "VLAN_MEMBER|Vlan4|Ethernet16": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER|Vlan4|Ethernet24": { + "tagging_mode": "tagged" + }, + "VLAN_INTERFACE|Vlan4|192.168.1.2/24": { + "NULL": "NULL" + }, + "VLAN_INTERFACE|Vlan4": { + "NULL": "NULL" + }, + "VLAN|Vlan6": { + "vlanid" : "6" + }, + "VLAN_MEMBER|Vlan6|Ethernet32": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER|Vlan6|Ethernet40": { + "tagging_mode": "tagged" + }, + "VLAN|Vlan7": { + "vlanid" : "7" + }, + "VLAN_MEMBER|Vlan7|Ethernet48": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER|Vlan7|Ethernet56": { + "tagging_mode": "tagged" + }, + "VLAN|Vlan8": { + "vlanid" : "8" + }, + "VLAN_MEMBER|Vlan8|Ethernet64": { + "tagging_mode": "tagged" + }, + "VLAN_MEMBER|Vlan8|Ethernet72": { + "tagging_mode": "tagged" + } +} diff --git a/tests/dump_input/vlan/state_db.json b/tests/dump_input/vlan/state_db.json new file mode 100644 index 000000000000..994c867254e5 --- /dev/null +++ b/tests/dump_input/vlan/state_db.json @@ -0,0 +1,41 @@ +{ + "VLAN_TABLE|Vlan2": { + "state": "ok" + }, + "VLAN_TABLE|Vlan3": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan3|Ethernet8": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan3|Ethernet0": { + "state": "ok" + }, + "VLAN_TABLE|Vlan4": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan4|Ethernet16": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan4|Ethernet24": { + "state": "ok" + }, + "VLAN_TABLE|Vlan6": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan6|Ethernet32": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan6|Ethernet40": { + "state": "ok" + }, + "VLAN_TABLE|Vlan8": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan8|Ethernet64": { + "state": "ok" + }, + "VLAN_MEMBER_TABLE|Vlan8|Ethernet72": { + "state": "ok" + } +} diff --git a/tests/dump_tests/module_tests/vlan_test.py b/tests/dump_tests/module_tests/vlan_test.py new file mode 100644 index 000000000000..806fc6122281 --- /dev/null +++ b/tests/dump_tests/module_tests/vlan_test.py @@ -0,0 +1,374 @@ +import json, os, sys +import jsonpatch +import unittest +import pytest +from deepdiff import DeepDiff +from mock import patch +from dump.helper import create_template_dict, sort_lists +from dump.plugins.vlan import Vlan +from dump.plugins.vlan_member import Vlan_Member +from dump.match_infra import MatchEngine, ConnectionPool +from swsscommon.swsscommon import SonicV2Connector + +module_tests_path = os.path.dirname(__file__) +dump_tests_path = os.path.join(module_tests_path, "../") +tests_path = os.path.join(dump_tests_path, "../") +dump_test_input = os.path.join(tests_path, "dump_input") + + +# Location for dedicated db's used for UT +vlan_files_path = os.path.join(dump_test_input, "vlan") + +dedicated_dbs = {} +dedicated_dbs['CONFIG_DB'] = os.path.join(vlan_files_path, "config_db.json") +dedicated_dbs['APPL_DB'] = os.path.join(vlan_files_path, "appl_db.json") +dedicated_dbs['ASIC_DB'] = os.path.join(vlan_files_path, "asic_db.json") +dedicated_dbs['STATE_DB'] = os.path.join(vlan_files_path, "state_db.json") + +def verbosity_setup(): + print("SETUP") + os.environ["VERBOSE"] = "1" + yield + print("TEARDOWN") + os.environ["VERBOSE"] = "0" + +def populate_mock(db, db_names): + for db_name in db_names: + db.connect(db_name) + # Delete any default data + db.delete_all_by_pattern(db_name, "*") + with open(dedicated_dbs[db_name]) as f: + mock_json = json.load(f) + for key in mock_json: + for field, value in mock_json[key].items(): + db.set(db_name, key, field, value) + +@pytest.fixture(scope="class", autouse=True) +def match_engine(): + + # Monkey Patch the SonicV2Connector Object + from ...mock_tables import dbconnector + db = SonicV2Connector() + + # popualate the db with mock data + db_names = list(dedicated_dbs.keys()) + try: + populate_mock(db, db_names) + except Exception as e: + assert False, "Mock initialization failed: " + str(e) + + # Initialize connection pool + conn_pool = ConnectionPool() + DEF_NS = '' # Default Namespace + conn_pool.cache = {DEF_NS: {'conn': db, + 'connected_to': set(db_names)}} + + # Initialize match_engine + match_engine = MatchEngine(conn_pool) + yield match_engine + +@pytest.mark.usefixtures("match_engine") +class TestVlanModule: + + def test_working_state_vlan(self, match_engine): + params = {} + params["namespace"] = "" + params[Vlan.ARG_NAME] = "Vlan4" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan4") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan4") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan4") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000619") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_working_state_vlan_member1(self, match_engine): + params = {} + params["namespace"] = "" + params[Vlan_Member.ARG_NAME] = "Vlan4|Ethernet16" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet16") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet16") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet16") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000622") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000621") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_working_state_vlan_member2(self, match_engine): + params = {} + params["namespace"] = "" + params[Vlan_Member.ARG_NAME] = "Vlan4|Ethernet24" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet24") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet24") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet24") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000624") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000623") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + # Wildcard works for CONFIG, APPL & STATE, but not currently suppoerted for ASIC + def test_working_state_vlan_member_wildcard(self, match_engine): + params = {} + params["namespace"] = "" + params[Vlan_Member.ARG_NAME] = "Vlan4|*" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet16") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet24") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet16") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet24") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet16") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet24") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_members(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "Vlan2" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan2") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan2") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan2") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000617") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_wrong_case_vlan(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "VLAN4" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_wrong_case_vlan_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "Vlan4|ETHERNET16" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_unconfigured_vlan(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "Vlan5" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_unconfigured_vlan_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "Vlan4|Ethernet0" # member but not in that vlan + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_garbage_alpha_vlan(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "garbage" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_garbage_alpha_vlan_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "garbage" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_garbage_number_vlan(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "614" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_garbage_number_vlan_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME]= "3892" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + # Vlan6 is not defined in appl_db + def test_missing_appl_db(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "Vlan6" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan6") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan6") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061a") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_appl_db_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "Vlan6|Ethernet32" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan6|Ethernet32") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan6|Ethernet32") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000626") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000625") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + # Vlan7 is not defined in state_db + def test_missing_state_db(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "Vlan7" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan7") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan7") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061b") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_state_db_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "Vlan7|Ethernet56" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan7|Ethernet56") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan7:Ethernet56") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062c") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000062b") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + # Vlan8 is not defined in asic_db + def test_missing_asic_db(self, match_engine): + params = {} + params[Vlan.ARG_NAME] = "Vlan8" + params["namespace"] = "" + m_vlan = Vlan(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan8") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan8") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan8") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_asic_db_member(self, match_engine): + params = {} + params[Vlan_Member.ARG_NAME] = "Vlan8|Ethernet72" + params["namespace"] = "" + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan8|Ethernet72") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan8:Ethernet72") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan8|Ethernet72") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_all_args(self, match_engine): + params = {} + m_vlan = Vlan(match_engine) + returned = m_vlan.get_all_args("") + expect = ["Vlan2", "Vlan3", "Vlan4", "Vlan6", "Vlan7", "Vlan8"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff + + def test_all_args_member(self, match_engine): + params = {} + m_vlan = Vlan_Member(match_engine) + returned = m_vlan.get_all_args("") + expect = ["Vlan3|Ethernet0", "Vlan3|Ethernet8", + "Vlan4|Ethernet16", "Vlan4|Ethernet24", + "Vlan6|Ethernet32", "Vlan6|Ethernet40", + "Vlan7|Ethernet48", "Vlan7|Ethernet56", + "Vlan8|Ethernet64", "Vlan8|Ethernet72"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff