diff --git a/tests/bgp/test_bgp_fact.py b/tests/bgp/test_bgp_fact.py index d8bb544e81f..4cd7c9cf5ec 100644 --- a/tests/bgp/test_bgp_fact.py +++ b/tests/bgp/test_bgp_fact.py @@ -5,10 +5,10 @@ pytest.mark.device_type('vs') ] -def test_bgp_facts(duthosts, dut_index, asic_index): +def test_bgp_facts(duthosts, dut_hostname, asic_index): """compare the bgp facts between observed states and target state""" - duthost = duthosts[dut_index] + duthost = duthosts[dut_hostname] bgp_facts =duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] namespace = duthost.get_namespace_from_asic_id(asic_index) config_facts = duthost.config_facts(host=duthost.hostname, source="running",namespace=namespace)['ansible_facts'] @@ -16,12 +16,11 @@ def test_bgp_facts(duthosts, dut_index, asic_index): for k, v in bgp_facts['bgp_neighbors'].items(): # Verify bgp sessions are established assert v['state'] == 'established' - # Verify locat ASNs in bgp sessions + # Verify local ASNs in bgp sessions assert v['local AS'] == int(config_facts['DEVICE_METADATA']['localhost']['bgp_asn'].decode("utf-8")) for k, v in config_facts['BGP_NEIGHBOR'].items(): - # Compare the bgp neighbors name with config db bgp neigbhors name + # Compare the bgp neighbors name with config db bgp neighbors name assert v['name'] == bgp_facts['bgp_neighbors'][k]['description'] # Compare the bgp neighbors ASN with config db assert int(v['asn'].decode("utf-8")) == bgp_facts['bgp_neighbors'][k]['remote AS'] - diff --git a/tests/conftest.py b/tests/conftest.py index 29acb8da37d..a24a60012f0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -456,13 +456,12 @@ def get_host_data(request, dut): def generate_param_asic_index(request, dut_indices, param_type): logging.info("generating {} asic indicies for DUT [{}] in ".format(param_type, dut_indices)) - + tbname = request.config.getoption("--testbed") tbfile = request.config.getoption("--testbed_file") if tbname is None or tbfile is None: raise ValueError("testbed and testbed_file are required!") - - + tbinfo = TestbedInfo(tbfile) #if the params are not present treat the device as a single asic device @@ -491,6 +490,17 @@ def generate_params_dut_index(request): return range(num_duts) +def generate_params_dut_hostname(request): + tbname = request.config.getoption("--testbed") + tbfile = request.config.getoption("--testbed_file") + if tbname is None or tbfile is None: + raise ValueError("testbed and testbed_file are required!") + tbinfo = TestbedInfo(tbfile) + duts = tbinfo.testbed_topo[tbname]["duts"] + logging.info("DUTs in testbed topology: {}".format(str(duts))) + return duts + + def generate_port_lists(request, port_scope): empty = [ encode_dut_port_name('unknown', 'unknown') ] if 'ports' in port_scope: @@ -543,6 +553,9 @@ def pytest_generate_tests(metafunc): if "dut_index" in metafunc.fixturenames: dut_indices = generate_params_dut_index(metafunc) metafunc.parametrize("dut_index",dut_indices) + elif "dut_hostname" in metafunc.fixturenames: # Fixture "dut_index" and "dut_hostname" should be mutually exclusive + dut_hostnames = generate_params_dut_hostname(metafunc) + metafunc.parametrize("dut_hostname", dut_hostnames) if "asic_index" in metafunc.fixturenames: metafunc.parametrize("asic_index",generate_param_asic_index(metafunc, dut_indices, ASIC_PARAM_TYPE_ALL)) if "frontend_asic_index" in metafunc.fixturenames: