Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vstest/subintf] Add vs test case to validate processing sequence of APPL DB keys #1663

Merged
merged 11 commits into from
Mar 10, 2021
73 changes: 73 additions & 0 deletions tests/test_sub_port_intf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
LAG_PREFIX = "PortChannel"

VLAN_SUB_INTERFACE_SEPARATOR = "."
APPL_DB_SEPARATOR = ":"


class TestSubPortIntf(object):
Expand Down Expand Up @@ -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}

Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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]
Expand Down