Skip to content

code coverage breakage #6769

@ani-sinha

Description

@ani-sinha

Bug report

The commit 143bc9e40f7f33695216db60f73e10a900d1d1cd ("feat: Single process optimization (#5489)") changed the following in the cloud-init-local.service.tmpl

-ExecStart=/usr/bin/cloud-init init --local
+# This service is a shim which preserves systemd ordering while allowing a
+# single Python process to run cloud-init's logic. This works by communicating
+# with the cloud-init process over a unix socket to tell the process that this
+# stage can start, and then wait on a return socket until the cloud-init
+# process has completed this stage. The output from the return socket is piped
+# into a shell so that the process can send a completion message (defaults to
+# "done", otherwise includes an error message) and an exit code to systemd.
+ExecStart=sh -c 'echo "start" | nc.openbsd -Uu -W1 /run/cloud-init/share/local.sock -s /run/cloud-init/share/local-return.sock | sh'

and for other unit files as well. Example, for cloud-config.service.tmpl

-ExecStart=/usr/bin/cloud-init modules --mode=config
+# This service is a shim which preserves systemd ordering while allowing a
+# single Python process to run cloud-init's logic. This works by communicating
+# with the cloud-init process over a unix socket to tell the process that this
+# stage can start, and then wait on a return socket until the cloud-init
+# process has completed this stage. The output from the return socket is piped
+# into a shell so that the process can send a completion message (defaults to
+# "done", otherwise includes an error message) and an exit code to systemd.
+ExecStart=sh -c 'echo "start" | nc.openbsd -Uu -W1 /run/cloud-init/share/config.sock -s /run/cloud-init/share/config-return.sock | sh'

The enable_coverage.py looks for ExecStart=/usr and replaces with a code that calls the code coverage tool:

    content = content.replace(
        "ExecStart=/usr",
        (
            "ExecStart=python3 -m coverage run "
            "--source=/usr/lib/python3/dist-packages/cloudinit --append /usr"
        ),
    )

so that the unit files when executed can start collecting the code coverage data. This is broken with the change.

Steps to reproduce the problem

Try to run code coverage integration test in cloud-init. It does not work.

Environment details

  • Cloud-init version: latest
  • Operating System Distribution: Ubuntu 24.4
  • Cloud provider, platform or installer type: lxd container

cloud-init logs

2026-02-26 12:16:08 WARNING   integration_testing:conftest.py:569 Could not generate report during session finish: [Errno 2] No such file or directory: '/tmp/cloud_init_test_logs/260226121439'
 ...

Message: 'Could not generate report during session finish: %s'
Arguments: (FileNotFoundError(2, 'No such file or directory'),

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions