Add caching capability for frequently used facts#2789
Add caching capability for frequently used facts#2789wangxin merged 3 commits intosonic-net:masterfrom wangxin:cache-facts
Conversation
To run test scripts, we frequently need to gather facts from various devices again and again. Most of the facts gatherings need to run some commands on remote devices through SSH connection, parse the commands output and return the results. Most of the time, the facts to be gathered are unchanged, like DUT HWSKU, platform, etc. For the less frequently changed facts, we can cache them for quicker access to save a lot of overhead for gathering them each time. Then we can improve the overall time required for running all the tests. This change added caching capability for frequently used facts. For more details, please refer to the documentation included in this change. Signed-off-by: Xin Wang <[email protected]>
tests/common/cache/facts_cache.py
Outdated
| cache = FactsCache() | ||
| def decorator(target): | ||
| def wrapper(*args, **kwargs): | ||
| hostname = args[0].hostname |
There was a problem hiding this comment.
I suggest adding a check for existence for hostname in args[0] in case this wrapper is used at none subclass of AnsibleHostBase. If hostname not exists, just call target directly.
lolyu
left a comment
There was a problem hiding this comment.
Should we limit the cache size(entries count or memory size)?
I think that's a nice to have feature. Currently we are just using it to cache a few dictionaries in json file. It's OK for now. We can enhance it in the future when storage size is becoming a real issue. |
Agreed, for the future multiple DUTs in one testbed, the memory consumption might be a challenge for the test running host. It would be nicer if we could limit how many cache entries we store in memory and store all other caches that exceed a certain threshold only to files. |
Added cache usage check. |
|
retest vsimage please |
|
retest vsimage please |
…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.
…lly (sonic-net#15387) src/sonic-swss * 2aec547 - (HEAD -> 202205, origin/202205) [pfcwd] Enhance DLR_INIT based recovery and DLR_PACKET_ACTION for broadcom platforms (sonic-net#2807) (4 days ago) [Neetha John] * fa4acd3 - Fix to substract the macsec sectag size from port MTU during InitializePort (sonic-net#2789) (5 days ago) [judyjoseph]
Description of PR
Summary:
Fixes # (issue)
Type of change
Approach
What is the motivation for this PR?
To run test scripts, we frequently need to gather facts from various devices again and again. Most of the facts gatherings need to run some commands on remote devices through SSH connection, parse the commands output and return the results. Most of the time, the facts to be gathered are unchanged, like DUT HWSKU, platform, etc. For the less frequently changed facts, we can cache them for quicker access to save a lot of overhead for gathering them each time. Then we can improve the overall time required for running all the tests.
How did you do it?
This change added caching capability for frequently used facts. For more details, please refer to the documentation included in this change.
How did you verify/test it?
Currently caching has been enabled for duthost.facts and duthost.get_extended_minigraph_facts.
testbed-cli.sh deploy-mgto verify that cached json files of current DUT are cleaned.Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation