Skip to content

Enable caching of host and group ansible variables#2873

Merged
wangxin merged 1 commit intosonic-net:masterfrom
wangxin:more-cache-pr
Jan 29, 2021
Merged

Enable caching of host and group ansible variables#2873
wangxin merged 1 commit intosonic-net:masterfrom
wangxin:more-cache-pr

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 <xiwang5@microsoft.com>
@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.
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
…AD (sonic-net#15532)

#### Why I did it
Update submodule sonic-utilities to the latest HEAD
```
50296b90 - [202012][dhcp-relay] Fix dhcp6relay counter issue (sonic-net#2866) (sonic-net#2873) (Fri Jun 30 18:08:53 2023 +0800) <Yaqiang Zhu>
160030c4 - [202012][dhcp_relay] Add "Reconfigure", "Information-Request", "Malformed" counter options (sonic-net#2844) (Sun Jun 11 20:35:30 2023 -0700) <kellyyeh>
e6289ced - [vlan][dhcp_relay] Clear dhcpv6 relay counter while deleting vlan (sonic-net#2852) (Fri Jun 2 18:20:21 2023 +0000) <Yaqiang Zhu>
885082ec - correctly parsing complete ipv6 vnet info (sonic-net#2827) (Thu May 25 06:01:40 2023 +0000) <Keith Lu>
```

##### Work item tracking
- Microsoft ADO 22635770
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