Skip to content

Commit

Permalink
Fixed DPB system test cases to bring stability
Browse files Browse the repository at this point in the history
Signed-off-by: Sangita Maity <samaity@linkedin.com>
  • Loading branch information
Sangita Maity committed Jun 24, 2021
1 parent b8b2df2 commit cfbc8ce
Showing 1 changed file with 73 additions and 45 deletions.
118 changes: 73 additions & 45 deletions tests/test_port_dpb_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from port_dpb import Port
from port_dpb import DPB
from dvslib.dvs_common import wait_for_result, PollingConfig
from swsscommon import swsscommon
import time

ARP_FLUSH_POLLING = PollingConfig(polling_interval=0.01, timeout=10, strict=True)
ROUTE_CHECK_POLLING = PollingConfig(polling_interval=0.01, timeout=5, strict=True)
Expand All @@ -17,10 +19,12 @@
@pytest.mark.usefixtures('dvs_vlan_manager')
class TestPortDPBSystem(object):

def create_l3_intf(self, dvs, interface, vrf_name):
dvs_asic_db = dvs.get_asic_db()
initial_entries = set(dvs_asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE"))
def setup_db(self, dvs):
self.pdb = dvs.get_app_db()
self.adb = dvs.get_asic_db()
self.cdb = dvs.get_config_db()

def create_l3_intf(self, dvs, interface, vrf_name):
if interface.startswith("PortChannel"):
tbl_name = "PORTCHANNEL_INTERFACE"
elif interface.startswith("Vlan"):
Expand All @@ -31,15 +35,13 @@ def create_l3_intf(self, dvs, interface, vrf_name):
tbl_name = "INTERFACE"

if len(vrf_name) == 0:
fvs = {'NULL':'NULL'}
fvs = swsscommon.FieldValuePairs([("NULL", "NULL")])
else:
fvs = {'vrf_name':vrf_name}
dvs.get_config_db().create_entry(tbl_name, interface, fvs)
fvs = swsscommon.FieldValuePairs([("vrf_name", vrf_name)])

dvs_asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", len(initial_entries)+1)
current_entries = set(dvs_asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE"))
assert len(current_entries - initial_entries) == 1
return list(current_entries - initial_entries)[0]
tbl = swsscommon.Table(self.cdb, tbl_name)
tbl.set(interface, fvs)
time.sleep(1)

def remove_l3_intf(self, dvs, interface):
if interface.startswith("PortChannel"):
Expand All @@ -51,7 +53,9 @@ def remove_l3_intf(self, dvs, interface):
else:
tbl_name = "INTERFACE"

dvs.get_config_db().delete_entry(tbl_name, interface)
tbl = swsscommon.Table(self.cdb, tbl_name)
tbl._del(interface)
time.sleep(1)

def add_ip_address(self, dvs, interface, ip):
if interface.startswith("PortChannel"):
Expand All @@ -63,7 +67,8 @@ def add_ip_address(self, dvs, interface, ip):
else:
tbl_name = "INTERFACE"

dvs.get_config_db().create_entry(tbl_name, interface+'|'+ip, {'NULL':'NULL'})
self.cdb.create_entry(tbl_name, interface+'|'+ip, {'NULL':'NULL'})
time.sleep(1)

def remove_ip_address(self, dvs, interface, ip):
if interface.startswith("PortChannel"):
Expand All @@ -75,23 +80,26 @@ def remove_ip_address(self, dvs, interface, ip):
else:
tbl_name = "INTERFACE"

dvs.get_config_db().delete_entry(tbl_name, interface+'|'+ip)
self.cdb.delete_entry(tbl_name, interface+'|'+ip)
time.sleep(1)

def clear_srv_config(self, dvs):
dvs.servers[0].runcmd("ip address flush dev eth0")
dvs.servers[1].runcmd("ip address flush dev eth0")
dvs.servers[2].runcmd("ip address flush dev eth0")
dvs.servers[3].runcmd("ip address flush dev eth0")
time.sleep(1)

def set_admin_status(self, dvs, interface, status):
dvs_cfg_db = dvs.get_config_db()
dvs_cfg_db = self.cdb
if interface.startswith("PortChannel"):
tbl_name = "PORTCHANNEL"
elif interface.startswith("Vlan"):
tbl_name = "VLAN"
else:
tbl_name = "PORT"
dvs_cfg_db.create_entry(tbl_name, interface, {'admin_status':status})
time.sleep(1)

def verify_only_ports_exist(self, dvs, port_names):
all_port_names = ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"]
Expand Down Expand Up @@ -124,7 +132,6 @@ def verify_only_ports_exist(self, dvs, port_names):
|-----------------------------------------------------------------------------------------------------
| 1x50G(2)+2x25G(2) | | P | | P | P | P | NA |
|-----------------------------------------------------------------------------------------------------
NA --> Not Applicable
P --> Pass
F --> Fail
Expand Down Expand Up @@ -152,8 +159,11 @@ def verify_only_ports_exist(self, dvs, port_names):
('Ethernet0', '1x50G(2)+2x25G(2)'),
('Ethernet0', '1x100G[40G]')
], scope="function")

