Skip to content

Commit

Permalink
Made get_lag_facts and get_port_facts in conftest return selected por…
Browse files Browse the repository at this point in the history
…t and dictionary of facts

Changes made as per the review comment
  • Loading branch information
falodiya committed Mar 2, 2021
1 parent e4cdd1a commit 58f1a4a
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions tests/ipfwd/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,60 @@
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:
# 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']
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):
Expand All @@ -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)
Expand Down

0 comments on commit 58f1a4a

Please sign in to comment.