Skip to content

Cover the libvirt helper and its CLI - #101

Merged
insatomcat merged 2 commits into
mainfrom
libvirt-unit-coverage
Sep 14, 2026
Merged

insatomcat merged 2 commits into
mainfrom
libvirt-unit-coverage

Conversation

@insatomcat

Copy link
Copy Markdown
Member

Last of the three PRs on the helpers. helpers/libvirt.py goes from 65% to 100% and helpers/libvirt_cmd.py from 0% to 94%, in 57 unit tests, with no libvirt daemon. The two modules travel together because they are 55 uncovered statements between them, too little to be worth splitting.

test_libvirt_manager.py still drives a real qemu:///system and is untouched. What is added covers what a daemon will not produce on demand: a crashed or PM-suspended domain, the console handover to virsh, the XML export. Only libvirt.open() is replaced, so a test asserting on VIR_DOMAIN_PMSUSPENDED asserts on the value the daemon reports; the constants and exception types still come from the real module, through a __getattr__ fall-through on the fake.

libvirt_cmd is driven through sys.argv against a recording manager. The two spots left uncovered are the __main__ guard and the fall-through of the command chain, which argparse makes unreachable. Both also stand uncovered in vm_manager_cmd.py, and neither is worth a coverage exclusion.

No production code changes, and no defect found in either module this time.

Twelve mutations are all caught, among them the word each domain state maps to, the VIR_DOMAIN_UNDEFINE_NVRAM and VIR_DOMAIN_DEFINE_VALIDATE flags, the autostart value, the CalledProcessError the console swallows, the shell=True of the export, and the argument order libvirt_cmd export passes on.

Independent of #99 and #100. With the three merged, the project reaches roughly 99% statement coverage, past the OpenSSF gold target of 90%.

39 unit tests against a fake connection, no daemon.
helpers/libvirt.py goes from 65% to 100%.

test_libvirt_manager.py keeps driving a real qemu:///system. What is
added here is what a daemon will not produce on demand: the crashed and
PM-suspended domain states, the console handover and the XML export.
Only libvirt.open() is replaced, so the VIR_DOMAIN_* constants under
test are the ones the daemon reports.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
18 unit tests driving main() through argv against a recording manager.
helpers/libvirt_cmd.py goes from 0% to 94%.

The two spots left are the __main__ guard and the fall-through of the
command chain, which argparse makes unreachable.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
@insatomcat
insatomcat force-pushed the libvirt-unit-coverage branch from fbc64ef to b6b99ac Compare September 14, 2026 12:03
@sonarqubecloud

Copy link
Copy Markdown

@insatomcat
insatomcat merged commit 0856ab9 into main Sep 14, 2026
5 checks passed
@insatomcat
insatomcat deleted the libvirt-unit-coverage branch September 14, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants