Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,24 @@ def get_namespace_from_asic_id(self, asic_id):
return DEFAULT_NAMESPACE
return "{}{}".format(NAMESPACE_PREFIX, asic_id)

def get_minigraph_facts(self, tbinfo):
mg_facts = self.minigraph_facts(host = self.hostname)['ansible_facts']

# Fix the ptf port index for multi-dut testbeds. These testbeds have
# multiple DUTs sharing a same PTF host. Therefore, the indeces from
# the minigraph facts are not always match up with PTF port indeces.
try:
dut_index = tbinfo['duts'].index(self.hostname)
map = tbinfo['topo']['ptf_map'][dut_index]
if map:
for port, index in mg_facts['minigraph_port_indices'].items():
if index in map:
mg_facts['minigraph_port_indices'][port] = map[index]
except ValueError:
pass

return mg_facts


class EosHost(AnsibleHostBase):
"""
Expand Down
59 changes: 59 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(self, testbed_file):
line['topo']['type'] = self.get_testbed_type(line['topo']['name'])
with open("../ansible/vars/topo_{}.yml".format(topo), 'r') as fh:
line['topo']['properties'] = yaml.safe_load(fh)
line['topo']['ptf_map'] = self.calculate_ptf_index_map(line)

self.testbed_topo[line['conf-name']] = line

Expand All @@ -101,6 +102,64 @@ def get_testbed_type(self, topo_name):
tb_type = 't0'
return tb_type

def _parse_dut_port_index(self, port):
"""
parse port string

port format : dut_index.port_index@ptf_index

"""
m = re.match("(\d+)\.(\d+)@(\d+)", port)
(dut_index, port_index, ptf_index) = (int(m.group(1)), int(m.group(2)), int(m.group(3)))

return (dut_index, port_index, ptf_index)

def calculate_ptf_index_map(self, line):
map = defaultdict()
if len(line['duts']) <= 1:
# No need to calculate map for single DUT testbed
return map

# For multi-DUT testbed, because multiple DUTs are sharing a same
# PTF docker, the ptf docker interface index will not be exactly
# match the interface index on DUT. The information is available
# in the topology facts. Get these information out and put them
# in the 2 levels dictionary as:
# { dut_index : { dut_port_index : ptf_index * } * }

topo_facts = line['topo']['properties']
if 'topology' not in topo_facts:
return map

topology = topo_facts['topology']
if 'host_interfaces' in topology:
for ports in topology['host_interfaces']:
# Example: ['0.0,1.0', '0.1,1.1', '0.2,1.2', ... ]
# if there is no '@' then they are shared, no need to update.
for port in ports.split(','):
if '@' in port and '.' in port:
dut_index, port_index, ptf_index = _parse_dut_port_index(port)
if port_index != ptf_index:
# Need to add this in map
dut_dict = map[dut_index] if dut_index in map else {}
dut_dict[port_index] = ptf_index
map[dut_index] = dut_dict

if 'VMs' in topology:
for _, vm in topology['VMs'].items():
if 'vlans' in vm:
for port in vm['vlans']:
# Example: ['0.31@34', '1.31@35']
if '@' in port and '.' in port:
dut_index, port_index, ptf_index = self._parse_dut_port_index(port)
if port_index != ptf_index:
# Need to add this in map
dut_dict = map[dut_index] if dut_index in map else {}
dut_dict[port_index] = ptf_index
map[dut_index] = dut_dict

return map

def pytest_addoption(parser):
parser.addoption("--testbed", action="store", default=None, help="testbed name")
parser.addoption("--testbed_file", action="store", default=None, help="testbed file name")
Expand Down
18 changes: 6 additions & 12 deletions tests/pc/test_lag_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]

@pytest.fixture(scope="module")
def common_setup_teardown(duthost, ptfhost, tbinfo):
def common_setup_teardown(ptfhost):
logger.info("########### Setup for lag testing ###########")

# Copy PTF test into PTF-docker for test LACP DU
Expand All @@ -31,22 +31,16 @@ def common_setup_teardown(duthost, ptfhost, tbinfo):
dst = "/tmp/%s" % test_file
ptfhost.copy(src=src, dest=dst)

# Inlucde testbed topology configuration
topo_name = tbinfo['topo']['name']
topo_type = tbinfo['topo']['type']

support_testbed_types = frozenset(['t1-lag', 't0', 't0-116', 'dualtor'])
pytest_require(topo_name in support_testbed_types, "Not support given test bed type {} topology {}".format(topo_type, topo_name))

yield ptfhost

class LagTest:
def __init__(self, duthost, ptfhost, nbrhosts, fanouthosts, conn_graph_facts):
def __init__(self, duthost, tbinfo, ptfhost, nbrhosts, fanouthosts, conn_graph_facts):
self.duthost = duthost
self.tbinfo = tbinfo
self.ptfhost = ptfhost
self.nbrhosts = nbrhosts
self.fanouthosts = fanouthosts
self.mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts']
self.mg_facts = duthost.get_minigraph_facts(tbinfo)
self.conn_graph_facts = conn_graph_facts
self.vm_neighbors = self.mg_facts['minigraph_neighbors']
self.fanout_neighbors = self.conn_graph_facts['device_conn'][duthost.hostname] if 'device_conn' in self.conn_graph_facts else {}
Expand Down Expand Up @@ -242,7 +236,7 @@ def run_lag_fallback_test(self, lag_name):
@pytest.mark.parametrize("testcase", ["single_lag",
"lacp_rate",
"fallback"])
def test_lag(common_setup_teardown, duthosts, nbrhosts, fanouthosts, conn_graph_facts, all_pcs, testcase):
def test_lag(common_setup_teardown, duthosts, tbinfo, nbrhosts, fanouthosts, conn_graph_facts, all_pcs, testcase):
ptfhost = common_setup_teardown

dut_name, dut_lag = decode_dut_port_name(all_pcs)
Expand All @@ -252,7 +246,7 @@ def test_lag(common_setup_teardown, duthosts, nbrhosts, fanouthosts, conn_graph_
if dut_name in [ 'unknown', duthost.hostname ]:
lag_facts = duthost.lag_facts(host = duthost.hostname)['ansible_facts']['lag_facts']

test_instance = LagTest(duthost, ptfhost, nbrhosts, fanouthosts, conn_graph_facts)
test_instance = LagTest(duthost, tbinfo, ptfhost, nbrhosts, fanouthosts, conn_graph_facts)

# Test for each lag
if dut_lag == "unknown":
Expand Down