Skip to content
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

Enable caching of host and group ansible variables #2873

Merged
merged 1 commit into from
Jan 29, 2021
Merged

Enable caching of host and group ansible variables #2873

merged 1 commit into from
Jan 29, 2021

Conversation

wangxin
Copy link
Collaborator

@wangxin wangxin commented Jan 27, 2021

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Approach

What is the motivation for this PR?

Loading variables from inventory files is a kind of expensive operation. Caching them could further improve testing performance.

How did you do it?

This change enabled caching of below items:

  • Ansible InventoryManager instance
  • Ansible VariableManager instance
  • Host visible variables
  • Group visible variables
  • Test server variables
    Another change is to use a lock to guard writing to cache.

How did you verify/test it?

Tested the change using a test script like below:

import logging

from tests.common.utilities import get_inventory_files
from tests.common.utilities import get_host_vars
from tests.common.utilities import get_host_visible_vars
from tests.common.utilities import get_group_visible_vars
from tests.common.utilities import get_test_server_vars

logger = logging.getLogger(__name__)


def test_case1(duthost, request):
    inv_files = get_inventory_files(request)
    vars = get_host_vars(inv_files, duthost.hostname)
    logger.info(str(vars))


def test_case2(duthost, request):
    inv_files = get_inventory_files(request)
    vars = get_host_visible_vars(inv_files, duthost.hostname)
    logger.info(str(vars))


def test_case3(duthost, request):
    inv_files = get_inventory_files(request)
    vars = get_group_visible_vars(inv_files, 'sonic')
    logger.info(str(vars))


def test_case4(duthost, request):
    inv_files = get_inventory_files(request)
    vars = get_test_server_vars(inv_files, 'server_1')
    logger.info(str(vars))


def test_case5(duthost, request, enum_frontend_dut_hostname, enum_asic_index):
    inv_files = get_inventory_files(request)

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@wangxin wangxin requested a review from a team January 27, 2021 04:29
@sanmalho-git
Copy link
Contributor

@wangxin - can you expedite merging this PR as would like to use that in my optimization for pytest_generate_test PR as well.

@wangxin
Copy link
Collaborator Author

wangxin commented Jan 27, 2021

Force pushed to resolve conflicts.

@bingwang-ms
Copy link
Collaborator

retest this, please

Loading variables from inventory files also takes time. Caching them could futher improve testing performance.

This change enabled caching of below items:
* Ansible InventoryManager
* Ansible VariableManager
* Host visible variables
* Group visible variables
* Test server variables

Another change is to use a lock to guard writing to cache.

Signed-off-by: Xin Wang <[email protected]>
@wangxin wangxin merged commit cde66e3 into sonic-net:master Jan 29, 2021
@wangxin wangxin deleted the more-cache-pr branch February 1, 2021 08:23
wangxin pushed a commit that referenced this pull request Feb 6, 2021
…xtures (#2811)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants