-
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
Use cached testbedInfo and host_vars in inventory in dut selection fixtures #2811
Conversation
This pull request introduces 6 alerts when merging 117b34203a2a2d9f4cba0b9b55d769c3f4fba22e into 3c9d9b8 - view on LGTM.com new alerts:
|
retest vsimage please |
53822fd
to
9b46984
Compare
retest vsimage please |
This pull request introduces 2 alerts when merging dd06eb0ead6f9bc2280f2d74781a36bdede2f82c into 86d9894 - view on LGTM.com new alerts:
|
@sanmalho-git After some investigation, I feel that the previously added caching function can be used here to avoid global variables. I have enhanced the caching function and enabled caching of TestbedInfo object in PR #2856. With the change of PR #2856, the performance of pytest_generate_tests is significantly improved and there is no need to introduce global variables into conftest.py. Well, I am not completely correct about the statement of global variables. My fix still introduced a global variable I have plan to enable cache of more information, like host visible variables, then the performance of pytest_generate_tests should can be further improved. I'll submit more PRs to address that. |
@wangxin Agreed. Will wait for your PR to be merged and then will modify the code to use the newly introduced caching for the TestbedInfo. |
@sanmalho-git can you resolve the merge conflict and ping us for another review? |
@yxieca I was waiting for PR# 2873 from Xin to incorporate his changes as well. Once that is merged, will do the rebase and resolve conflicts. |
PR #2873 was merged. This PR should be unblocked now. |
88c9248
to
8e5622b
Compare
retest vsimage please |
This is a fix for issue sonic-net#2790 - pytest_generate_tests in tests/conftest.py takes much more time than before The reason for the issue was that creating the TestbedInfo takes 1-9 seconds, and was part of pytest_generate_tests. Since pytest_generate_tests is called for all the tests/fixtures, this was adding a long time when trying to execute many tests. For some of the other dut selection fixtures we were also getting variables for the duts from the inventory files - which also takes a long time - adding to the execution delay. To fix is to use create the TestbedInfo and getting the variables from the inventory files for all the DUTS only once - by storing it in global variables. If these global variables are not set, then we would set them. Thus, creating TestbedInfo and getting variables only once per pytest run
…hen any of the 'enum_*' fixtures are needed.
…_rand_one_per_hwsku_hostname' fixture. With caching of facts, the tbInfo and vars in inventory for a host are cached. Instead of using global variables '_dut_in_testbeds', _dut_vars, we would call the methods again, but since it is cached, it is not re-creating testbed info or reading the vars from the inventory. Added enum_rand_one_per_hwsku_hostname fixture to pytest_generate_tests. This is needed as there are tests like platform tests (test_show_platform_syseeprom) that need to run on both the supervisor and linecard of a T2 chassis.
…ku where a_host_hwsku could be undefined.
8e5622b
to
6a11c36
Compare
@sanmalho-git Can you update the PR description to match the actual code change? Then we can move forward with merging it. |
Changed the title |
@sanmalho-git Can you also update the content under What is the motivation for this PR? and How did you do it?? We generally use these information as commit message while merging PRs. The commit message needs to be accurate. |
Description of PR
Summary:
Fixes # (issue)
Type of change
Approach
What is the motivation for this PR?
pytest_generate_tests dynamically adds enum_* fixtures that select DUTs on which the tests are to be parameterized. In order to select the DUTs on which the tests are to run, we need to get the TestbedInfo and also all variables defined in the inventory file for each DUT. These operations are time consuming - like creating TestbedInfo taking 1-9 seconds, and getting variables from inventory taking 3-5 seconds.
pytest_generate_tests is called for all the tests/fixtures that needs to run in a pytest session. This was adding a long time when trying to execute many tests.
This issue was reported in issue #2790 - pytest_generate_tests in tests/conftest.py takes much more time than before
How did you do it?
To fix this, we need to create the TestbedInfo only once, store it, and then use the stored value in the next execution of pytest_generate_tests, rather than re-creating TestbedInfo. Similary, the variables for all the DUTs in the testbed should be read once from the inventory files, stored, and the re-used in the next execution of pytest_generate_tests.
PR #2789 Added caching capability to store any facts using pickle.
PR #2856 added caching capability for TestbedInfo
PR #2873 added caching capability for variables for DUTs in the inventory files.
We use the cached TestbedInfo and DUT variables in the selection of DUTs in pytest_generate_tests.
How did you verify/test it?
Ran tests that use the dut selection fixtures and validated that the delay is seen only once, and not in every call to pytest_generate_tests.
Validated the execution time reduced significantly when using caching when executing iface_namingmode test cases which have ~30 tests.
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation