From 90c5f7b3322899d4bb9aa95ef1ca2897958ddb82 Mon Sep 17 00:00:00 2001 From: falodiya Date: Mon, 25 Jan 2021 18:36:24 -0500 Subject: [PATCH 1/5] Modified testcase to run on T2 topology --- ansible/roles/test/files/ptftests/mtu_test.py | 29 ++--- tests/ipfwd/test_mtu.py | 105 +++++++++++++++++- 2 files changed, 116 insertions(+), 18 deletions(-) diff --git a/ansible/roles/test/files/ptftests/mtu_test.py b/ansible/roles/test/files/ptftests/mtu_test.py index 4645980424f..1691177279d 100644 --- a/ansible/roles/test/files/ptftests/mtu_test.py +++ b/ansible/roles/test/files/ptftests/mtu_test.py @@ -50,6 +50,11 @@ def setUp(self): self.router_mac = self.test_params['router_mac'] self.testbed_type = self.test_params['testbed_type'] self.testbed_mtu = self.test_params['testbed_mtu'] + self.src_host_ip = self.test_params.get('src_host_ip') + self.src_router_ip = self.test_params.get('src_router_ip') + self.dst_host_ip = self.test_params.get('dst_host_ip') + self.src_ptf_port_list = self.test_params.get('src_ptf_port_list') + self.dst_ptf_port_list = self.test_params.get('dst_ptf_port_list') #--------------------------------------------------------------------- @@ -57,9 +62,9 @@ def check_icmp_mtu(self): ''' @summary: Check ICMP/Ping to DUT works for MAX MTU. ''' - ip_src = "10.0.0.1" - ip_dst = "10.0.0.0" - src_mac = self.dataplane.get_mac(0, 0) + ip_src = self.src_host_ip + ip_dst = self.src_router_ip + src_mac = self.dataplane.get_mac(0, self.src_ptf_port_list[0]) pktlen = self.pktlen pkt = simple_icmp_packet(pktlen=pktlen, @@ -82,10 +87,10 @@ def check_icmp_mtu(self): masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "ttl") masked_exp_pkt.set_do_not_care_scapy(scapy.ICMP, "chksum") - src_port = 0 + src_port = self.src_ptf_port_list[0] send_packet(self, src_port, pkt) logging.info("Sending packet from port " + str(src_port) + " to " + ip_dst) - dst_port_list = [0,1] + dst_port_list = self.src_ptf_port_list (matched_index, received) = verify_packet_any_port(self, masked_exp_pkt, dst_port_list) @@ -102,9 +107,9 @@ def check_ip_mtu(self): ''' @summary: Check unicast IP forwarding in DUT works for MAX MTU. ''' - ip_src = "10.0.0.1" - ip_dst = "10.0.0.63" - src_mac = self.dataplane.get_mac(0, 0) + ip_src = self.src_host_ip + ip_dst = self.dst_host_ip + src_mac = self.dataplane.get_mac(0, self.src_ptf_port_list[0]) pkt = simple_ip_packet(pktlen=self.pktlen, eth_dst=self.router_mac, @@ -122,15 +127,11 @@ def check_ip_mtu(self): masked_exp_pkt = Mask(exp_pkt) masked_exp_pkt.set_do_not_care_scapy(scapy.Ether, "dst") - src_port = 0 + src_port = self.src_ptf_port_list[0] send_packet(self, src_port, pkt) logging.info("Sending packet from port " + str(src_port) + " to " + ip_dst) - dst_port_list = [] - if self.testbed_type == 't1' or self.testbed_type == 't1-lag': - dst_port_list = [31] - elif self.testbed_type == 't1-64-lag' or self.testbed_type == 't1-64-lag-clet': - dst_port_list = [58] + dst_port_list = self.dst_ptf_port_list (matched_index, received) = verify_packet_any_port(self, masked_exp_pkt, dst_port_list) assert received diff --git a/tests/ipfwd/test_mtu.py b/tests/ipfwd/test_mtu.py index 2dcd385234e..acab5d6350e 100644 --- a/tests/ipfwd/test_mtu.py +++ b/tests/ipfwd/test_mtu.py @@ -7,12 +7,103 @@ from datetime import datetime pytestmark = [ - pytest.mark.topology('t1') + pytest.mark.topology('t1', 't2') ] +''' +In case of multi-dut we need src_host_ip, src_router_ip, dst_host_ip, src_ptf_port_list, dst_ptf_port_list for the dut under test, +to take care of that made changes in the testcase +''' + +def lag_facts(dut, mg_facts): + facts = {} + + if not mg_facts['minigraph_portchannels']: + pytest.fail("minigraph_portchannels is not defined") + + # minigraph facts + src_lag = mg_facts['minigraph_portchannel_interfaces'][0]['attachto'] + dst_lag = mg_facts['minigraph_portchannel_interfaces'][2]['attachto'] + logger.info("src_lag is {}, dst_lag is {}".format(src_lag, dst_lag)) + + for intf in mg_facts['minigraph_portchannel_interfaces']: + if intf['attachto'] == dst_lag: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + facts['dst_router_ip'] = intf['addr'] + facts['dst_host_ip'] = intf['peer_addr'] + if intf['attachto'] == src_lag: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + facts['src_router_ip'] = intf['addr'] + facts['src_host_ip'] = intf['peer_addr'] + + facts['dst_port_ids'] = [] + for intf in mg_facts['minigraph_portchannels'][dst_lag]['members']: + facts['dst_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) + + facts['src_port_ids'] = [] + for intf in mg_facts['minigraph_portchannels'][src_lag]['members']: + facts['src_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) + + return facts + + +def port_facts(dut, mg_facts): + facts = {} + + if not mg_facts['minigraph_interfaces']: + pytest.fail("minigraph_interfaces is not defined.") + + # minigraph facts + src_port = mg_facts['minigraph_interfaces'][0]['attachto'] + dst_port = mg_facts['minigraph_interfaces'][2]['attachto'] + logger.info("src_port is {}, dst_port is {}".format(src_port, dst_port)) + + + for intf in mg_facts['minigraph_interfaces']: + if intf['attachto'] == dst_port: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + facts['dst_router_ip'] = intf['addr'] + facts['dst_host_ip'] = intf['peer_addr'] + if intf['attachto'] == src_port: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + facts['src_router_ip'] = intf['addr'] + facts['src_host_ip'] = intf['peer_addr'] + + facts['dst_port_ids'] = [mg_facts['minigraph_ptf_indices'][dst_port]] + facts['src_port_ids'] = [mg_facts['minigraph_ptf_indices'][src_port]] + + return facts + + +@pytest.fixture(scope='function') +def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] + facts = {} + + topo_type = tbinfo['topo']['type'] + if topo_type not in ('t0', 't1', 't2'): + pytest.skip("Unsupported topology") + + logger.info("Gathering facts on DUT ...") + mg_facts = duthost.get_extended_minigraph_facts(tbinfo) + + # if minigraph_portchannel_interfaces is not empty - topology with lag + if mg_facts['minigraph_portchannel_interfaces']: + facts = lag_facts(duthost, mg_facts) + else: + facts = port_facts(duthost, mg_facts) + + logger.info("gathered_facts={}".format(json.dumps(facts, indent=2))) + + yield facts + @pytest.mark.parametrize("mtu", [1514,9114]) -def test_mtu(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, mtu): - duthost = duthosts[rand_one_dut_hostname] +def test_mtu(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, mtu, gather_facts): + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] testbed_type = tbinfo['topo']['name'] router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") @@ -27,6 +118,12 @@ def test_mtu(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, mtu): platform_dir="ptftests", params={"testbed_type": testbed_type, "router_mac": router_mac, - "testbed_mtu": mtu }, + "testbed_mtu": mtu, + "src_host_ip": gather_facts['src_host_ip'], + "src_router_ip": gather_facts['src_router_ip'], + "dst_host_ip": gather_facts['dst_host_ip'], + "src_ptf_port_list": gather_facts['src_port_ids'], + "dst_ptf_port_list": gather_facts['dst_port_ids'] + }, log_file=log_file, socket_recv_size=16384) From e744a684381e0facf062a7480e5f24c93fe47cdd Mon Sep 17 00:00:00 2001 From: falodiya Date: Sun, 31 Jan 2021 00:11:42 -0500 Subject: [PATCH 2/5] Added support to pick only up lag and ports as per the comment --- tests/ipfwd/test_dip_sip.py | 149 ++++++++++++++++++------------------ tests/ipfwd/test_mtu.py | 128 ++++++++++++++++--------------- 2 files changed, 142 insertions(+), 135 deletions(-) diff --git a/tests/ipfwd/test_dip_sip.py b/tests/ipfwd/test_dip_sip.py index 0301b87ae36..baafb430235 100644 --- a/tests/ipfwd/test_dip_sip.py +++ b/tests/ipfwd/test_dip_sip.py @@ -24,80 +24,59 @@ def lldp_setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, patch_lldpct yield unpatch_lldpctl(localhost, duthost) - -def lag_facts(dut, mg_facts): - facts = {} - +def get_lag_facts(dut, lag_facts, switch_arptable, mg_facts, ignore_lags, test_facts, key='src'): if not mg_facts['minigraph_portchannels']: pytest.fail("minigraph_portchannels is not defined") # minigraph facts - src_lag = mg_facts['minigraph_portchannel_interfaces'][2]['attachto'] - dst_lag = mg_facts['minigraph_portchannel_interfaces'][0]['attachto'] - logger.info("src_lag is {}, dst_lag is {}".format(src_lag, dst_lag)) - - # lldp facts - lldp_facts = dut.lldp()['ansible_facts']['lldp'] - facts['dst_host_mac'] = lldp_facts[mg_facts['minigraph_portchannels'][dst_lag]['members'][0]]['chassis']['mac'] - facts['src_host_mac'] = lldp_facts[mg_facts['minigraph_portchannels'][src_lag]['members'][0]]['chassis']['mac'] - - facts['dst_router_mac'] = dut.facts['router_mac'] - facts['src_router_mac'] = dut.facts['router_mac'] - - for intf in mg_facts['minigraph_portchannel_interfaces']: - if intf['attachto'] == dst_lag: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['dst_router_ipv4'] = intf['addr'] - facts['dst_host_ipv4'] = intf['peer_addr'] - elif addr.version == 6: - facts['dst_router_ipv6'] = intf['addr'] - facts['dst_host_ipv6'] = intf['peer_addr'] - - facts['dst_port_ids'] = [] - for intf in mg_facts['minigraph_portchannels'][dst_lag]['members']: - facts['dst_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) - - facts['src_port_ids'] = [] - for intf in mg_facts['minigraph_portchannels'][src_lag]['members']: - facts['src_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) - - return facts - - -def port_facts(dut, mg_facts): - facts = {} - + up_lag = None + for a_lag_name, a_lag_data in lag_facts['lags'].items(): + if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: + # We found a portchannel that is up. + up_lag = a_lag_name + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] + test_facts[key + '_router_mac'] = dut.facts['router_mac'] + for intf in mg_facts['minigraph_portchannel_interfaces']: + if intf['attachto'] == up_lag: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ipv4'] = intf['addr'] + test_facts[key + '_host_ipv4'] = intf['peer_addr'] + test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + elif addr.version == 6: + test_facts[key + '_router_ipv6'] = intf['addr'] + test_facts[key + '_host_ipv6'] = intf['peer_addr'] + logger.info("{} lag is {}".format(key, up_lag)) + break + + return up_lag + + +def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, test_facts, key='src'): if not mg_facts['minigraph_interfaces']: pytest.fail("minigraph_interfaces is not defined.") - # minigraph facts - src_port = mg_facts['minigraph_interfaces'][2]['attachto'] - dst_port = mg_facts['minigraph_interfaces'][0]['attachto'] - logger.info("src_port is {}, dst_port is {}".format(src_port, dst_port)) - - # lldp facts - lldp_facts = dut.lldp()['ansible_facts']['lldp'] - facts['dst_host_mac'] = lldp_facts[dst_port]['chassis']['mac'] - facts['src_host_mac'] = lldp_facts[src_port]['chassis']['mac'] - - facts['dst_router_mac'] = dut.facts['router_mac'] - facts['src_router_mac'] = dut.facts['router_mac'] - - for intf in mg_facts['minigraph_interfaces']: - if intf['attachto'] == dst_port: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['dst_router_ipv4'] = intf['addr'] - facts['dst_host_ipv4'] = intf['peer_addr'] - elif addr.version == 6: - facts['dst_router_ipv6'] = intf['addr'] - facts['dst_host_ipv6'] = intf['peer_addr'] - - facts['dst_port_ids'] = [mg_facts['minigraph_ptf_indices'][dst_port]] - facts['src_port_ids'] = [mg_facts['minigraph_ptf_indices'][src_port]] - - return facts + up_port = None + for a_intf_name, a_intf_data in port_status['int_status'].items(): + if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: + # Got a port that is up and not already used. + for intf in mg_facts['minigraph_interfaces']: + if intf['attachto'] == a_intf_name: + up_port = a_intf_name + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] + test_facts[key + '_router_mac'] = dut.facts['router_mac'] + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ipv4'] = intf['addr'] + test_facts[key + '_host_ipv4'] = intf['peer_addr'] + test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + elif addr.version == 6: + test_facts[key + '_router_ipv6'] = intf['addr'] + test_facts[key + '_host_ipv6'] = intf['peer_addr'] + if up_port: + logger.info("{} port is {}".format(key, up_port)) + break + return up_port @pytest.fixture(scope='function') @@ -112,14 +91,36 @@ def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): logger.info("Gathering facts on DUT ...") mg_facts = duthost.get_extended_minigraph_facts(tbinfo) - # if minigraph_portchannel_interfaces is not empty - topology with lag - if mg_facts['minigraph_portchannel_interfaces']: - facts = lag_facts(duthost, mg_facts) - else: - facts = port_facts(duthost, mg_facts) - - logger.info("gathered_facts={}".format(json.dumps(facts, indent=2))) + # Use the arp table to get the mac address of the host (VM's) instead of lldp_facts as that is was is used + # by the DUT to forward traffic - regardless of lag or port. + switch_arptable = duthost.switch_arptable()['ansible_facts'] + used_intfs = set() + src = None # Name of lag or interface that is is up + dst = None # Name of lag or interface that is is up + # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' + if mg_facts['minigraph_portchannel_interfaces']: + # Get lag facts from the DUT to check which ag is up + new_lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] + src = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='src') + used_intfs.add(src) + if src: + # We found a src lag, let see if we can find a dst lag + dst = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='dst') + used_intfs.add(dst) + + if src is None or dst is None: + # We didn't find 2 lags, lets check up interfaces + port_status = duthost.show_interface(command='status')['ansible_facts'] + if src is None: + src = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='src') + used_intfs.add(src) + if dst is None: + dst = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='dst') + + if src is None or dst is None: + pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname) + logger.info("gathered_new_facts={}".format(json.dumps(facts, indent=2))) yield facts diff --git a/tests/ipfwd/test_mtu.py b/tests/ipfwd/test_mtu.py index acab5d6350e..7fde5380ab0 100644 --- a/tests/ipfwd/test_mtu.py +++ b/tests/ipfwd/test_mtu.py @@ -5,6 +5,9 @@ from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] from tests.ptf_runner import ptf_runner from datetime import datetime +from ipaddress import ip_address +import json +logger = logging.getLogger(__name__) pytestmark = [ pytest.mark.topology('t1', 't2') @@ -14,70 +17,51 @@ In case of multi-dut we need src_host_ip, src_router_ip, dst_host_ip, src_ptf_port_list, dst_ptf_port_list for the dut under test, to take care of that made changes in the testcase ''' - -def lag_facts(dut, mg_facts): - facts = {} - +def get_lag_facts(dut, lag_facts, mg_facts, ignore_lags, test_facts, key='src'): if not mg_facts['minigraph_portchannels']: pytest.fail("minigraph_portchannels is not defined") # minigraph facts - src_lag = mg_facts['minigraph_portchannel_interfaces'][0]['attachto'] - dst_lag = mg_facts['minigraph_portchannel_interfaces'][2]['attachto'] - logger.info("src_lag is {}, dst_lag is {}".format(src_lag, dst_lag)) - - for intf in mg_facts['minigraph_portchannel_interfaces']: - if intf['attachto'] == dst_lag: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['dst_router_ip'] = intf['addr'] - facts['dst_host_ip'] = intf['peer_addr'] - if intf['attachto'] == src_lag: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['src_router_ip'] = intf['addr'] - facts['src_host_ip'] = intf['peer_addr'] - - facts['dst_port_ids'] = [] - for intf in mg_facts['minigraph_portchannels'][dst_lag]['members']: - facts['dst_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) - - facts['src_port_ids'] = [] - for intf in mg_facts['minigraph_portchannels'][src_lag]['members']: - facts['src_port_ids'].append(mg_facts['minigraph_ptf_indices'][intf]) - - return facts - - -def port_facts(dut, mg_facts): - facts = {} - + up_lag = None + for a_lag_name, a_lag_data in lag_facts['lags'].items(): + if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: + # We found a portchannel that is up. + up_lag = a_lag_name + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] + for intf in mg_facts['minigraph_portchannel_interfaces']: + if intf['attachto'] == up_lag: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ip'] = intf['addr'] + test_facts[key + '_host_ip'] = intf['peer_addr'] + break + logger.info("{} lag is {}".format(key, up_lag)) + break + + return up_lag + + +def get_port_facts(dut, mg_facts, port_status, ignore_intfs, test_facts, key='src'): if not mg_facts['minigraph_interfaces']: pytest.fail("minigraph_interfaces is not defined.") - # minigraph facts - src_port = mg_facts['minigraph_interfaces'][0]['attachto'] - dst_port = mg_facts['minigraph_interfaces'][2]['attachto'] - logger.info("src_port is {}, dst_port is {}".format(src_port, dst_port)) - - - for intf in mg_facts['minigraph_interfaces']: - if intf['attachto'] == dst_port: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['dst_router_ip'] = intf['addr'] - facts['dst_host_ip'] = intf['peer_addr'] - if intf['attachto'] == src_port: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - facts['src_router_ip'] = intf['addr'] - facts['src_host_ip'] = intf['peer_addr'] - - facts['dst_port_ids'] = [mg_facts['minigraph_ptf_indices'][dst_port]] - facts['src_port_ids'] = [mg_facts['minigraph_ptf_indices'][src_port]] - - return facts - + up_port = None + for a_intf_name, a_intf_data in port_status['int_status'].items(): + if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: + # Got a port that is up and not already used. + for intf in mg_facts['minigraph_interfaces']: + if intf['attachto'] == a_intf_name: + up_port = a_intf_name + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ip'] = intf['addr'] + test_facts[key + '_host_ip'] = intf['peer_addr'] + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] + break + if up_port: + logger.info("{} port is {}".format(key, up_port)) + break + return up_port @pytest.fixture(scope='function') def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): @@ -91,11 +75,33 @@ def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): logger.info("Gathering facts on DUT ...") mg_facts = duthost.get_extended_minigraph_facts(tbinfo) - # if minigraph_portchannel_interfaces is not empty - topology with lag + facts = {} + used_intfs = set() + src = None # Name of lag or interface that is is up + dst = None # Name of lag or interface that is is up + + # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' if mg_facts['minigraph_portchannel_interfaces']: - facts = lag_facts(duthost, mg_facts) - else: - facts = port_facts(duthost, mg_facts) + # Get lag facts from the DUT to check which ag is up + lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] + src = get_lag_facts(duthost, lag_facts, mg_facts, used_intfs, facts, key='src') + used_intfs.add(src) + if src: + # We found a src lag, let see if we can find a dst lag + dst = get_lag_facts(duthost, lag_facts, mg_facts, used_intfs, facts, key='dst') + used_intfs.add(dst) + + if src is None or dst is None: + # We didn't find 2 lags, lets check up interfaces + port_status = duthost.show_interface(command='status')['ansible_facts'] + if src is None: + src = get_port_facts(duthost, mg_facts, port_status, used_intfs, facts, key='src') + used_intfs.add(src) + if dst is None: + dst = get_port_facts(duthost, mg_facts, port_status, used_intfs, facts, key='dst') + + if src is None or dst is None: + pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname) logger.info("gathered_facts={}".format(json.dumps(facts, indent=2))) From 2975555865d727b43041b36343c8d61583490899 Mon Sep 17 00:00:00 2001 From: falodiya Date: Mon, 8 Feb 2021 14:31:36 -0500 Subject: [PATCH 3/5] Created conftest.py as per the comment. --- tests/ipfwd/conftest.py | 109 ++++++++++++++++++++++++++++++++++ tests/ipfwd/test_dip_sip.py | 113 +++--------------------------------- tests/ipfwd/test_mtu.py | 105 ++------------------------------- 3 files changed, 122 insertions(+), 205 deletions(-) create mode 100644 tests/ipfwd/conftest.py diff --git a/tests/ipfwd/conftest.py b/tests/ipfwd/conftest.py new file mode 100644 index 00000000000..be234555670 --- /dev/null +++ b/tests/ipfwd/conftest.py @@ -0,0 +1,109 @@ +import pytest +import ptf.testutils as testutils +from ipaddress import ip_address +import logging +import json + + +logger = logging.getLogger(__name__) + + +''' +In case of multi-dut we need src_host_ip, src_router_ip, dst_host_ip, src_ptf_port_list, dst_ptf_port_list for the dut under test, +to take care of that made changes in the testcase +''' + +def get_lag_facts(dut, lag_facts, switch_arptable, mg_facts, ignore_lags, test_facts, key='src'): + if not mg_facts['minigraph_portchannels']: + pytest.fail("minigraph_portchannels is not defined") + + # minigraph facts + up_lag = None + for a_lag_name, a_lag_data in lag_facts['lags'].items(): + if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: + # We found a portchannel that is up. + up_lag = a_lag_name + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] + test_facts[key + '_router_mac'] = dut.facts['router_mac'] + for intf in mg_facts['minigraph_portchannel_interfaces']: + if intf['attachto'] == up_lag: + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ipv4'] = intf['addr'] + test_facts[key + '_host_ipv4'] = intf['peer_addr'] + test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + elif addr.version == 6: + test_facts[key + '_router_ipv6'] = intf['addr'] + test_facts[key + '_host_ipv6'] = intf['peer_addr'] + logger.info("{} lag is {}".format(key, up_lag)) + break + + return up_lag + + +def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, test_facts, key='src'): + if not mg_facts['minigraph_interfaces']: + pytest.fail("minigraph_interfaces is not defined.") + + up_port = None + for a_intf_name, a_intf_data in port_status['int_status'].items(): + if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: + # Got a port that is up and not already used. + for intf in mg_facts['minigraph_interfaces']: + if intf['attachto'] == a_intf_name: + up_port = a_intf_name + test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] + test_facts[key + '_router_mac'] = dut.facts['router_mac'] + addr = ip_address(unicode(intf['addr'])) + if addr.version == 4: + test_facts[key + '_router_ipv4'] = intf['addr'] + test_facts[key + '_host_ipv4'] = intf['peer_addr'] + test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + elif addr.version == 6: + test_facts[key + '_router_ipv6'] = intf['addr'] + test_facts[key + '_host_ipv6'] = intf['peer_addr'] + if up_port: + logger.info("{} port is {}".format(key, up_port)) + break + return up_port + +@pytest.fixture(scope='function') +def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] + facts = {} + + logger.info("Gathering facts on DUT ...") + mg_facts = duthost.get_extended_minigraph_facts(tbinfo) + + # Use the arp table to get the mac address of the host (VM's) instead of lldp_facts as that is was is used + # by the DUT to forward traffic - regardless of lag or port. + switch_arptable = duthost.switch_arptable()['ansible_facts'] + used_intfs = set() + src = None # Name of lag or interface that is is up + dst = None # Name of lag or interface that is is up + + # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' + if mg_facts['minigraph_portchannel_interfaces']: + # Get lag facts from the DUT to check which ag is up + new_lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] + src = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='src') + used_intfs.add(src) + if src: + # We found a src lag, let see if we can find a dst lag + dst = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='dst') + used_intfs.add(dst) + + if src is None or dst is None: + # We didn't find 2 lags, lets check up interfaces + port_status = duthost.show_interface(command='status')['ansible_facts'] + if src is None: + src = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='src') + used_intfs.add(src) + if dst is None: + dst = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='dst') + + if src is None or dst is None: + pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname) + logger.info("gathered_new_facts={}".format(json.dumps(facts, indent=2))) + + yield facts diff --git a/tests/ipfwd/test_dip_sip.py b/tests/ipfwd/test_dip_sip.py index baafb430235..6c243db783b 100644 --- a/tests/ipfwd/test_dip_sip.py +++ b/tests/ipfwd/test_dip_sip.py @@ -1,8 +1,6 @@ import pytest import ptf.testutils as testutils -from ipaddress import ip_address import logging -import json from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import remove_ip_addresses # lgtm[py/unused-import] @@ -10,13 +8,12 @@ DEFAULT_HLIM_TTL = 64 WAIT_EXPECTED_PACKET_TIMEOUT = 5 +logger = logging.getLogger(__name__) + pytestmark = [ pytest.mark.topology('t0', 't1', 't2') ] -logger = logging.getLogger(__name__) - - @pytest.fixture(scope="module", autouse="True") def lldp_setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, patch_lldpctl, unpatch_lldpctl, localhost): duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] @@ -24,106 +21,6 @@ def lldp_setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, patch_lldpct yield unpatch_lldpctl(localhost, duthost) -def get_lag_facts(dut, lag_facts, switch_arptable, mg_facts, ignore_lags, test_facts, key='src'): - if not mg_facts['minigraph_portchannels']: - pytest.fail("minigraph_portchannels is not defined") - - # minigraph facts - up_lag = None - for a_lag_name, a_lag_data in lag_facts['lags'].items(): - if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: - # We found a portchannel that is up. - up_lag = a_lag_name - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] - test_facts[key + '_router_mac'] = dut.facts['router_mac'] - for intf in mg_facts['minigraph_portchannel_interfaces']: - if intf['attachto'] == up_lag: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - test_facts[key + '_router_ipv4'] = intf['addr'] - test_facts[key + '_host_ipv4'] = intf['peer_addr'] - test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] - elif addr.version == 6: - test_facts[key + '_router_ipv6'] = intf['addr'] - test_facts[key + '_host_ipv6'] = intf['peer_addr'] - logger.info("{} lag is {}".format(key, up_lag)) - break - - return up_lag - - -def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, test_facts, key='src'): - if not mg_facts['minigraph_interfaces']: - pytest.fail("minigraph_interfaces is not defined.") - - up_port = None - for a_intf_name, a_intf_data in port_status['int_status'].items(): - if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: - # Got a port that is up and not already used. - for intf in mg_facts['minigraph_interfaces']: - if intf['attachto'] == a_intf_name: - up_port = a_intf_name - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] - test_facts[key + '_router_mac'] = dut.facts['router_mac'] - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - test_facts[key + '_router_ipv4'] = intf['addr'] - test_facts[key + '_host_ipv4'] = intf['peer_addr'] - test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] - elif addr.version == 6: - test_facts[key + '_router_ipv6'] = intf['addr'] - test_facts[key + '_host_ipv6'] = intf['peer_addr'] - if up_port: - logger.info("{} port is {}".format(key, up_port)) - break - return up_port - - -@pytest.fixture(scope='function') -def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): - duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - facts = {} - - topo_type = tbinfo['topo']['type'] - if topo_type not in ('t0', 't1', 't2'): - pytest.skip("Unsupported topology") - - logger.info("Gathering facts on DUT ...") - mg_facts = duthost.get_extended_minigraph_facts(tbinfo) - - # Use the arp table to get the mac address of the host (VM's) instead of lldp_facts as that is was is used - # by the DUT to forward traffic - regardless of lag or port. - switch_arptable = duthost.switch_arptable()['ansible_facts'] - used_intfs = set() - src = None # Name of lag or interface that is is up - dst = None # Name of lag or interface that is is up - - # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' - if mg_facts['minigraph_portchannel_interfaces']: - # Get lag facts from the DUT to check which ag is up - new_lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] - src = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='src') - used_intfs.add(src) - if src: - # We found a src lag, let see if we can find a dst lag - dst = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='dst') - used_intfs.add(dst) - - if src is None or dst is None: - # We didn't find 2 lags, lets check up interfaces - port_status = duthost.show_interface(command='status')['ansible_facts'] - if src is None: - src = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='src') - used_intfs.add(src) - if dst is None: - dst = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='dst') - - if src is None or dst is None: - pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname) - logger.info("gathered_new_facts={}".format(json.dumps(facts, indent=2))) - yield facts - - def run_test_ipv6(ptfadapter, facts): logger.info("Running test with ipv6 packets") @@ -184,7 +81,11 @@ def run_test_ipv4(ptfadapter, facts): testutils.verify_packet_any_port(ptfadapter, exp_pkt, facts['dst_port_ids'], timeout=WAIT_EXPECTED_PACKET_TIMEOUT) -def test_dip_sip(ptfadapter, gather_facts): +def test_dip_sip(tbinfo, ptfadapter, gather_facts): + topo_type = tbinfo['topo']['type'] + if topo_type not in ('t0', 't1', 't2'): + pytest.skip("Unsupported topology") + ptfadapter.reinit() run_test_ipv4(ptfadapter, gather_facts) run_test_ipv6(ptfadapter, gather_facts) diff --git a/tests/ipfwd/test_mtu.py b/tests/ipfwd/test_mtu.py index 7fde5380ab0..487b0746d87 100644 --- a/tests/ipfwd/test_mtu.py +++ b/tests/ipfwd/test_mtu.py @@ -5,112 +5,19 @@ from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] from tests.ptf_runner import ptf_runner from datetime import datetime -from ipaddress import ip_address -import json -logger = logging.getLogger(__name__) pytestmark = [ pytest.mark.topology('t1', 't2') ] -''' -In case of multi-dut we need src_host_ip, src_router_ip, dst_host_ip, src_ptf_port_list, dst_ptf_port_list for the dut under test, -to take care of that made changes in the testcase -''' -def get_lag_facts(dut, lag_facts, mg_facts, ignore_lags, test_facts, key='src'): - if not mg_facts['minigraph_portchannels']: - pytest.fail("minigraph_portchannels is not defined") - - # minigraph facts - up_lag = None - for a_lag_name, a_lag_data in lag_facts['lags'].items(): - if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: - # We found a portchannel that is up. - up_lag = a_lag_name - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] - for intf in mg_facts['minigraph_portchannel_interfaces']: - if intf['attachto'] == up_lag: - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - test_facts[key + '_router_ip'] = intf['addr'] - test_facts[key + '_host_ip'] = intf['peer_addr'] - break - logger.info("{} lag is {}".format(key, up_lag)) - break - - return up_lag - - -def get_port_facts(dut, mg_facts, port_status, ignore_intfs, test_facts, key='src'): - if not mg_facts['minigraph_interfaces']: - pytest.fail("minigraph_interfaces is not defined.") - - up_port = None - for a_intf_name, a_intf_data in port_status['int_status'].items(): - if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: - # Got a port that is up and not already used. - for intf in mg_facts['minigraph_interfaces']: - if intf['attachto'] == a_intf_name: - up_port = a_intf_name - addr = ip_address(unicode(intf['addr'])) - if addr.version == 4: - test_facts[key + '_router_ip'] = intf['addr'] - test_facts[key + '_host_ip'] = intf['peer_addr'] - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] - break - if up_port: - logger.info("{} port is {}".format(key, up_port)) - break - return up_port - -@pytest.fixture(scope='function') -def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): +@pytest.mark.parametrize("mtu", [1514,9114]) +def test_mtu(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, mtu, gather_facts): duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - facts = {} topo_type = tbinfo['topo']['type'] - if topo_type not in ('t0', 't1', 't2'): + if topo_type not in ('t1', 't2'): pytest.skip("Unsupported topology") - logger.info("Gathering facts on DUT ...") - mg_facts = duthost.get_extended_minigraph_facts(tbinfo) - - facts = {} - used_intfs = set() - src = None # Name of lag or interface that is is up - dst = None # Name of lag or interface that is is up - - # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' - if mg_facts['minigraph_portchannel_interfaces']: - # Get lag facts from the DUT to check which ag is up - lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] - src = get_lag_facts(duthost, lag_facts, mg_facts, used_intfs, facts, key='src') - used_intfs.add(src) - if src: - # We found a src lag, let see if we can find a dst lag - dst = get_lag_facts(duthost, lag_facts, mg_facts, used_intfs, facts, key='dst') - used_intfs.add(dst) - - if src is None or dst is None: - # We didn't find 2 lags, lets check up interfaces - port_status = duthost.show_interface(command='status')['ansible_facts'] - if src is None: - src = get_port_facts(duthost, mg_facts, port_status, used_intfs, facts, key='src') - used_intfs.add(src) - if dst is None: - dst = get_port_facts(duthost, mg_facts, port_status, used_intfs, facts, key='dst') - - if src is None or dst is None: - pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname) - - logger.info("gathered_facts={}".format(json.dumps(facts, indent=2))) - - yield facts - -@pytest.mark.parametrize("mtu", [1514,9114]) -def test_mtu(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhost, mtu, gather_facts): - duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - testbed_type = tbinfo['topo']['name'] router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") @@ -125,9 +32,9 @@ def test_mtu(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname, ptfhos params={"testbed_type": testbed_type, "router_mac": router_mac, "testbed_mtu": mtu, - "src_host_ip": gather_facts['src_host_ip'], - "src_router_ip": gather_facts['src_router_ip'], - "dst_host_ip": gather_facts['dst_host_ip'], + "src_host_ip": gather_facts['src_host_ipv4'], + "src_router_ip": gather_facts['src_router_ipv4'], + "dst_host_ip": gather_facts['dst_host_ipv4'], "src_ptf_port_list": gather_facts['src_port_ids'], "dst_ptf_port_list": gather_facts['dst_port_ids'] }, From e4cdd1a37b41776d540c2f6e4843ca02d41b6d94 Mon Sep 17 00:00:00 2001 From: falodiya Date: Mon, 8 Feb 2021 17:33:32 -0500 Subject: [PATCH 4/5] removed unused import --- tests/ipfwd/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ipfwd/conftest.py b/tests/ipfwd/conftest.py index be234555670..c3487a0f45d 100644 --- a/tests/ipfwd/conftest.py +++ b/tests/ipfwd/conftest.py @@ -1,5 +1,4 @@ import pytest -import ptf.testutils as testutils from ipaddress import ip_address import logging import json From 58f1a4ad5eaebd6e70e2c18ddf7344d2a4e0ef81 Mon Sep 17 00:00:00 2001 From: falodiya Date: Tue, 2 Mar 2021 18:37:58 -0500 Subject: [PATCH 5/5] Made get_lag_facts and get_port_facts in conftest return selected port and dictionary of facts Changes made as per the review comment --- tests/ipfwd/conftest.py | 54 +++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/ipfwd/conftest.py b/tests/ipfwd/conftest.py index c3487a0f45d..6c60afa82dc 100644 --- a/tests/ipfwd/conftest.py +++ b/tests/ipfwd/conftest.py @@ -12,38 +12,39 @@ to take care of that made changes in the testcase ''' -def get_lag_facts(dut, lag_facts, switch_arptable, mg_facts, ignore_lags, test_facts, key='src'): +def get_lag_facts(dut, lag_facts, switch_arptable, mg_facts, ignore_lags, key='src'): if not mg_facts['minigraph_portchannels']: pytest.fail("minigraph_portchannels is not defined") # minigraph facts + selected_lag_facts = {} up_lag = None for a_lag_name, a_lag_data in lag_facts['lags'].items(): if a_lag_data['po_intf_stat'] == 'Up' and a_lag_name not in ignore_lags: # We found a portchannel that is up. up_lag = a_lag_name - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] - test_facts[key + '_router_mac'] = dut.facts['router_mac'] + selected_lag_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][intf] for intf in a_lag_data['po_config']['ports']] + selected_lag_facts[key + '_router_mac'] = dut.facts['router_mac'] for intf in mg_facts['minigraph_portchannel_interfaces']: if intf['attachto'] == up_lag: addr = ip_address(unicode(intf['addr'])) if addr.version == 4: - test_facts[key + '_router_ipv4'] = intf['addr'] - test_facts[key + '_host_ipv4'] = intf['peer_addr'] - test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + selected_lag_facts[key + '_router_ipv4'] = intf['addr'] + selected_lag_facts[key + '_host_ipv4'] = intf['peer_addr'] + selected_lag_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] elif addr.version == 6: - test_facts[key + '_router_ipv6'] = intf['addr'] - test_facts[key + '_host_ipv6'] = intf['peer_addr'] + selected_lag_facts[key + '_router_ipv6'] = intf['addr'] + selected_lag_facts[key + '_host_ipv6'] = intf['peer_addr'] logger.info("{} lag is {}".format(key, up_lag)) break - return up_lag + return up_lag, selected_lag_facts -def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, test_facts, key='src'): +def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, key='src'): if not mg_facts['minigraph_interfaces']: pytest.fail("minigraph_interfaces is not defined.") - + selected_port_facts = {} up_port = None for a_intf_name, a_intf_data in port_status['int_status'].items(): if a_intf_data['oper_state'] == 'up' and a_intf_name not in ignore_intfs: @@ -51,20 +52,20 @@ def get_port_facts(dut, mg_facts, port_status, switch_arptable, ignore_intfs, te for intf in mg_facts['minigraph_interfaces']: if intf['attachto'] == a_intf_name: up_port = a_intf_name - test_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] - test_facts[key + '_router_mac'] = dut.facts['router_mac'] + selected_port_facts[key + '_port_ids'] = [mg_facts['minigraph_ptf_indices'][a_intf_name]] + selected_port_facts[key + '_router_mac'] = dut.facts['router_mac'] addr = ip_address(unicode(intf['addr'])) if addr.version == 4: - test_facts[key + '_router_ipv4'] = intf['addr'] - test_facts[key + '_host_ipv4'] = intf['peer_addr'] - test_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] + selected_port_facts[key + '_router_ipv4'] = intf['addr'] + selected_port_facts[key + '_host_ipv4'] = intf['peer_addr'] + selected_port_facts[key + '_host_mac'] = switch_arptable['arptable']['v4'][intf['peer_addr']]['macaddress'] elif addr.version == 6: - test_facts[key + '_router_ipv6'] = intf['addr'] - test_facts[key + '_host_ipv6'] = intf['peer_addr'] + selected_port_facts[key + '_router_ipv6'] = intf['addr'] + selected_port_facts[key + '_host_ipv6'] = intf['peer_addr'] if up_port: logger.info("{} port is {}".format(key, up_port)) break - return up_port + return up_port, selected_port_facts @pytest.fixture(scope='function') def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): @@ -84,22 +85,27 @@ def gather_facts(tbinfo, duthosts, enum_rand_one_per_hwsku_frontend_hostname): # if minigraph_portchannel_interfaces is not empty - topology with lag - check if we have 2 lags that are 'Up' if mg_facts['minigraph_portchannel_interfaces']: # Get lag facts from the DUT to check which ag is up - new_lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] - src = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='src') + lag_facts = duthost.lag_facts(host=duthost.hostname)['ansible_facts']['lag_facts'] + src, src_lag_facts = get_lag_facts(duthost, lag_facts, switch_arptable, mg_facts, used_intfs, key='src') used_intfs.add(src) if src: + facts.update(src_lag_facts) # We found a src lag, let see if we can find a dst lag - dst = get_lag_facts(duthost, new_lag_facts, switch_arptable, mg_facts, used_intfs, facts, key='dst') + dst, dst_lag_facts = get_lag_facts(duthost, lag_facts, switch_arptable, mg_facts, used_intfs, key='dst') used_intfs.add(dst) + facts.update(dst_lag_facts) if src is None or dst is None: # We didn't find 2 lags, lets check up interfaces port_status = duthost.show_interface(command='status')['ansible_facts'] if src is None: - src = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='src') + src, src_port_facts = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, key='src') used_intfs.add(src) + facts.update(src_port_facts) + if dst is None: - dst = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, facts, key='dst') + dst, dst_port_facts = get_port_facts(duthost, mg_facts, port_status, switch_arptable, used_intfs, key='dst') + facts.update(dst_port_facts) if src is None or dst is None: pytest.fail("Did not find 2 lag or interfaces that are up on host {}".duthost.hostname)