Skip to content

Skip QemuImgTest when libvirt native library cannot load#13086

Open
codingkiddo wants to merge 6 commits intoapache:mainfrom
codingkiddo:skip-qemu-img-test-when-libvirt-native-library-unavailable
Open

Skip QemuImgTest when libvirt native library cannot load#13086
codingkiddo wants to merge 6 commits intoapache:mainfrom
codingkiddo:skip-qemu-img-test-when-libvirt-native-library-unavailable

Conversation

@codingkiddo
Copy link
Copy Markdown

Description

QemuImgTest#setUp() currently checks whether qemu-img and libvirt are available before running the tests. The libvirt check catches LibvirtException, but native library loading failures such as UnsatisfiedLinkError can still escape and fail the test class.

On macOS without libvirt.dylib available, the test fails during setup with:

java.lang.UnsatisfiedLinkError: Unable to load library 'virt'

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:

java.lang.UnsatisfiedLinkError: Unable to load library 'virt'

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:

} catch (LibvirtException ignored) {}

to:

} catch (LibvirtException | LinkageError ignored) {}

How Has This Been Tested?

Tested locally with:

mvn -pl plugins/hypervisors/kvm -Dtest=QemuImgTest test

Before 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

  • Bug fix
  • Improvement
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • The change is limited to test setup behavior
  • No production code behavior is changed
  • Existing behavior is preserved when libvirt is available
  • The test now skips instead of failing when native libvirt libraries cannot be loaded

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 29, 2026

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)
Here are some useful points:

@DaanHoogland DaanHoogland requested review from Copilot and shwstppr and removed request for Copilot April 29, 2026 13:11
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 18.07%. Comparing base (8906aa1) to head (39ad0a4).

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     
Flag Coverage Δ
uitests 3.52% <ø> (ø)
unittests 19.24% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LinkageError in addition to LibvirtException.
  • Ensure libvirt native library load failures (e.g., UnsatisfiedLinkError) cause the test to be skipped via the existing Assume.assumeTrue(...) gate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants