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

test: use single SSH connection for lifetime of microvm #4953

Closed
wants to merge 16 commits into from

Conversation

roypat
Copy link
Contributor

@roypat roypat commented Dec 10, 2024

Changes

In the SSHConnection class in our integration test framework, open a single SSH connection and reuse that for all communication with a specific microvm.

Reason

Currently, we were recreating SSH connections for each command we want to run inside a microvm. This was leading to spurious failures because only the first connection attempt (which we also use to wait for microvm boot) was using retries.

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.

ShadowCurse and others added 15 commits December 10, 2024 12:04
Update Rust to 1.83 version

Signed-off-by: Egor Lazarchuk <[email protected]>
Signed-off-by: Patrick Roy <[email protected]>
From: Egor Lazarchuk <[email protected]>

With a new Rust version, new Clippy entered our repository.
This commit aligns our codebase with guidance provided by
new lints.

Also remove a `deny(clippy::pedantic)`, because I'm not fixing those.

Signed-off-by: Egor Lazarchuk <[email protected]>
Co-authored-by: Patrick Roy <[email protected]>
Signed-off-by: Patrick Roy <[email protected]>
This is needed for CI to install previous version of the
toolchain used on the main branch. This change will need
to be reverted after this PR is merged.

Signed-off-by: Egor Lazarchuk <[email protected]>
Signed-off-by: Patrick Roy <[email protected]>
Add the rust-src component and the $(uname -m)-unknown-linux-musl
targets for the nightly toolchain, and install python3-seccomp and
rustfilt. Since the python bindings for libseccomp are not published to
pip, we have to install it into the global python installation via
apt-get, and then copy into our venv.

Signed-off-by: Patrick Roy <[email protected]>
Build static version of libseccomp with `musl-gcc`. This is needed for
our musl builds as the version shipped in the ubuntu package is not
compiled with `musl-gcc` and produces linker errors.

Signed-off-by: Egor Lazarchuk <[email protected]>
Signed-off-by: Patrick Roy <[email protected]>
From: Jonathan Woollett-Light <[email protected]>

Adds `cargo-udeps` and the Rust `nightly` toolchain to support it, to
dev container.

Signed-off-by: Jonathan Woollett-Light <[email protected]>
Co-authored-by: Patrick Roy <[email protected]>
Signed-off-by: Patrick Roy <[email protected]>
These python dependencies are used for an upcoming PR about reusing SSH
connection in our SSH tests.

Signed-off-by: Patrick Roy <[email protected]>
accumulate all the dockerfile changes into a new devctr version

Signed-off-by: Patrick Roy <[email protected]>
This is needed to work around a bug in `VmFd::create_device`, where
undefined behavior caused a miscompilation on newer rust toolchains.

Signed-off-by: Patrick Roy <[email protected]>
With the devctr's python dependencies update, we pulled in a new pylint
version, which has a new `too-many-positional-arguments` lint. Fixing
this would be a significant refactor, so just suppress it, as it seems
low-value.

Signed-off-by: Patrick Roy <[email protected]>
With newer rust toolchains, rust will SIGABRT if an already closed file
descriptor is closed in the the `Drop` implementation for `File`. This
also applies to creating `File`s with invalid file descriptors. Thus fix
tests that accidentally double-close fds, and remove those that
explicitly construct `File`s with invalid file descriptors (they are
redundant now anyway, because Rust would abort if this ever happened).

Signed-off-by: Patrick Roy <[email protected]>
It seemingly finally got intelligent enough to realize we don't need all
these backslashes on the brackets.

Signed-off-by: Patrick Roy <[email protected]>
The unittests here rely on the cfg(not(test)) antipattern for mocking,
which new rust compiler interprets as the production version of the
structs being dead-code when running unittests.

Refactoring this to eliminate mocking is difficult, because fdt unit
tests rely on the mocks removing all host-specific information from the
cpu FDT nodes (particularly cache information, which in prod is read
from the host sysfs, but in test mode is some dummy mock values).

Signed-off-by: Patrick Roy <[email protected]>
with new mdformat we no longer need to wrap level 2 headings in escaped
brackets, just normal brackets.

Signed-off-by: Patrick Roy <[email protected]>
My python version does not accept the precense of double quotes inside a
double-quoted f-string. Use single quotes instead.

Signed-off-by: Patrick Roy <[email protected]>
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.98%. Comparing base (db2e270) to head (85a2f24).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
src/vmm/src/devices/virtio/queue.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4953      +/-   ##
==========================================
- Coverage   84.07%   83.98%   -0.10%     
==========================================
  Files         251      251              
  Lines       28059    27889     -170     
==========================================
- Hits        23592    23422     -170     
  Misses       4467     4467              
Flag Coverage Δ
5.10-c5n.metal 84.55% <97.05%> (-0.10%) ⬇️
5.10-m5n.metal 84.53% <97.05%> (-0.10%) ⬇️
5.10-m6a.metal 83.82% <97.05%> (-0.12%) ⬇️
5.10-m6g.metal 80.68% <97.05%> (-0.07%) ⬇️
5.10-m6i.metal 84.52% <97.05%> (-0.10%) ⬇️
5.10-m7g.metal 80.68% <97.05%> (-0.07%) ⬇️
6.1-c5n.metal 84.55% <97.05%> (-0.10%) ⬇️
6.1-m5n.metal 84.54% <97.05%> (-0.10%) ⬇️
6.1-m6a.metal 83.82% <97.05%> (-0.12%) ⬇️
6.1-m6g.metal 80.67% <97.05%> (-0.08%) ⬇️
6.1-m6i.metal 84.53% <97.05%> (-0.10%) ⬇️
6.1-m7g.metal 80.68% <97.05%> (-0.07%) ⬇️

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.

@roypat roypat mentioned this pull request Dec 10, 2024
10 tasks
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Dec 10, 2024
zulinx86
zulinx86 previously approved these changes Dec 11, 2024
Comment on lines 79 to 74

def _scp(self, path1, path2, options):
"""Copy files to/from the VM using scp."""
self._exec(["scp", *options, path1, path2], check=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Do we still need _scp()? If no, we can also remove the internal function _exec() and hardcode the logic in run().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah, good catch! Removed :)

Instead of creating new SSH connections every time we want to run a
command inside the microvm, open a single ssh connection in the
constructor of `SSHConnection`, and reuse it until we kill the microvm.

Use the `fabric` SSH library to achieve this.

Since fabric by default does not support opening its connections in
specific network namespaces (e.g. ip netns exec), explicitly switch into
the target network namespace before establishing the connected. Since
entering network namspaces happens per-thread (instead of per-process),
this is fine to do even in a highly-multithreaded pytest environment.

Signed-off-by: Patrick Roy <[email protected]>
@roypat
Copy link
Contributor Author

roypat commented Dec 11, 2024

I'm closing this PR since @pb8o has shown me an approach using ControlMaster/ControlPersist that doesnt require new dependencies. Will open a separate PR with that.

@roypat roypat closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants