From 1345618439de1e0798233f1e11495493f51b9981 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Tue, 9 Mar 2021 16:15:57 -0800 Subject: [PATCH] [vstest/subintf] Add vs test case to validate processing sequence of APPL DB keys (#1663) Signed-off-by: Wenda Ni --- tests/test_sub_port_intf.py | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/test_sub_port_intf.py b/tests/test_sub_port_intf.py index 6a135e6cd1..5074599545 100644 --- a/tests/test_sub_port_intf.py +++ b/tests/test_sub_port_intf.py @@ -34,6 +34,7 @@ LAG_PREFIX = "PortChannel" VLAN_SUB_INTERFACE_SEPARATOR = "." +APPL_DB_SEPARATOR = ":" class TestSubPortIntf(object): @@ -102,12 +103,32 @@ def add_lag_members(self, lag, members): key = "{}|{}".format(lag, member) self.config_db.create_entry(CFG_LAG_MEMBER_TABLE_NAME, key, fvs) + def create_sub_port_intf_profile_appl_db(self, sub_port_intf_name, admin_status): + pairs = [ + (ADMIN_STATUS, admin_status), + ("mtu", "0"), + ] + fvs = swsscommon.FieldValuePairs(pairs) + + tbl = swsscommon.ProducerStateTable(self.app_db.db_connection, APP_INTF_TABLE_NAME) + tbl.set(sub_port_intf_name, fvs) + def add_sub_port_intf_ip_addr(self, sub_port_intf_name, ip_addr): fvs = {"NULL": "NULL"} key = "{}|{}".format(sub_port_intf_name, ip_addr) self.config_db.create_entry(CFG_VLAN_SUB_INTF_TABLE_NAME, key, fvs) + def add_sub_port_intf_ip_addr_appl_db(self, sub_port_intf_name, ip_addr): + pairs = [ + ("scope", "global"), + ("family", "IPv4" if "." in ip_addr else "IPv6"), + ] + fvs = swsscommon.FieldValuePairs(pairs) + + tbl = swsscommon.ProducerStateTable(self.app_db.db_connection, APP_INTF_TABLE_NAME) + tbl.set(sub_port_intf_name + APPL_DB_SEPARATOR + ip_addr, fvs) + def set_sub_port_intf_admin_status(self, sub_port_intf_name, status): fvs = {ADMIN_STATUS: status} @@ -124,6 +145,10 @@ def remove_sub_port_intf_profile(self, sub_port_intf_name): def check_sub_port_intf_profile_removal(self, rif_oid): self.asic_db.wait_for_deleted_keys(ASIC_RIF_TABLE, [rif_oid]) + def remove_sub_port_intf_profile_appl_db(self, sub_port_intf_name): + tbl = swsscommon.ProducerStateTable(self.app_db.db_connection, APP_INTF_TABLE_NAME) + tbl._del(sub_port_intf_name) + def remove_sub_port_intf_ip_addr(self, sub_port_intf_name, ip_addr): key = "{}|{}".format(sub_port_intf_name, ip_addr) self.config_db.delete_entry(CFG_VLAN_SUB_INTF_TABLE_NAME, key) @@ -132,6 +157,10 @@ def check_sub_port_intf_ip_addr_removal(self, sub_port_intf_name, ip_addrs): interfaces = ["{}:{}".format(sub_port_intf_name, addr) for addr in ip_addrs] self.app_db.wait_for_deleted_keys(APP_INTF_TABLE_NAME, interfaces) + def remove_sub_port_intf_ip_addr_appl_db(self, sub_port_intf_name, ip_addr): + tbl = swsscommon.ProducerStateTable(self.app_db.db_connection, APP_INTF_TABLE_NAME) + tbl._del(sub_port_intf_name + APPL_DB_SEPARATOR + ip_addr) + def get_oids(self, table): return self.asic_db.get_keys(table) @@ -320,6 +349,50 @@ def test_sub_port_intf_add_ip_addrs(self, dvs): self._test_sub_port_intf_add_ip_addrs(dvs, self.SUB_PORT_INTERFACE_UNDER_TEST) self._test_sub_port_intf_add_ip_addrs(dvs, self.LAG_SUB_PORT_INTERFACE_UNDER_TEST) + def _test_sub_port_intf_appl_db_proc_seq(self, dvs, sub_port_intf_name, admin_up): + substrs = sub_port_intf_name.split(VLAN_SUB_INTERFACE_SEPARATOR) + parent_port = substrs[0] + vlan_id = substrs[1] + + old_rif_oids = self.get_oids(ASIC_RIF_TABLE) + + self.set_parent_port_admin_status(dvs, parent_port, "up") + + # Create ip address configuration in APPL_DB before creating configuration for sub port interface itself + self.add_sub_port_intf_ip_addr_appl_db(sub_port_intf_name, self.IPV4_ADDR_UNDER_TEST) + self.add_sub_port_intf_ip_addr_appl_db(sub_port_intf_name, self.IPV6_ADDR_UNDER_TEST) + time.sleep(2) + + # Create sub port interface configuration in APPL_DB + self.create_sub_port_intf_profile_appl_db(sub_port_intf_name, "up" if admin_up == True else "down") + + # Verify that a sub port router interface entry is created in ASIC_DB + fv_dict = { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "{}".format(vlan_id), + "SAI_ROUTER_INTERFACE_ATTR_ADMIN_V4_STATE": "true" if admin_up == True else "false", + "SAI_ROUTER_INTERFACE_ATTR_ADMIN_V6_STATE": "true" if admin_up == True else "false", + "SAI_ROUTER_INTERFACE_ATTR_MTU": DEFAULT_MTU, + } + rif_oid = self.get_newly_created_oid(ASIC_RIF_TABLE, old_rif_oids) + self.check_sub_port_intf_fvs(self.asic_db, ASIC_RIF_TABLE, rif_oid, fv_dict) + + # Remove ip addresses from APPL_DB + self.remove_sub_port_intf_ip_addr_appl_db(sub_port_intf_name, self.IPV4_ADDR_UNDER_TEST) + self.remove_sub_port_intf_ip_addr_appl_db(sub_port_intf_name, self.IPV6_ADDR_UNDER_TEST) + # Remove sub port interface from APPL_DB + self.remove_sub_port_intf_profile_appl_db(sub_port_intf_name) + self.check_sub_port_intf_profile_removal(rif_oid) + + def test_sub_port_intf_appl_db_proc_seq(self, dvs): + self.connect_dbs(dvs) + + self._test_sub_port_intf_appl_db_proc_seq(dvs, self.SUB_PORT_INTERFACE_UNDER_TEST, admin_up=True) + self._test_sub_port_intf_appl_db_proc_seq(dvs, self.SUB_PORT_INTERFACE_UNDER_TEST, admin_up=False) + + self._test_sub_port_intf_appl_db_proc_seq(dvs, self.LAG_SUB_PORT_INTERFACE_UNDER_TEST, admin_up=True) + self._test_sub_port_intf_appl_db_proc_seq(dvs, self.LAG_SUB_PORT_INTERFACE_UNDER_TEST, admin_up=False) + def _test_sub_port_intf_admin_status_change(self, dvs, sub_port_intf_name): substrs = sub_port_intf_name.split(VLAN_SUB_INTERFACE_SEPARATOR) parent_port = substrs[0]