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

Tests: create new fixtures to make writing booted/restored simpler #4934

Merged
merged 12 commits into from
Dec 5, 2024

Conversation

pb8o
Copy link
Contributor

@pb8o pb8o commented Nov 29, 2024

Changes

This introduces a few new pytest fixtures to deal with CPU template differences, A/B tests, and booted/restored VMs.

In addition there's some cleanups in the affected tests.

Reason

Making those tests simple to write is important so that we don't forget one case. In addition they become easier to write.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@pb8o pb8o added Priority: Low Indicates that an issue or pull request should be resolved behind issues or pull requests labelled ` Status: Awaiting author Indicates that an issue or pull request requires author action python Pull requests that update Python code labels Nov 29, 2024
@pb8o pb8o self-assigned this Nov 29, 2024
Copy link

codecov bot commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.07%. Comparing base (81bae9f) to head (d6f21cd).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4934   +/-   ##
=======================================
  Coverage   84.07%   84.07%           
=======================================
  Files         251      251           
  Lines       28059    28059           
=======================================
  Hits        23592    23592           
  Misses       4467     4467           
Flag Coverage Δ
5.10-c5n.metal 84.65% <ø> (ø)
5.10-m5n.metal 84.63% <ø> (+<0.01%) ⬆️
5.10-m6a.metal 83.93% <ø> (-0.01%) ⬇️
5.10-m6g.metal 80.74% <ø> (ø)
5.10-m6i.metal 84.62% <ø> (ø)
5.10-m7g.metal 80.74% <ø> (ø)
6.1-c5n.metal 84.64% <ø> (-0.01%) ⬇️
6.1-m5n.metal 84.62% <ø> (-0.02%) ⬇️
6.1-m6a.metal 83.93% <ø> (ø)
6.1-m6g.metal 80.74% <ø> (-0.01%) ⬇️
6.1-m6i.metal 84.62% <ø> (-0.01%) ⬇️
6.1-m7g.metal 80.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pb8o pb8o force-pushed the test-refactors branch 10 times, most recently from ef74727 to 0ba22d7 Compare December 2, 2024 12:25
Copy link
Contributor

@zulinx86 zulinx86 left a comment

Choose a reason for hiding this comment

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

I really love this series of refactoring! I only left some minor comments.

tests/framework/microvm.py Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/framework/microvm.py Outdated Show resolved Hide resolved
tests/integration_tests/security/test_vulnerabilities.py Outdated Show resolved Hide resolved
tests/framework/microvm.py Outdated Show resolved Hide resolved
tests/integration_tests/functional/test_rng.py Outdated Show resolved Hide resolved
There is some information in the Microvm class that we don't save in the
snapshot. Some tests do depend on those, so to make the booted/restored
case homogenous, make room in the snapshot to save metadata that we can
then restore.

Signed-off-by: Pablo Barbáchano <[email protected]>
@pb8o pb8o force-pushed the test-refactors branch 2 times, most recently from 3432d94 to ae90872 Compare December 3, 2024 18:00
@pb8o pb8o requested a review from zulinx86 December 3, 2024 18:37
@pb8o pb8o added Status: Awaiting review Indicates that a pull request is ready to be reviewed and removed Status: Awaiting author Indicates that an issue or pull request requires author action labels Dec 3, 2024
Copy link
Contributor

@zulinx86 zulinx86 left a comment

Choose a reason for hiding this comment

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

Looks good to me to merge :)

Do you think it's worth updating the description for pytest fixtures in the test README file?

firecracker/tests/README.md

Lines 300 to 308 in 81bae9f

Most integration tests use fixtures that abstract away the creation and teardown
of Firecracker processes. The following fixtures spawn Firecracker processes
that are pre-initialized with specific guest kernels and rootfs:
- `uvm_plain_any` is parametrized by the guest kernels
[supported](../docs/kernel-policy.md) by Firecracker and a read-only Ubuntu
24.04 squashfs as rootfs,
- `uvm_plain` yields a Firecracker process pre-initialized with a 5.10 kernel
and the same Ubuntu 24.04 squashfs.

