From 134a19388e866f1fecd88e6d8e48a5b7b5b32fde Mon Sep 17 00:00:00 2001 From: Raphael Tryster Date: Tue, 10 Aug 2021 18:48:51 +0000 Subject: [PATCH 1/6] [Debug Dump Util] Vlan Module Added Signed-off-by: Raphael Tryster --- dump/plugins/vlan.py | 144 +++++++++++++++++ tests/dump_input/vlan/appl_db.json | 32 ++++ tests/dump_input/vlan/asic_db.json | 31 ++++ tests/dump_input/vlan/config_db.json | 29 ++++ tests/dump_input/vlan/state_db.json | 23 +++ tests/dump_tests/module_tests/vlan_test.py | 177 +++++++++++++++++++++ 6 files changed, 436 insertions(+) create mode 100644 dump/plugins/vlan.py create mode 100644 tests/dump_input/vlan/appl_db.json create mode 100644 tests/dump_input/vlan/asic_db.json create mode 100644 tests/dump_input/vlan/config_db.json create mode 100644 tests/dump_input/vlan/state_db.json create mode 100644 tests/dump_tests/module_tests/vlan_test.py diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py new file mode 100644 index 0000000000..f5cf1db838 --- /dev/null +++ b/dump/plugins/vlan.py @@ -0,0 +1,144 @@ +from .executor import Executor +from dump.match_infra import MatchEngine, MatchRequest +from dump.helper import create_template_dict +from _ast import Or + +class Vlan(Executor): + + ARG_NAME = "vlan_name" + + def __init__(self): + self.match_engine = MatchEngine() + 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_member_config_info(vlan_name) + self.init_vlan_interface_config_info(vlan_name) + self.init_vlan_sub_interface_config_info(vlan_name) + self.init_vlan_appl_info(vlan_name) + self.init_vlan_member_appl_info(vlan_name) + self.init_state_vlan_info(vlan_name) + self.init_state_vlan_member_info(vlan_name) + self.init_asic_vlan_info(vlan_name) + self.init_asic_vlan_member_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_member_config_info(self, vlan_name): + req = MatchRequest(db="CONFIG_DB", table="VLAN_MEMBER", key_pattern=vlan_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_interface_config_info(self, vlan_name): + req = MatchRequest(db="CONFIG_DB", table="VLAN_INTERFACE", key_pattern=vlan_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_sub_interface_config_info(self, vlan_name): + req = MatchRequest(db="CONFIG_DB", table="VLAN_SUB_INTERFACE", key_pattern=vlan_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_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_vlan_member_appl_info(self, vlan_name): + req = MatchRequest(db="APPL_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_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_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_state_vlan_member_info(self, vlan_name): + req = MatchRequest(db="STATE_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_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_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] + + def init_asic_vlan_member_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"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + 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) + + # Find all the member tables whose vlan is the oid:0x... part of the table name just found + if not ret["error"] and len(ret["keys"]) != 0: + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER", key_pattern="*", + field="SAI_VLAN_MEMBER_ATTR_VLAN_ID", value=ret["keys"][0][32:], 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("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + \ No newline at end of file diff --git a/tests/dump_input/vlan/appl_db.json b/tests/dump_input/vlan/appl_db.json new file mode 100644 index 0000000000..15c9266126 --- /dev/null +++ b/tests/dump_input/vlan/appl_db.json @@ -0,0 +1,32 @@ +{ + "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" + } +} diff --git a/tests/dump_input/vlan/asic_db.json b/tests/dump_input/vlan/asic_db.json new file mode 100644 index 0000000000..d7e777465c --- /dev/null +++ b/tests/dump_input/vlan/asic_db.json @@ -0,0 +1,31 @@ +{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005df":{ + "SAI_VLAN_ATTR_VLAN_ID": "2" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e0":{ + "SAI_VLAN_ATTR_VLAN_ID": "3" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e4": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e3", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e0", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e2": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e1", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e0", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e5":{ + "SAI_VLAN_ATTR_VLAN_ID": "4" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e7": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e6", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e5", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e9": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e8", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e5", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + } +} diff --git a/tests/dump_input/vlan/config_db.json b/tests/dump_input/vlan/config_db.json new file mode 100644 index 0000000000..9fd4d43eb3 --- /dev/null +++ b/tests/dump_input/vlan/config_db.json @@ -0,0 +1,29 @@ +{ + "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" + } +} diff --git a/tests/dump_input/vlan/state_db.json b/tests/dump_input/vlan/state_db.json new file mode 100644 index 0000000000..4847fde49d --- /dev/null +++ b/tests/dump_input/vlan/state_db.json @@ -0,0 +1,23 @@ +{ + "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" + } +} 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 0000000000..111403c99e --- /dev/null +++ b/tests/dump_tests/module_tests/vlan_test.py @@ -0,0 +1,177 @@ +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 .mock_sonicv2connector import MockSonicV2Connector + +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 mock_connector(namespace, use_unix_socket_path=True): + return MockSonicV2Connector(dedicated_dbs, namespace=namespace, use_unix_socket_path=use_unix_socket_path) + +@pytest.fixture(scope="module", autouse=True) +def verbosity_setup(): + print("SETUP") + os.environ["VERBOSE"] = "1" + yield + print("TEARDOWN") + os.environ["VERBOSE"] = "0" + + +@patch("dump.match_infra.SonicV2Connector", mock_connector) +class TestVlanModule(unittest.TestCase): + + def test_working_state(self): + params = {} + params[Vlan.ARG_NAME] = "Vlan4" + params["namespace"] = "" + m_vlan = Vlan() + 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet16") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet24") + expect["CONFIG_DB"]["keys"].append("VLAN_INTERFACE|Vlan4|192.168.1.2/24") + expect["CONFIG_DB"]["keys"].append("VLAN_INTERFACE|Vlan4") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan4") + 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_TABLE|Vlan4") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet16") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet24") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e5") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e7") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e9") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_interface(self): + params = {} + params[Vlan.ARG_NAME] = "Vlan3" + params["namespace"] = "" + m_vlan = Vlan() + returned = m_vlan.execute(params) + expect = create_template_dict(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"]) + expect["CONFIG_DB"]["keys"].append("VLAN|Vlan3") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet0") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet8") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan3") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet0") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet8") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan3") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan3|Ethernet0") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan3|Ethernet8") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e0") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e4") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e2") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + def test_missing_memebers_and_interface(self): + params = {} + params[Vlan.ARG_NAME] = "Vlan2" + params["namespace"] = "" + m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan2") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan2") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005df") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_wrong_case_vlan(self): + params = {} + params[Vlan.ARG_NAME] = "VLAN4" + params["namespace"] = "" + m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_unconfigured_vlan(self): + params = {} + params[Vlan.ARG_NAME] = "Vlan5" + params["namespace"] = "" + m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_garbage_vlan(self): + params = {} + params[Vlan.ARG_NAME] = "garbage" + params["namespace"] = "" + m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") + expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + ddiff = DeepDiff(returned, expect, ignore_order=True) + assert not ddiff, ddiff + + def test_all_args(self): + params = {} + m_vlan = Vlan() + returned = m_vlan.get_all_args("") + expect = ["Vlan2", "Vlan3", "Vlan4"] + ddiff = DeepDiff(expect, returned, ignore_order=True) + assert not ddiff, ddiff From 1afeac7b8405e2dfd260215c21b6470437fdfed3 Mon Sep 17 00:00:00 2001 From: Raphael Tryster Date: Sun, 29 Aug 2021 08:44:56 +0000 Subject: [PATCH 2/6] [Debug Dump Util] Vlan module changes due to infrastructure changes and Vivek's comments Signed-off-by: Raphael Tryster --- dump/plugins/vlan.py | 27 +------ tests/dump_tests/module_tests/vlan_test.py | 87 +++++++++++++--------- 2 files changed, 55 insertions(+), 59 deletions(-) diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py index f5cf1db838..3e67b5cbfc 100644 --- a/dump/plugins/vlan.py +++ b/dump/plugins/vlan.py @@ -1,14 +1,13 @@ from .executor import Executor from dump.match_infra import MatchEngine, MatchRequest from dump.helper import create_template_dict -from _ast import Or class Vlan(Executor): ARG_NAME = "vlan_name" - def __init__(self): - self.match_engine = MatchEngine() + def __init__(self, match_engine=None): + super().__init__(match_engine) self.ret_temp = {} self.ns = '' @@ -24,8 +23,6 @@ def execute(self, params_dict): self.ns = params_dict["namespace"] self.init_vlan_config_info(vlan_name) self.init_vlan_member_config_info(vlan_name) - self.init_vlan_interface_config_info(vlan_name) - self.init_vlan_sub_interface_config_info(vlan_name) self.init_vlan_appl_info(vlan_name) self.init_vlan_member_appl_info(vlan_name) self.init_state_vlan_info(vlan_name) @@ -51,24 +48,6 @@ def init_vlan_member_config_info(self, vlan_name): else: self.ret_temp[req.db]["tables_not_found"].append(req.table) - def init_vlan_interface_config_info(self, vlan_name): - req = MatchRequest(db="CONFIG_DB", table="VLAN_INTERFACE", key_pattern=vlan_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_sub_interface_config_info(self, vlan_name): - req = MatchRequest(db="CONFIG_DB", table="VLAN_SUB_INTERFACE", key_pattern=vlan_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_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) @@ -141,4 +120,4 @@ def init_asic_vlan_member_info(self, vlan_name): self.ret_temp[req.db]["keys"].append(mem) else: self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - \ No newline at end of file + diff --git a/tests/dump_tests/module_tests/vlan_test.py b/tests/dump_tests/module_tests/vlan_test.py index 111403c99e..cd5451febf 100644 --- a/tests/dump_tests/module_tests/vlan_test.py +++ b/tests/dump_tests/module_tests/vlan_test.py @@ -6,8 +6,8 @@ from mock import patch from dump.helper import create_template_dict, sort_lists from dump.plugins.vlan import Vlan - -from .mock_sonicv2connector import MockSonicV2Connector +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, "../") @@ -24,10 +24,6 @@ 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 mock_connector(namespace, use_unix_socket_path=True): - return MockSonicV2Connector(dedicated_dbs, namespace=namespace, use_unix_socket_path=use_unix_socket_path) - -@pytest.fixture(scope="module", autouse=True) def verbosity_setup(): print("SETUP") os.environ["VERBOSE"] = "1" @@ -35,23 +31,54 @@ def verbosity_setup(): 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 -@patch("dump.match_infra.SonicV2Connector", mock_connector) -class TestVlanModule(unittest.TestCase): +@pytest.mark.usefixtures("match_engine") +class TestVlanModule: - def test_working_state(self): + def test_working_state(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan4" params["namespace"] = "" - m_vlan = Vlan() + 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet16") expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan4|Ethernet24") - expect["CONFIG_DB"]["keys"].append("VLAN_INTERFACE|Vlan4|192.168.1.2/24") - expect["CONFIG_DB"]["keys"].append("VLAN_INTERFACE|Vlan4") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan4") expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet16") expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan4:Ethernet24") @@ -64,18 +91,16 @@ def test_working_state(self): ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) assert not ddiff, ddiff - def test_missing_interface(self): + def test_missing_interface(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan3" params["namespace"] = "" - m_vlan = Vlan() + 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|Vlan3") expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet0") expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet8") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan3") expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet0") expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet8") @@ -88,17 +113,15 @@ def test_missing_interface(self): ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) assert not ddiff, ddiff - def test_missing_memebers_and_interface(self): + def test_missing_memebers_and_interface(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan2" params["namespace"] = "" - m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan2") expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan2") @@ -108,17 +131,15 @@ def test_missing_memebers_and_interface(self): ddiff = DeepDiff(returned, expect, ignore_order=True) assert not ddiff, ddiff - def test_wrong_case_vlan(self): + def test_wrong_case_vlan(self, match_engine): params = {} params[Vlan.ARG_NAME] = "VLAN4" params["namespace"] = "" - m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") @@ -128,17 +149,15 @@ def test_wrong_case_vlan(self): ddiff = DeepDiff(returned, expect, ignore_order=True) assert not ddiff, ddiff - def test_unconfigured_vlan(self): + def test_unconfigured_vlan(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan5" params["namespace"] = "" - m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") @@ -148,17 +167,15 @@ def test_unconfigured_vlan(self): ddiff = DeepDiff(returned, expect, ignore_order=True) assert not ddiff, ddiff - def test_garbage_vlan(self): + def test_garbage_vlan(self, match_engine): params = {} params[Vlan.ARG_NAME] = "garbage" params["namespace"] = "" - m_vlan = Vlan() + 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_INTERFACE") - expect["CONFIG_DB"]["tables_not_found"].append("VLAN_SUB_INTERFACE") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") @@ -168,9 +185,9 @@ def test_garbage_vlan(self): ddiff = DeepDiff(returned, expect, ignore_order=True) assert not ddiff, ddiff - def test_all_args(self): + def test_all_args(self, match_engine): params = {} - m_vlan = Vlan() + m_vlan = Vlan(match_engine) returned = m_vlan.get_all_args("") expect = ["Vlan2", "Vlan3", "Vlan4"] ddiff = DeepDiff(expect, returned, ignore_order=True) From 788b326da168cc480948b05241b9d2977a4146fa Mon Sep 17 00:00:00 2001 From: Raphael Tryster Date: Tue, 14 Sep 2021 17:38:39 +0000 Subject: [PATCH 3/6] [Debug Dump Util] Vlan module additional tables and tests requested by Sud Signed-off-by: Raphael Tryster --- dump/plugins/vlan.py | 60 ++++++++-- tests/dump_input/vlan/appl_db.json | 24 ++++ tests/dump_input/vlan/asic_db.json | 106 ++++++++++++++--- tests/dump_input/vlan/config_db.json | 27 +++++ tests/dump_input/vlan/state_db.json | 18 +++ tests/dump_tests/module_tests/vlan_test.py | 132 ++++++++++++++++----- 6 files changed, 309 insertions(+), 58 deletions(-) diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py index 3e67b5cbfc..25714ce19d 100644 --- a/dump/plugins/vlan.py +++ b/dump/plugins/vlan.py @@ -27,8 +27,8 @@ def execute(self, params_dict): self.init_vlan_member_appl_info(vlan_name) self.init_state_vlan_info(vlan_name) self.init_state_vlan_member_info(vlan_name) - self.init_asic_vlan_info(vlan_name) - self.init_asic_vlan_member_info(vlan_name) + req, vlan_table = self.init_asic_vlan_info(vlan_name) + self.init_asic_vlan_member_info(vlan_name, req, vlan_table) return self.ret_temp def init_vlan_config_info(self, vlan_name): @@ -86,7 +86,7 @@ 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 + 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 @@ -97,27 +97,61 @@ def init_asic_vlan_info(self, vlan_name): self.ret_temp[req.db]["keys"] = ret["keys"] else: self.ret_temp[req.db]["tables_not_found"] = [req.table] + + # Return request and table to caller in case its next call is to init_asic_vlan_member_info which also needs it + return req, ret - def init_asic_vlan_member_info(self, vlan_name): - # Convert 'Vlanxxx' to 'xxx' + def init_asic_vlan_member_info(self, vlan_name, req, vlan_table): + + bridge_oids = [] + ret = {} + + # Handle invalid vlan name if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric(): 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") 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) + # Find vlan table if not passed by caller + if not req or not vlan_table: + + # Convert 'Vlanxxx' to 'xxx' + 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) + vlan_table = self.match_engine.fetch(req) # Find all the member tables whose vlan is the oid:0x... part of the table name just found - if not ret["error"] and len(ret["keys"]) != 0: + if not vlan_table["error"] and len(vlan_table["keys"]) != 0: req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER", key_pattern="*", - field="SAI_VLAN_MEMBER_ATTR_VLAN_ID", value=ret["keys"][0][32:], ns=self.ns) + field="SAI_VLAN_MEMBER_ATTR_VLAN_ID", value=vlan_table["keys"][0][32:], + return_fields=["SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID"], ns=self.ns) ret = self.match_engine.fetch(req) - if not ret["error"] and len(ret["keys"]) != 0: + + # Retrieve SAI_OBJECT_TYPE_VLAN_MEMBER and SAI_OBJECT_TYPE_BRIDGE_PORT tables for each member port + if ret and not ret["error"] and len(ret["keys"]) != 0: for mem in ret["keys"]: + + # Append ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:... directly to output self.ret_temp[req.db]["keys"].append(mem) + + # Find the SAI_OBJECT_TYPE_BRIDGE_PORT key corresponding to member's SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID + req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT", + key_pattern=ret['return_values'][mem]['SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID'], ns=self.ns) + bridge_ret = self.match_engine.fetch(req) + + # Append ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:... to a separate list + if bridge_ret and not bridge_ret["error"] and len(bridge_ret["keys"]) != 0: + bridge_oids.append(bridge_ret['keys'][0]) + else: + self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + + # Append the collection of ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:... to the output after the vlan members + for bp in bridge_oids: + self.ret_temp[req.db]["keys"].append(bp) else: self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + self.ret_temp[req.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 index 15c9266126..5e4191a500 100644 --- a/tests/dump_input/vlan/appl_db.json +++ b/tests/dump_input/vlan/appl_db.json @@ -27,6 +27,30 @@ "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 index d7e777465c..42e8f1b528 100644 --- a/tests/dump_input/vlan/asic_db.json +++ b/tests/dump_input/vlan/asic_db.json @@ -1,31 +1,105 @@ { - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005df":{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000629":{ "SAI_VLAN_ATTR_VLAN_ID": "2" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e0":{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000062a":{ "SAI_VLAN_ATTR_VLAN_ID": "3" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e4": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e3", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e0", + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062f": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000062e", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062a", "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e2": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e1", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e0", + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062d": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000062c", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062a", "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e5":{ + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000062e": { + "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_BRIDGE_PORT:oid:0x3a00000000062c": { + "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_VLAN:oid:0x2600000000062b":{ "SAI_VLAN_ATTR_VLAN_ID": "4" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e7": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e6", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e5", + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000631": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000630", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062b", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000633": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000632", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062b", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000630": { + "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_BRIDGE_PORT:oid:0x3a000000000632": { + "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_VLAN:oid:0x2600000000061c":{ + "SAI_VLAN_ATTR_VLAN_ID": "6" + }, + "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:0x2600000000061c", "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e9": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000005e8", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x260000000005e5", + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061f": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000618", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061c", "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:0x10000000002b4", + "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000618": { + "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_VLAN:oid:0x26000000000620":{ + "SAI_VLAN_ATTR_VLAN_ID": "7" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000623": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000622", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000620", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000621": { + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000061a", + "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000620", + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE": "SAI_VLAN_TAGGING_MODE_TAGGED" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000622": { + "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" + } } diff --git a/tests/dump_input/vlan/config_db.json b/tests/dump_input/vlan/config_db.json index 9fd4d43eb3..c7feeab601 100644 --- a/tests/dump_input/vlan/config_db.json +++ b/tests/dump_input/vlan/config_db.json @@ -25,5 +25,32 @@ }, "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 index 4847fde49d..5c68128d89 100644 --- a/tests/dump_input/vlan/state_db.json +++ b/tests/dump_input/vlan/state_db.json @@ -18,6 +18,24 @@ "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 index cd5451febf..362897f889 100644 --- a/tests/dump_tests/module_tests/vlan_test.py +++ b/tests/dump_tests/module_tests/vlan_test.py @@ -85,35 +85,15 @@ def test_working_state(self, match_engine): expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan4") expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet16") expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet24") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e5") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e7") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e9") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000062b") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000631") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000633") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000630") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000632") ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) assert not ddiff, ddiff - def test_missing_interface(self, match_engine): - params = {} - params[Vlan.ARG_NAME] = "Vlan3" - 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|Vlan3") - expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet0") - expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan3|Ethernet8") - expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan3") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet0") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan3:Ethernet8") - expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan3") - expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan3|Ethernet0") - expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan3|Ethernet8") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005e0") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e4") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x270000000005e2") - ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) - assert not ddiff, ddiff - - def test_missing_memebers_and_interface(self, match_engine): + def test_missing_members(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan2" params["namespace"] = "" @@ -126,8 +106,9 @@ def test_missing_memebers_and_interface(self, match_engine): expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan2") expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x260000000005df") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000629") 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 @@ -146,6 +127,7 @@ def test_wrong_case_vlan(self, match_engine): expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") 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 @@ -164,10 +146,11 @@ def test_unconfigured_vlan(self, match_engine): expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") 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_vlan(self, match_engine): + def test_garbage_alpha_vlan(self, match_engine): params = {} params[Vlan.ARG_NAME] = "garbage" params["namespace"] = "" @@ -182,13 +165,104 @@ def test_garbage_vlan(self, match_engine): expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan6|Ethernet32") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan6|Ethernet40") + expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan6") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan6|Ethernet32") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan6|Ethernet40") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061c") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061e") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061f") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061d") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000618") + ddiff = DeepDiff(sort_lists(returned), sort_lists(expect), ignore_order=True) + assert not ddiff, ddiff + + # Vlan7 is not defined in state_db, but adds bridge port tables in asic_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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan7|Ethernet48") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan7|Ethernet56") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan7") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan7:Ethernet48") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan7:Ethernet56") + expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") + expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000620") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000623") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000621") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000622") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061a") + 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan8|Ethernet64") + expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan8|Ethernet72") + expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan8") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan8:Ethernet64") + expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan8:Ethernet72") + expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan8") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan8|Ethernet64") + expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan8|Ethernet72") + expect["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + 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"] + expect = ["Vlan2", "Vlan3", "Vlan4", "Vlan6", "Vlan7", "Vlan8"] ddiff = DeepDiff(expect, returned, ignore_order=True) assert not ddiff, ddiff From 737b4aac7a61aead87dcbca7c36e1201ed030a16 Mon Sep 17 00:00:00 2001 From: raphaelt Date: Sun, 10 Oct 2021 13:00:30 +0000 Subject: [PATCH 4/6] Separate vlan and vlan_member debug dump modules Signed-off-by: raphaelt --- dump/plugins/vlan.py | 85 --------- dump/plugins/vlan_member.py | 144 ++++++++++++++ tests/dump_input/vlan/asic_db.json | 136 +++++++++---- tests/dump_tests/module_tests/vlan_test.py | 212 +++++++++++++++------ 4 files changed, 399 insertions(+), 178 deletions(-) create mode 100644 dump/plugins/vlan_member.py diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py index 25714ce19d..bef8fc7e38 100644 --- a/dump/plugins/vlan.py +++ b/dump/plugins/vlan.py @@ -22,13 +22,9 @@ def execute(self, params_dict): vlan_name = params_dict[Vlan.ARG_NAME] self.ns = params_dict["namespace"] self.init_vlan_config_info(vlan_name) - self.init_vlan_member_config_info(vlan_name) self.init_vlan_appl_info(vlan_name) - self.init_vlan_member_appl_info(vlan_name) self.init_state_vlan_info(vlan_name) - self.init_state_vlan_member_info(vlan_name) req, vlan_table = self.init_asic_vlan_info(vlan_name) - self.init_asic_vlan_member_info(vlan_name, req, vlan_table) return self.ret_temp def init_vlan_config_info(self, vlan_name): @@ -39,15 +35,6 @@ def init_vlan_config_info(self, vlan_name): else: self.ret_temp[req.db]["tables_not_found"] = [req.table] - def init_vlan_member_config_info(self, vlan_name): - req = MatchRequest(db="CONFIG_DB", table="VLAN_MEMBER", key_pattern=vlan_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_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) @@ -56,15 +43,6 @@ def init_vlan_appl_info(self, vlan_name): else: self.ret_temp[req.db]["tables_not_found"] = [req.table] - def init_vlan_member_appl_info(self, vlan_name): - req = MatchRequest(db="APPL_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_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_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) @@ -73,15 +51,6 @@ def init_state_vlan_info(self, vlan_name): else: self.ret_temp[req.db]["tables_not_found"] = [req.table] - def init_state_vlan_member_info(self, vlan_name): - req = MatchRequest(db="STATE_DB", table="VLAN_MEMBER_TABLE", key_pattern=vlan_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_info(self, vlan_name): # Convert 'Vlanxxx' to 'xxx' if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric(): @@ -101,57 +70,3 @@ def init_asic_vlan_info(self, vlan_name): # Return request and table to caller in case its next call is to init_asic_vlan_member_info which also needs it return req, ret - def init_asic_vlan_member_info(self, vlan_name, req, vlan_table): - - bridge_oids = [] - ret = {} - - # Handle invalid vlan name - if vlan_name[0:4] != "Vlan" or not vlan_name[4:].isnumeric(): - 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") - return - - # Find vlan table if not passed by caller - if not req or not vlan_table: - - # Convert 'Vlanxxx' to 'xxx' - 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) - vlan_table = self.match_engine.fetch(req) - - # Find all the member tables whose vlan is the oid:0x... part of the table name just found - if not vlan_table["error"] and len(vlan_table["keys"]) != 0: - req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER", key_pattern="*", - field="SAI_VLAN_MEMBER_ATTR_VLAN_ID", value=vlan_table["keys"][0][32:], - return_fields=["SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID"], ns=self.ns) - ret = self.match_engine.fetch(req) - - # Retrieve SAI_OBJECT_TYPE_VLAN_MEMBER and SAI_OBJECT_TYPE_BRIDGE_PORT tables for each member port - if ret and not ret["error"] and len(ret["keys"]) != 0: - for mem in ret["keys"]: - - # Append ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:... directly to output - self.ret_temp[req.db]["keys"].append(mem) - - # Find the SAI_OBJECT_TYPE_BRIDGE_PORT key corresponding to member's SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID - req = MatchRequest(db="ASIC_DB", table="ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT", - key_pattern=ret['return_values'][mem]['SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID'], ns=self.ns) - bridge_ret = self.match_engine.fetch(req) - - # Append ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:... to a separate list - if bridge_ret and not bridge_ret["error"] and len(bridge_ret["keys"]) != 0: - bridge_oids.append(bridge_ret['keys'][0]) - else: - self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - - # Append the collection of ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:... to the output after the vlan members - for bp in bridge_oids: - self.ret_temp[req.db]["keys"].append(bp) - else: - self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - self.ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - diff --git a/dump/plugins/vlan_member.py b/dump/plugins/vlan_member.py new file mode 100644 index 0000000000..9068f62fbb --- /dev/null +++ b/dump/plugins/vlan_member.py @@ -0,0 +1,144 @@ +from .executor import Executor +from dump.match_infra import MatchEngine, MatchRequest, ConnectionPool +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("|")[-2]+'|'+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_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 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/asic_db.json b/tests/dump_input/vlan/asic_db.json index 42e8f1b528..355cf66d06 100644 --- a/tests/dump_input/vlan/asic_db.json +++ b/tests/dump_input/vlan/asic_db.json @@ -1,96 +1,138 @@ { - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000629":{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000617":{ "SAI_VLAN_ATTR_VLAN_ID": "2" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000062a":{ + "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000618":{ "SAI_VLAN_ATTR_VLAN_ID": "3" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000062f": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000062e", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062a", + "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:0x2700000000062d": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000062c", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062a", + "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:0x3a00000000062e": { + "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:0x10000000002f6", + "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:0x3a00000000062c": { + "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:0x100000000037a", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x10000000002f6", "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000062b":{ + "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:0x27000000000631": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000630", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062b", + "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:0x27000000000633": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000632", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000062b", + "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:0x3a000000000630": { + "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:0x1000000000338", + "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:0x3a000000000632": { + "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:0x1000000000272", + "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000338", "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT" }, - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061c":{ + "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:0x2700000000061e": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000061d", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061c", + "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:0x2700000000061f": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000618", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x2600000000061c", + "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:0x3a00000000061d": { + "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:0x3a000000000618": { + "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_VLAN:oid:0x26000000000620":{ + "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:0x27000000000623": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000622", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000620", + "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:0x27000000000621": { - "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID": "oid:0x3a00000000061a", - "SAI_VLAN_MEMBER_ATTR_VLAN_ID": "oid:0x26000000000620", + "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:0x3a000000000622": { + "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", @@ -101,5 +143,19 @@ "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_tests/module_tests/vlan_test.py b/tests/dump_tests/module_tests/vlan_test.py index 362897f889..806fc61222 100644 --- a/tests/dump_tests/module_tests/vlan_test.py +++ b/tests/dump_tests/module_tests/vlan_test.py @@ -6,6 +6,7 @@ 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 @@ -69,30 +70,69 @@ def match_engine(): @pytest.mark.usefixtures("match_engine") class TestVlanModule: - def test_working_state(self, match_engine): + def test_working_state_vlan(self, match_engine): params = {} - params[Vlan.ARG_NAME] = "Vlan4" 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_TABLE:Vlan4") 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_TABLE|Vlan4") expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet16") expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan4|Ethernet24") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000062b") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000631") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000633") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000630") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000632") + 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" @@ -101,14 +141,9 @@ def test_missing_members(self, 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan2") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan2") - expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000629") - 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") + expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000617") ddiff = DeepDiff(returned, expect, ignore_order=True) assert not ddiff, ddiff @@ -120,12 +155,22 @@ def test_wrong_case_vlan(self, 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_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) @@ -139,12 +184,22 @@ def test_unconfigured_vlan(self, 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_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) @@ -158,12 +213,22 @@ def test_garbage_alpha_vlan(self, 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_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) @@ -177,12 +242,22 @@ def test_garbage_number_vlan(self, 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["CONFIG_DB"]["tables_not_found"].append("VLAN_MEMBER") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_TABLE") expect["STATE_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["STATE_DB"]["tables_not_found"].append("VLAN_MEMBER_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) @@ -197,22 +272,28 @@ def test_missing_appl_db(self, 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan6|Ethernet32") - expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan6|Ethernet40") expect["APPL_DB"]["tables_not_found"].append("VLAN_TABLE") - expect["APPL_DB"]["tables_not_found"].append("VLAN_MEMBER_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["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan6|Ethernet40") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x2600000000061c") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061e") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x2700000000061f") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061d") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000618") + 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, but adds bridge port tables in asic_db + # Vlan7 is not defined in state_db def test_missing_state_db(self, match_engine): params = {} params[Vlan.ARG_NAME] = "Vlan7" @@ -221,18 +302,24 @@ def test_missing_state_db(self, 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan7|Ethernet48") - expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan7|Ethernet56") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan7") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan7:Ethernet48") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan7:Ethernet56") 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:oid:0x26000000000620") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000623") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER:oid:0x27000000000621") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000622") - expect["ASIC_DB"]["keys"].append("ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a00000000061a") + 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 @@ -245,15 +332,22 @@ def test_missing_asic_db(self, 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["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan8|Ethernet64") - expect["CONFIG_DB"]["keys"].append("VLAN_MEMBER|Vlan8|Ethernet72") expect["APPL_DB"]["keys"].append("VLAN_TABLE:Vlan8") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan8:Ethernet64") - expect["APPL_DB"]["keys"].append("VLAN_MEMBER_TABLE:Vlan8:Ethernet72") expect["STATE_DB"]["keys"].append("VLAN_TABLE|Vlan8") - expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan8|Ethernet64") - expect["STATE_DB"]["keys"].append("VLAN_MEMBER_TABLE|Vlan8|Ethernet72") 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) @@ -266,3 +360,15 @@ def test_all_args(self, match_engine): 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 From 256403f7206cf6c81ff1b1096e97e2fe8fea21e6 Mon Sep 17 00:00:00 2001 From: Raphael Tryster Date: Tue, 12 Oct 2021 16:39:56 +0000 Subject: [PATCH 5/6] Changes after review of separate vlan and vlan_member modules Signed-off-by: Raphael Tryster --- dump/plugins/vlan.py | 5 +--- dump/plugins/vlan_member.py | 4 +-- tests/dump_input/vlan/appl_db.json | 28 +++++++++---------- tests/dump_input/vlan/asic_db.json | 10 +++---- tests/dump_input/vlan/config_db.json | 40 ++++++++++++++-------------- tests/dump_input/vlan/state_db.json | 26 +++++++++--------- 6 files changed, 55 insertions(+), 58 deletions(-) diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py index bef8fc7e38..82d9a0850e 100644 --- a/dump/plugins/vlan.py +++ b/dump/plugins/vlan.py @@ -24,7 +24,7 @@ def execute(self, params_dict): self.init_vlan_config_info(vlan_name) self.init_vlan_appl_info(vlan_name) self.init_state_vlan_info(vlan_name) - req, vlan_table = self.init_asic_vlan_info(vlan_name) + self.init_asic_vlan_info(vlan_name) return self.ret_temp def init_vlan_config_info(self, vlan_name): @@ -66,7 +66,4 @@ def init_asic_vlan_info(self, vlan_name): self.ret_temp[req.db]["keys"] = ret["keys"] else: self.ret_temp[req.db]["tables_not_found"] = [req.table] - - # Return request and table to caller in case its next call is to init_asic_vlan_member_info which also needs it - return req, ret diff --git a/dump/plugins/vlan_member.py b/dump/plugins/vlan_member.py index 9068f62fbb..f1b6a29464 100644 --- a/dump/plugins/vlan_member.py +++ b/dump/plugins/vlan_member.py @@ -15,7 +15,7 @@ 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("|")[-2]+'|'+key.split("|")[-1]) for key in all_vlans] + 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"]) @@ -102,7 +102,7 @@ def init_asic_vlan_member_info(self, vlan_name, member_name): 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 OID + # 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) diff --git a/tests/dump_input/vlan/appl_db.json b/tests/dump_input/vlan/appl_db.json index 5e4191a500..cc9d9916d3 100644 --- a/tests/dump_input/vlan/appl_db.json +++ b/tests/dump_input/vlan/appl_db.json @@ -1,56 +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 index 355cf66d06..8511cefbd9 100644 --- a/tests/dump_input/vlan/asic_db.json +++ b/tests/dump_input/vlan/asic_db.json @@ -1,15 +1,15 @@ { - "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000617":{ - "SAI_VLAN_ATTR_VLAN_ID": "2" - }, + "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": { + "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", diff --git a/tests/dump_input/vlan/config_db.json b/tests/dump_input/vlan/config_db.json index c7feeab601..4e034b85b4 100644 --- a/tests/dump_input/vlan/config_db.json +++ b/tests/dump_input/vlan/config_db.json @@ -1,56 +1,56 @@ { - "VLAN|Vlan2": { - "vlanid" : "2" - }, + "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 index 5c68128d89..994c867254 100644 --- a/tests/dump_input/vlan/state_db.json +++ b/tests/dump_input/vlan/state_db.json @@ -1,41 +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" - } + } } From 4fc97eb51f86e4ff33e2901f96035dc6b0085953 Mon Sep 17 00:00:00 2001 From: Raphael Tryster Date: Wed, 13 Oct 2021 13:32:07 +0000 Subject: [PATCH 6/6] Removed unused imports Signed-off-by: Raphael Tryster --- dump/plugins/vlan.py | 2 +- dump/plugins/vlan_member.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dump/plugins/vlan.py b/dump/plugins/vlan.py index 82d9a0850e..f753d0019a 100644 --- a/dump/plugins/vlan.py +++ b/dump/plugins/vlan.py @@ -1,5 +1,5 @@ from .executor import Executor -from dump.match_infra import MatchEngine, MatchRequest +from dump.match_infra import MatchRequest from dump.helper import create_template_dict class Vlan(Executor): diff --git a/dump/plugins/vlan_member.py b/dump/plugins/vlan_member.py index f1b6a29464..1518ac4bd7 100644 --- a/dump/plugins/vlan_member.py +++ b/dump/plugins/vlan_member.py @@ -1,5 +1,5 @@ from .executor import Executor -from dump.match_infra import MatchEngine, MatchRequest, ConnectionPool +from dump.match_infra import MatchRequest from dump.helper import create_template_dict class Vlan_Member(Executor):