Skip QemuImgTest when libvirt native library cannot load#13086
Skip QemuImgTest when libvirt native library cannot load#13086codingkiddo wants to merge 6 commits intoapache:mainfrom
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13086 +/- ##
=========================================
Coverage 18.07% 18.07%
+ Complexity 16704 16703 -1
=========================================
Files 6037 6037
Lines 542437 542437
Branches 66420 66420
=========================================
Hits 98067 98067
- Misses 433356 433357 +1
+ Partials 11014 11013 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR hardens the QemuImgTest setup routine so the test suite is skipped (via JUnit assumptions) when libvirt’s native/JNA library cannot be loaded, instead of failing the entire test class—improving developer experience on platforms like macOS.
Changes:
- Extend the libvirt availability probe to also catch
LinkageErrorin addition toLibvirtException. - Ensure libvirt native library load failures (e.g.,
UnsatisfiedLinkError) cause the test to be skipped via the existingAssume.assumeTrue(...)gate.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
QemuImgTest#setUp()currently checks whetherqemu-imgand libvirt are available before running the tests. The libvirt check catchesLibvirtException, but native library loading failures such asUnsatisfiedLinkErrorcan still escape and fail the test class.On macOS without
libvirt.dylibavailable, the test fails during setup with:This change catches LinkageError along with LibvirtException during the libvirt availability check, allowing the existing Assume.assumeTrue("libvirt not available", libVirtAvailable) to skip the test instead of failing the test class.
However, when the native libvirt/JNA library itself cannot be loaded, the setup can fail with UnsatisfiedLinkError before the test reaches the assumption check.
For example, on macOS without libvirt.dylib available, the test fails during setup with:
On Apple Silicon machines, this can also happen when the native library architecture is incompatible with the running JVM.
This change catches LinkageError along with LibvirtException during the libvirt availability check. Since UnsatisfiedLinkError extends LinkageError, this allows native library loading failures to be treated the same way as unavailable libvirt: the test is skipped instead of failing the entire test run.
Motivation and Context
QemuImgTest depends on native libvirt availability. On many developer machines, especially macOS environments, libvirt may not be installed or the required native library may not be loadable.
The existing test logic already treats unavailable libvirt as a skip condition. This change makes the availability check more robust by also handling native linkage failures.
This avoids failing the test class when the environment does not have the required native libvirt setup, while keeping the actual test behavior unchanged when libvirt is available.
What Changed
Updated the exception handling in QemuImgTest#setUp() from:
to:
How Has This Been Tested?
Tested locally with:
mvn -pl plugins/hypervisors/kvm -Dtest=QemuImgTest testBefore this change, the test failed during setup with:
java.lang.UnsatisfiedLinkError: Unable to load library 'virt'After this change, the test is skipped when the native libvirt library is not available.
Types of changes
Checklist