codingkiddo opened a new pull request, #13086:
URL: https://github.com/apache/cloudstack/pull/13086

   ## 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:
   
   ```text
   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:
   
   ```text
   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:
   
   ```java
   } catch (LibvirtException ignored) {}
   ```
   to: 
   
   ```java
   } catch (LibvirtException | LinkageError ignored) {}
   ```
   
   ### How Has This Been Tested?
   
   Tested locally with:
   
   ```bash
   mvn -pl plugins/hypervisors/kvm -Dtest=QemuImgTest test
   ```
   
   Before this change, the test failed during setup with:
   
   ```bash
   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
   
   - [x] Bug fix
   - [ ] Improvement
   - [ ] New feature
   - [ ] Breaking change
   - [ ] Documentation update
   
   ## Checklist
   
   - [x] The change is limited to test setup behavior
   - [x] No production code behavior is changed
   - [x] Existing behavior is preserved when libvirt is available
   - [x] The test now skips instead of failing when native libvirt libraries 
cannot be loaded


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to