Skip to content
40 changes: 23 additions & 17 deletions tests/pc/test_lag_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def __get_lag_intf_info(self, lag_facts, lag_name):
intf = lag_facts['lags'][lag_name]['po_config']['ports'].keys()[0]
return intf, po_interfaces

def __get_lag_intf_namespace_id(self, lag_facts, lag_name):
return (lag_facts['lags'][lag_name]['po_namespace_id'])

def __check_flap(self, lag_facts, lag_name):
po_intf_num = len(lag_facts['lags'][lag_name]['po_config']['ports'])
po_min_links = lag_facts['lags'][lag_name]['po_config']['runner']['min_ports']
Expand Down Expand Up @@ -83,20 +86,26 @@ def __verify_lag_minlink(
self,
host,
lag_name,
intf,
neighbor_intf, po_interfaces, po_flap, deselect_time, wait_timeout = 30):
lag_facts,
neighbor_intf, deselect_time, wait_timeout = 30):
delay = 5

try:
host.shutdown(neighbor_intf)

# Let PortalChannel react to neighbor interface shutdown
time.sleep(deselect_time)
intf, po_interfaces = self.__get_lag_intf_info(lag_facts, lag_name)
po_flap = self.__check_flap(lag_facts, lag_name)
namespace_id = self.__get_lag_intf_namespace_id(lag_facts, lag_name)
namespace_prefix = '-n ' + str(namespace_id) if namespace_id else ''


# Verify PortChannel interfaces are up correctly
for po_intf in po_interfaces.keys():
if po_intf != intf:
command = 'bash -c "teamdctl %s state dump" | python -c "import sys, json; print json.load(sys.stdin)[\'ports\'][\'%s\'][\'runner\'][\'selected\']"' % (lag_name, po_intf)
command = 'bash -c "teamdctl %s %s state dump" | python -c "import sys, json; print json.load(sys.stdin)[\'ports\'][\'%s\'][\'runner\'][\'selected\']"' \
% (namespace_prefix, lag_name, po_intf)
wait_until(wait_timeout, delay, self.__check_shell_output, self.duthost, command)

# Refresh lag facts
Expand All @@ -119,13 +128,13 @@ def __verify_lag_minlink(
# Verify PortChannel interfaces are up correctly
for po_intf in po_interfaces.keys():
if po_intf != intf:
command = 'bash -c "teamdctl %s state dump" | python -c "import sys, json; print json.load(sys.stdin)[\'ports\'][\'%s\'][\'link\'][\'up\']"' % (lag_name, po_intf)
command = 'bash -c "teamdctl %s %s state dump" | python -c "import sys, json; print json.load(sys.stdin)[\'ports\'][\'%s\'][\'link\'][\'up\']"'\
% (namespace_prefix, lag_name, po_intf)
wait_until(wait_timeout, delay, self.__check_shell_output, self.duthost, command)

def run_single_lag_lacp_rate_test(self, lag_name):
def run_single_lag_lacp_rate_test(self, lag_name, lag_facts):
logger.info("Start checking single lag lacp rate for: %s" % lag_name)

lag_facts = self.__get_lag_facts()
intf, po_interfaces = self.__get_lag_intf_info(lag_facts, lag_name)
peer_device = self.vm_neighbors[intf]['name']

Expand Down Expand Up @@ -169,28 +178,25 @@ def run_single_lag_lacp_rate_test(self, lag_name):
logger.info("Changing lacp rate to slow for %s in %s" % (neighbor_lag_member, peer_device))
vm_host.set_interface_lacp_rate_mode(neighbor_lag_member, 'normal')

def run_single_lag_test(self, lag_name):
def run_single_lag_test(self, lag_name, lag_facts):
logger.info("Start checking single lag for: %s" % lag_name)

lag_facts = self.__get_lag_facts()
intf, po_interfaces = self.__get_lag_intf_info(lag_facts, lag_name)
po_flap = self.__check_flap(lag_facts, lag_name)
intf, _ = self.__get_lag_intf_info(lag_facts, lag_name)

# Figure out fanout switches info if exists for the lag member and run minlink test
if intf in self.fanout_neighbors.keys():
peer_device = self.fanout_neighbors[intf]['peerdevice']
neighbor_intf = self.fanout_neighbors[intf]['peerport']
self.__verify_lag_minlink(self.fanouthosts[peer_device], lag_name, intf, neighbor_intf, po_interfaces, po_flap, deselect_time=5)
self.__verify_lag_minlink(self.fanouthosts[peer_device], lag_name, lag_facts, neighbor_intf, deselect_time=5)

# Figure out remote VM and interface info for the lag member and run minlink test
peer_device = self.vm_neighbors[intf]['name']
neighbor_intf = self.vm_neighbors[intf]['port']
self.__verify_lag_minlink(self.nbrhosts[peer_device]['host'], lag_name, intf, neighbor_intf, po_interfaces, po_flap, deselect_time=95)
self.__verify_lag_minlink(self.nbrhosts[peer_device]['host'], lag_name, lag_facts, neighbor_intf, deselect_time=95)

def run_lag_fallback_test(self, lag_name):
def run_lag_fallback_test(self, lag_name, lag_facts):
logger.info("Start checking lag fall back for: %s" % lag_name)

lag_facts = self.__get_lag_facts()
intf, po_interfaces = self.__get_lag_intf_info(lag_facts, lag_name)
po_fallback = lag_facts['lags'][lag_name]['po_config']['runner']['fallback']

Expand Down Expand Up @@ -266,9 +272,9 @@ def test_lag(common_setup_teardown, duthosts, tbinfo, nbrhosts, fanouthosts, con
else:
some_test_ran = True
if testcase == "single_lag":
test_instance.run_single_lag_test(lag_name)
test_instance.run_single_lag_test(lag_name, lag_facts)
else:
test_instance.run_single_lag_lacp_rate_test(lag_name)
test_instance.run_single_lag_lacp_rate_test(lag_name, lag_facts)
else: # fallback testcase
try:
lag_facts['lags'][lag_name]['po_config']['runner']['fallback']
Expand All @@ -278,6 +284,6 @@ def test_lag(common_setup_teardown, duthosts, tbinfo, nbrhosts, fanouthosts, con
continue
else:
some_test_ran = True
test_instance.run_lag_fallback_test(lag_name)
test_instance.run_lag_fallback_test(lag_name, lag_facts)

pytest_assert(some_test_ran, "Didn't run any test.")