Repository navigation
Conversation
enable_coverage.py wraps the ExecStart=/usr line of each stage service with `coverage run`. Since the single process optimization (canonical#5489) the stage services are shims whose ExecStart is `sh -c '... | nc ...'`, so nothing got wrapped and coverage was silently no longer collected. On releases whose packaging disables the optimization, the script instead exits early because the network stage is still cloud-init.service. Wrap whichever of cloud-init-main.service and the stage services run cloud-init from /usr, and fail when none do, so that a future unit change cannot silently disable coverage again. Fixes canonicalGH-6769
27a65dd to
301af0e
Compare
holmanb
left a comment
There was a problem hiding this comment.
Thanks for the work on this. It looks like this still doesn't work.
The 'coverage==' check in tests/integration_tests/instances.py makes an invalid assumption: coverage is no longer pinned.
| file_path.write_text(content) | ||
| patched.append(service) | ||
|
|
||
| if not patched: |
There was a problem hiding this comment.
I don't see patched used for anything but this - wouldn't a bool be simpler?
install_coverage() looked for a "coverage==" pin in integration-requirements.txt, which no longer pins coverage, so it raised before enabling coverage. Install the coverage version found locally instead, which is also the one that combines the collected data into the report. Releases implementing PEP 668 refuse "pip3 install" into the system Python, and the result was not checked, so coverage could be silently missing and the wrapped unit would then fail to start. Set PIP_BREAK_SYSTEM_PACKAGES, which older pip ignores, and assert that the install succeeds. Also make the patched flag in enable_coverage.py a bool.
|
@holmanb can you please review the changes again? |
|
Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close. If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging blackboxsw, and he will ensure that someone takes a look soon. (If the pull request is closed and you would like to continue working on it, please do tag blackboxsw to reopen it.) |
Proposed Commit Message
Additional Context
Fixes #6769
The script has to handle two unit layouts:
cloud-init-main.servicerunsExecStart=/usr/bin/cloud-init --all-stages, and the stage services arencshims. The current script exits 0 without wrapping anything, so coverage is never collected.debian/patches/no-single-process.patchonubuntu/jammyandubuntu/noble): there is nocloud-init-main.service. Each stage service runs/usr/bin/cloud-init ...itself, and the network stage iscloud-init.service. The current script exits 1 becausecloud-init-network.servicedoes not exist, so the assertion ininstall_coverage()fails.I checked the new script against unit files rendered from
systemd/*.tmpland against the no-single-process variants of them. It wraps onlycloud-init-main.servicein the first case and the four stage services in the second. With no matching unit, it fails. I also confirmed that aType=notifyunit whoseExecStartis wrapped inpython -m coverage run --appendstill reaches READY and writes.coverageto its working directory (systemd-run --user --wait -p Type=notify ...). I have not run the full integration suite with coverage enabled because I don't have LXD available here.enable_profile.pyhas the same problem, and_collect_profile()intests/integration_tests/conftest.pystill expects one stats file per stage. I'm happy to fix that in a follow-up so this PR stays focused on the reported issue.Test Steps
/tmp/cloud_init_test_logs/last/html/index.htmlshould now report coverage forcloudinit/. Repeat withCLOUD_INIT_OS_IMAGE=noble CLOUD_INIT_CLOUD_INIT_SOURCE=NONEfor the no-single-process layout.Merge type