Ensure the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance#13492
Conversation
…ils of the vms with failed migrations on host maintenance - Fixes the Constraint error Column 'value' cannot be null
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #13492 +/- ##
=========================================
Coverage 17.67% 17.67%
- Complexity 15790 15794 +4
=========================================
Files 5922 5922
Lines 533173 533187 +14
Branches 65209 65210 +1
=========================================
+ Hits 94218 94234 +16
+ Misses 428309 428304 -5
- Partials 10646 10649 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@blueorangutan package |
There was a problem hiding this comment.
Pull request overview
This PR addresses a host-maintenance edge case where updating KVM VNC access VM details can attempt to persist a null value, triggering DB constraint failures (e.g., Column 'value' cannot be null). It does so by adding validation around the GetVncPortAnswer before writing kvm.vnc.* details, plus small supporting updates in tests and KVM agent-side logging.
Changes:
- Refactors VNC detail persistence in
ResourceManagerImplinto a helper that validates theGetVncPortAnswerbefore writing VM details. - Updates
ResourceManagerImplTestmocks to reflect the newgetResult()-gated behavior. - Adds an error log in the KVM Libvirt
GetVncPortcommand wrapper when libvirt throws.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
server/src/main/java/com/cloud/resource/ResourceManagerImpl.java |
Adds guarded VNC detail update logic to avoid persisting null/invalid values from GetVncPortAnswer. |
server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java |
Adjusts test setup to return successful GetVncPortAnswer results under the new logic. |
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVncPortCommandWrapper.java |
Adds logging when libvirt fails to resolve VNC port details for a VM. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!vmVncPortAnswer.getResult()) { | ||
| logger.warn("Failed to get VNC port for VM {} on host {}. Details: {}", vm, hostId, vmVncPortAnswer.getDetails()); | ||
| return; | ||
| } | ||
|
|
||
| String vncAddress = vmVncPortAnswer.getAddress(); | ||
| String vncPort = String.valueOf(vmVncPortAnswer.getPort()); | ||
| if (org.apache.commons.lang3.StringUtils.isNotBlank(vmVncPortAnswer.getAddress()) && org.apache.commons.lang3.StringUtils.isNotBlank(vncPort)) { | ||
| logger.info("Setting VNC access details for VM {} on host {} to address: {}, port: {}", vm, hostId, vncAddress, vncPort); | ||
| vmInstanceDetailsDao.addDetail(vm.getId(), VmDetailConstants.KVM_VNC_ADDRESS, vncAddress, true); | ||
| vmInstanceDetailsDao.addDetail(vm.getId(), VmDetailConstants.KVM_VNC_PORT, vncPort, true); | ||
| } else { | ||
| logger.warn("Unable to set VNC access details for VM {} on host {} as the address or port is blank. Address: {}, Port: {}", vm, hostId, vncAddress, vncPort); | ||
| } |
| logger.error("Failed to get vnc port for the vm: {} due to {}", command.getName(), e.getMessage()); | ||
| return new GetVncPortAnswer(command, e.toString()); |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18378 |
Description
This PR ensures the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance. It fixes the Constraint error "Column 'value' cannot be null" while updating the VNC access details.
Failed error log below (noticed with 4.18).
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?