Skip QemuImgTest when libvirt native library cannot load by codingkiddo · Pull Request #13086 · apache/cloudstack (original) (raw)

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

Checklist