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

Improve cache and enable caching of TestbedInfo #2856

Merged
merged 4 commits into from
Jan 27, 2021
Merged

Improve cache and enable caching of TestbedInfo #2856

merged 4 commits into from
Jan 27, 2021

Conversation

wangxin
Copy link
Collaborator

@wangxin wangxin commented Jan 25, 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?

The original cache implementation uses json to save cached information to file. For objects that
cannot be serialized to JSON, they cannot be cached. Another limitation is that the cached facts
must be stored under sub-folder specified by hostname. This limited usage of the caching.

How did you do it?

This change improved caching in these ways:

  • Replace JSON with pickle to dump and load cached information. Then all object types supported by pickle can be cached.
  • Use more generic 'zone' to specify sub-folder for cached facts. The zone can be hostname or other string.
  • When 'testbed-cli.sh deploy-mg' is executed, cleanup all the cached information, not just cached information of current DUT.
  • Enable caching of TestbedInfo which is also frequently used and less frequently changed.
  • Enhance the cleanup method to support removing single cached information, cached information of a specified zone, or all cached information. Not just cached file is removed, cached information in memory is also removed.
  • Updated related documents.

How did you verify/test it?

  • Run test scripts that need cache enabled tbinfo and minigraph_facts.
  • Run testbed-cli.sh deploy-mg

Any platform specific information?

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

Documentation

The original cache implementation uses json to save cached information to file. For objects that
cannot be serialized to JSON, they cannot be cached. Another limitation is that the cached facts
must be stored under sub-folder specified by hostname. This limited usage of the caching.

This change improved caching in these ways:
* Replace JSON with pickle to dump and load cached information. Then all object types supported by pickle can be cached.
* Use more generic 'zone' to specify sub-folder for cached facts. The zone can be hostname or other string.
* When 'testbed-cli.sh deploy-mg' is executed, cleanup all the cached information, not just cached information of current DUT.
* Enable caching of TestbedInfo which is also frequently used and less frequently changed.
* Updated related documents.

Signed-off-by: Xin Wang <[email protected]>
@wangxin wangxin requested a review from a team January 25, 2021 05:58
@lgtm-com
Copy link

lgtm-com bot commented Jan 25, 2021

This pull request introduces 1 alert when merging 67f29e2 into 17ec1cc - view on LGTM.com

new alerts:

  • 1 for Unused argument in a formatting call

Copy link
Contributor

@lolyu lolyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangxin
Copy link
Collaborator Author

wangxin commented Jan 26, 2021

retest vsimage please

1 similar comment
@liat-grozovik
Copy link
Collaborator

retest vsimage please

@wangxin wangxin merged commit 0dee240 into sonic-net:master Jan 27, 2021
@wangxin wangxin deleted the refactor-cache 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.

4 participants