-
Notifications
You must be signed in to change notification settings - Fork 908
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
Enable coverage in integration tests #4682
Conversation
] | ||
): | ||
return | ||
def _collect_logs(instance: IntegrationInstance, log_dir: Path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To help read the following sections:
Instead of _collect_logs
, we instead call a new _collect_artifacts
after every test. This function will check what needs to be setup based on the integration settings, then call _collect_logs
and/or _collect_coverage
accordingly.
b64c70b
to
9001f07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @TheRealFalcon, great work.
As it is right now:
- We instrument the cloud-init services with
coverage
in the tested instance. - Run pytest from test-runner instance.
- Pull the coverage metadata files from the tested instance.
- Generate the coverage reports in the test-runner instance.
The last step fails if cloud-init is not installed in the test-runner instance because the coverage metadata points to /usr/lib/python3/dist-packages/cloudinit
. See: log.txt.
I wonder if it would be better to generate the reports in the tested instance and pull them, as coverage is already installed there.
This would remove the need to install cloud-init in developer's machines and would avoid misalignment between cloud-init versions in both machines, which could provoke this same error (I am not sure if the absence or modification of only one file would lead to this error, but it could be).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! One inline question / and some random comments.
In response to @aciba90's comments:
The last step fails if cloud-init is not installed in the test-runner instance
Is this actually a problem? The package python3-coverage
gets installed in tests/integration_tests/instances.py
, so when would this happen?
I wonder if it would be better to generate the reports in the tested instance and pull them, as coverage is already installed there.
This would remove the need to install cloud-init in developer's machines and would avoid misalignment between cloud-init versions in both machines, which could provoke this same error (I am not sure if the absence or modification of only one file would lead to this error, but it could be).
I think you meant s/cloud-init/python3-coverage/g
here. I agree this might forcibly require the host and guest to have the same coverage version for this to work. Generation on the host would be better I think and therefore also wouldn't require local install of coverage.
exit(1) | ||
|
||
# Prepend the ExecStart= line with 'python3 -m coverage run' | ||
for service in services: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done similar things (more ad-hoc) for inserting profiler commands into the service files. At some point I'll probably steal this code or make it more generic to do that in automatically in tox (unless someone else wants to do it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import pytest | ||
|
||
from cloudinit.subp import subp | ||
from tests.integration_tests.instances import IntegrationInstance | ||
|
||
if TYPE_CHECKING: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this? Performance optimization? Can we add a comment or something to the commit message? Also if this isn't required for enabling coverage maybe it should go in its own commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid circular import. I almost made it a separate commit...so...I guess I will 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please include a comment that it's for avoiding circular import?
9001f07
to
d33dee0
Compare
Thanks! I had the cloud-init package installed locally, so I hadn't noticed this
You've identified two different issues:
For 1, coverage has a configuration option to align a directory on your local machine with paths from coverage files. I pushed a change (see For 2, that is a valid concern, but it's not one that I'm super concerned about. If there's a mismatch in source, our coverage numbers might be slightly off, but in most cases not enough to make a considerable difference. If we want to avoid this, we can ensure that the code we're testing is the same as the code we're launching from.
I'm not sure there's a way as easy way to do this. |
Thanks for the explanation and addressing 1. I agree, 2 is not worth handling. I get now the following error:
Misalignment between inner and outer coverage versions? Full test session: https://pastebin.canonical.com/p/gShy25PkSq/ |
I pushed two new commits to install via pip rather than using python3-coverage. If the PR is approved, I plan on moving the refactor commit earlier and squashing the fixup commit, but I left them in the current order for easier review. |
d6daa1c
to
a3e1d40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
) Integration tests allow for installing a new version of cloud-init with the option of snapshotting the image after install. After taking a snapshot, it will then set the snapshot as the default for *all* future launches in this test run. This is also used by the conftest to setup the initial image, but it should not be used anywhere else. Rather than having it as an option to the install_new_cloud_init method, remove the option and make the confest set the global snapshot instead. This removes a footgun when writing other tests that need to install a different version of cloud-init.
`get_top_level_dir` and `cloud_init_project_dir` have uses in integration tests. Move them up to a top-level test helper file accordingly.
a3e1d40
to
673bb73
Compare
Integration tests allow for installing a new version of cloud-init with the option of snapshotting the image after install. After taking a snapshot, it will then set the snapshot as the default for *all* future launches in this test run. This is also used by the conftest to setup the initial image, but it should not be used anywhere else. Rather than having it as an option to the install_new_cloud_init method, remove the option and make the confest set the global snapshot instead. This removes a footgun when writing other tests that need to install a different version of cloud-init.
`get_top_level_dir` and `cloud_init_project_dir` have uses in integration tests. Move them up to a top-level test helper file accordingly.
Proposed Commit Message
rebase
Additional Context
Merge type