@zulinx86
Copy link
Contributor

zulinx86 commented Dec 4, 2024

It'd be nice to run it in non-PR mode before merging.

@pb8o pb8o requested a review from Manciukic as a code owner December 4, 2024 08:55
zulinx86
zulinx86 previously approved these changes Dec 5, 2024
Copy link
Contributor

@zulinx86 zulinx86 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks a lot for this series of changes again!

@pb8o
Copy link
Contributor Author

pb8o commented Dec 5, 2024

It'd be nice to run it in non-PR mode before merging.

I think at least the latest I have run it in both modes.

Manciukic
Manciukic previously approved these changes Dec 5, 2024
tests/integration_tests/security/test_vulnerabilities.py Outdated Show resolved Hide resolved
tests/integration_tests/security/test_nv.py Outdated Show resolved Hide resolved
tests/integration_tests/functional/test_rng.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
@pb8o pb8o dismissed stale reviews from Manciukic and zulinx86 via 5f8bd1a December 5, 2024 13:24
@pb8o pb8o force-pushed the test-refactors branch 2 times, most recently from 5f8bd1a to c1aecb7 Compare December 5, 2024 13:42
tests/framework/properties.py Show resolved Hide resolved
tests/framework/properties.py Show resolved Hide resolved
tests/integration_tests/security/test_nv.py Outdated Show resolved Hide resolved
@pb8o pb8o force-pushed the test-refactors branch 2 times, most recently from 714c78d to 2abf1da Compare December 5, 2024 14:22
pb8o added 11 commits December 5, 2024 15:25
Some further simplifications:
- Simplify the "_host" tests as they will provide the same result in
  both A/B situations.
- Add a second MicrovmFactory fixture with the "A" firecracker.
- Add a uvm_any fixture that includes all CPU templates and also a
  boot/restored dimension.

This decreases the need for separate tests. For example the guest test
test_check_vulnerability_files_ab can now test all variants:

2 (restored/booted) * 3 (kernels) * 9 (cpu templates) = 54 tests

Signed-off-by: Pablo Barbáchano <[email protected]>
Use a new uvm_any_booted fixture to make the test simpler.

Signed-off-by: Pablo Barbáchano <[email protected]>
Use the new uvm_any fixture to make the tests simpler

Signed-off-by: Pablo Barbáchano <[email protected]>
All tests in the file are x86_64 specific, so do the skip at the
top-level, once.

Signed-off-by: Pablo Barbáchano <[email protected]>
Make the common feature flags to get some clarity on what are the
differences between the CPUs.

Signed-off-by: Pablo Barbáchano <[email protected]>
This is the same test spread over two files. Putting it together in a
new file so they don't drift over time.

Signed-off-by: Pablo Barbáchano <[email protected]>
This is a fairly common repeated pattern, so extract it into a method to
make writing tests simpler.

Signed-off-by: Pablo Barbáchano <[email protected]>
Rewrite test_rng using uvm_any.

Signed-off-by: Pablo Barbáchano <[email protected]>
This fixture is not used anymore, as it is mostly superseded by
cpu_template_any.

Signed-off-by: Pablo Barbáchano <[email protected]>
Since we only have one rootfs, simplify the fixture to return a single
value. This will have also not show it as part of the test instance
name.

Signed-off-by: Pablo Barbáchano <[email protected]>
Add a parameter so that we can control vcpu number and memory.

Right now it uses a hardcoded value, but it can be overridden per test.

Signed-off-by: Pablo Barbáchano <[email protected]>
@pb8o pb8o merged commit d7734e2 into firecracker-microvm:main Dec 5, 2024
7 checks passed
@pb8o pb8o deleted the test-refactors branch December 5, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Indicates that an issue or pull request should be resolved behind issues or pull requests labelled ` python Pull requests that update Python code Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants