-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Multi asic]:parameterize asic_index and dut_index #2245
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
DEFAULT_ASIC_ID = None | ||
DEFAULT_NAMESPACE = None | ||
NAMESPACE_PREFIX = 'asic' | ||
ASIC_PARAM_TYPE_ALL = 'num_asics' | ||
ASIC_PARAM_TYPE_FRONTEND = 'frontend_asics' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
from tests.common.fixtures.conn_graph_facts import conn_graph_facts | ||
from tests.common.devices import SonicHost, Localhost | ||
from tests.common.devices import PTFHost, EosHost, FanoutHost | ||
from tests.common.helpers.constants import ASIC_PARAM_TYPE_ALL, ASIC_PARAM_TYPE_FRONTEND, DEFAULT_ASIC_ID | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -455,3 +456,52 @@ def disable_container_autorestart(duthost, request): | |
for name, state in container_autorestart_states.items(): | ||
if state == "enabled": | ||
duthost.command(cmd_enable.format(name)) | ||
|
||
def generate_param_asic_index(request, dut_indices, param_type): | ||
logging.info("generating {} asic indicies for DUT [{}] in ".format(param_type, dut_indices)) | ||
inv_file = request.config.getoption("ansible_inventory") | ||
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!") | ||
|
||
with open(inv_file, 'r') as fh: | ||
inv = yaml.safe_load(fh) | ||
|
||
hosts = inv['all']['children']['sonic']['hosts'] | ||
tbinfo = TestbedInfo(tbfile) | ||
|
||
#if the params are not present treat the device as a single asic device | ||
asic_index_params = [DEFAULT_ASIC_ID] | ||
|
||
for dut_id in dut_indices: | ||
dut = tbinfo.testbed_topo[tbname]["duts"][dut_id] | ||
inv_data = hosts[dut] | ||
if param_type == ASIC_PARAM_TYPE_ALL and ASIC_PARAM_TYPE_ALL in inv_data: | ||
asic_index_params = range(int(inv_data[ASIC_PARAM_TYPE_ALL])) | ||
if param_type == ASIC_PARAM_TYPE_FRONTEND and ASIC_PARAM_TYPE_ALL in inv_data: | ||
asic_index_params = inv_data[ASIC_PARAM_TYPE_ALL] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be more robust to use ansible.inventory.manager.InventoryManager to load inventory file and get host variables. Example: https://github.com/Azure/sonic-mgmt/blob/master/ansible/library/testbed_vm_info.py#L91 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to use the inventory manager. |
||
logging.info("dut_index {} dut name {} asics params = {}".format( | ||
dut_id, dut, asic_index_params)) | ||
return asic_index_params | ||
|
||
def generate_params_dut_index(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) | ||
num_duts = len(tbinfo.testbed_topo[tbname]["duts"]) | ||
logging.info("Num of duts in testbed topology {}".format(num_duts)) | ||
return range(num_duts) | ||
|
||
def pytest_generate_tests(metafunc): | ||
# The topology always has atleast 1 dut | ||
dut_indices = [0] | ||
if "dut_index" in metafunc.fixturenames: | ||
dut_indices = generate_params_dut_index(metafunc) | ||
metafunc.parametrize("dut_index",dut_indices) | ||
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: | ||
metafunc.parametrize("frontend_asic_index",generate_param_asic_index(metafunc, dut_indices, ASIC_PARAM_TYPE_FRONTEND)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
elif
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in the latest commit