def test_port_breakout_simple(self, dvs, root_port, breakout_mode):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

dvs.change_port_breakout_mode(root_port, breakout_mode)
Expand All @@ -162,7 +172,9 @@ def test_port_breakout_simple(self, dvs, root_port, breakout_mode):
self.verify_only_ports_exist(dvs, expected_ports)

def test_port_breakout_with_vlan(self, dvs):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

portName = "Ethernet0"
Expand Down Expand Up @@ -205,9 +217,11 @@ def test_port_breakout_with_vlan(self, dvs):
# Verify DPB is successful
dpb.verify_port_breakout_mode(dvs, "Ethernet0", breakoutMode1)

@pytest.mark.skip(reason="This test is not stable enough")

def test_port_breakout_with_acl(self, dvs, dvs_acl):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

# Create ACL table "test" and bind it to Ethernet0
Expand Down Expand Up @@ -257,7 +271,9 @@ def test_port_breakout_with_acl(self, dvs, dvs_acl):

@pytest.mark.skip("DEBUG: When we have more than one child ports, operation status of all does NOT go down")
def test_cli_command_with_force_option(self, dvs, dvs_acl):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

portGroup = ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"]
Expand Down Expand Up @@ -327,16 +343,16 @@ def test_cli_command_with_force_option(self, dvs, dvs_acl):
self.set_admin_status(dvs, "Ethernet8", "up")

# Create L3 interface
self.create_l3_intf(dvs, "Ethernet8", "");
self.create_l3_intf(dvs, "Ethernet8", "")

# Configure IPv4 address on Ethernet8
self.add_ip_address(dvs, "Ethernet8", Ethernet8_IP)

# one loopback router interface and one port based router interface
dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 2)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 2)

def _check_route_present():
routes = dvs.get_asic_db().get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
routes = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
subnet_found = False
ip2me_found = False
for route in routes:
Expand All @@ -358,10 +374,10 @@ def _check_route_present():

# check ASIC router interface database
# one loopback router interface
dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)

def _check_route_absent():
routes = dvs.get_asic_db().get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
routes = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
for route in routes:
rt = json.loads(route)
if rt["dest"] == Ethernet8_IP or \
Expand All @@ -378,7 +394,9 @@ def _check_route_absent():

@pytest.mark.skip("DEBUG: When we have more than one child ports, operation status of all does NOT go down")
def test_cli_command_with_load_port_breakout_config_option(self, dvs, dvs_acl):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

# Note below definitions are dependent on port_breakout_config_db.json
Expand Down Expand Up @@ -493,7 +511,7 @@ def test_cli_command_with_load_port_breakout_config_option(self, dvs, dvs_acl):

# check ASIC router interface database
# one loopback router interface
dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)

# Breakout Ethernet8 WITH "-l" option and ensure
# ip address gets configured as per port_breakout_config_db.json
Expand All @@ -502,10 +520,10 @@ def test_cli_command_with_load_port_breakout_config_option(self, dvs, dvs_acl):
dpb.verify_port_breakout_mode(dvs, "Ethernet8", breakoutMode2x)

# one loopback router interface and one port based router interface
dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 2)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 2)

def _check_route_present():
routes = dvs.get_asic_db().get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
routes = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
subnet_found = False
ip2me_found = False
for route in routes:
Expand All @@ -527,10 +545,10 @@ def _check_route_present():

# check ASIC router interface database
# one loopback router interface
dvs.get_asic_db().wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE", 1)

def _check_route_absent():
routes = dvs.get_asic_db().get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
routes = self.adb.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
for route in routes:
rt = json.loads(route)
if rt["dest"] == Ethernet8_IP or \
Expand All @@ -541,9 +559,11 @@ def _check_route_absent():
status, result = wait_for_result(_check_route_absent, ROUTE_CHECK_POLLING)
assert status == True

@pytest.mark.skip(reason="This test is not stable enough")

def test_cli_command_negative(self, dvs, dvs_acl):
dvs.setup_db()
# initialize
self.setup_db(dvs)

dpb = DPB()

portGroup = ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"]
Expand Down Expand Up @@ -625,10 +645,12 @@ def test_cli_command_negative(self, dvs, dvs_acl):
dvs_acl.verify_acl_table_count(0)
self.dvs_vlan.get_and_verify_vlan_ids(0)

@pytest.mark.skip(reason="This test is not stable enough")

def test_dpb_arp_flush(self, dvs):
dvs.setup_db()
dvs_asic_db = dvs.get_asic_db()
# initialize
self.setup_db(dvs)

dvs_asic_db = self.adb
dpb = DPB()

portName = "Ethernet0"
Expand Down Expand Up @@ -676,10 +698,12 @@ def test_dpb_arp_flush(self, dvs):
dvs.change_port_breakout_mode("Ethernet0", "1x100G[40G]")
dpb.verify_port_breakout_mode(dvs, "Ethernet0", "1x100G[40G]")

@pytest.mark.skip(reason="This test is not stable enough")

def test_dpb_arp_flush_vlan(self, dvs):
dvs.setup_db()
dvs_asic_db = dvs.get_asic_db()
# initialize
self.setup_db(dvs)

dvs_asic_db = self.adb
dpb = DPB()

self.clear_srv_config(dvs)
Expand Down Expand Up @@ -740,10 +764,12 @@ def test_dpb_arp_flush_vlan(self, dvs):
# Remove VLAN(note that member was removed during port breakout)
self.dvs_vlan.remove_vlan(vlanID)

@pytest.mark.skip(reason="This test is not stable enough")

def test_dpb_arp_flush_on_port_oper_shut(self, dvs):
dvs.setup_db()
dvs_asic_db = dvs.get_asic_db()
# initialize
self.setup_db(dvs)

dvs_asic_db = self.adb
dpb = DPB()

self.clear_srv_config(dvs)
Expand Down Expand Up @@ -805,10 +831,12 @@ def test_dpb_arp_flush_on_port_oper_shut(self, dvs):
self.dvs_vlan.remove_vlan_member(vlanID, portName)
self.dvs_vlan.remove_vlan(vlanID)

@pytest.mark.skip(reason="This test is not stable enough")

def test_dpb_arp_flush_on_vlan_member_remove(self, dvs):
dvs.setup_db()
dvs_asic_db = dvs.get_asic_db()
# initialize
self.setup_db(dvs)

dvs_asic_db = self.adb
dpb = DPB()

self.clear_srv_config(dvs)
Expand Down

0 comments on commit cfbc8ce

Please sign in to comment.