Throw runtime exception when null templateVO is found#12406
Throw runtime exception when null templateVO is found#12406borisstoyanov merged 1 commit intoapache:4.20from
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.20 #12406 +/- ##
============================================
- Coverage 16.23% 16.23% -0.01%
+ Complexity 13381 13379 -2
============================================
Files 5657 5657
Lines 498958 498960 +2
Branches 60557 60558 +1
============================================
Hits 81025 81025
- Misses 408900 408902 +2
Partials 9033 9033
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:
|
|
@blueorangutan package |
|
@Pearl1594 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 16339 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15175)
|
There was a problem hiding this comment.
LGTM
Test Environments
| Environment | CloudStack Version | PR Applied |
|---|---|---|
| ref-trl-10695 | 4.20 | No (baseline) |
| ref-trl-10712 | 4.20 | Yes (#12406) |
Test Flow
- Register an ISO and wait for it to be ready
- Deploy a VM from template
- Attach the ISO to the VM
- Stop the VM
- Corrupt the ISO reference in database to simulate orphaned/missing ISO:
UPDATE user_vm SET iso_id = 99999 WHERE id = <vm_internal_id>;- Attempt to start the VM
- Check error message and logs
Test Results
Without PR #12406 (baseline)
API Response:
(localcloud) 🐱 > start virtualmachine id=335cbb13-a336-4c2a-a465-27b50f112c88
{
"account": "admin",
"accountid": "12560165-f7a9-11f0-8a32-1e00530003f0",
"cmd": "org.apache.cloudstack.api.command.admin.vm.StartVMCmdByAdmin",
"completed": "2026-01-26T09:44:09+0000",
"created": "2026-01-26T09:44:01+0000",
"domainid": "caadbbc0-f7a8-11f0-8a32-1e00530003f0",
"domainpath": "ROOT",
"jobid": "03364689-61a5-43ef-ae23-0bd83502cff1",
"jobinstanceid": "335cbb13-a336-4c2a-a465-27b50f112c88",
"jobinstancetype": "VirtualMachine",
"jobprocstatus": 0,
"jobresult": {
"errorcode": 530,
"errortext": "Command failed due to Internal Server Error"
},
"jobresultcode": 530,
"jobresulttype": "object",
"jobstatus": 2,
"userid": "1256a1b2-f7a9-11f0-8a32-1e00530003f0"
}
🙈 Error: async API failed for job 03364689-61a5-43ef-ae23-0bd83502cff1
Management Server Log:
2026-01-26 09:44:06,042 ERROR [c.c.v.VmWorkJobHandlerProxy] Invocation exception, caused by: java.lang.NullPointerException: Cannot invoke "com.cloud.storage.VMTemplateVO.isDirectDownload()" because "templateVO" is null
at org.apache.cloudstack.storage.image.TemplateDataFactoryImpl.isTemplateMarkedForDirectDownload(TemplateDataFactoryImpl.java:299)
at com.cloud.template.TemplateManagerImpl.prepareIso(TemplateManagerImpl.java:1264)
at com.cloud.template.TemplateManagerImpl.prepareIsoForVmProfile(TemplateManagerImpl.java:636)
With PR #12406
API Response:
(localcloud) 🐱 > start virtualmachine id=720f7fad-a162-4145-9d33-858e5f517f33
{
"account": "admin",
"accountid": "e9fad968-fa94-11f0-9cac-1e009a0003c2",
"cmd": "org.apache.cloudstack.api.command.admin.vm.StartVMCmdByAdmin",
"completed": "2026-01-26T09:51:46+0000",
"created": "2026-01-26T09:51:38+0000",
"domainid": "994bbb7a-fa94-11f0-9cac-1e009a0003c2",
"domainpath": "ROOT",
"jobid": "7ae5495f-c097-4308-afe6-bc0db98e0b55",
"jobinstanceid": "720f7fad-a162-4145-9d33-858e5f517f33",
"jobinstancetype": "VirtualMachine",
"jobprocstatus": 0,
"jobresult": {
"errorcode": 530,
"errortext": "Unable to orchestrate the start of VM instance {\"instanceName\":\"i-2-3-VM\",\"uuid\":\"720f7fad-a162-4145-9d33-858e5f517f33\"}."
},
"jobresultcode": 530,
"jobresulttype": "object",
"jobstatus": 2,
"userid": "e9fb4e75-fa94-11f0-9cac-1e009a0003c2"
}
🙈 Error: async API failed for job 7ae5495f-c097-4308-afe6-bc0db98e0b55
Management Server Log:
2026-01-26 09:51:42,505 ERROR [c.c.v.ClusteredVirtualMachineManagerImpl] Unable to orchestrate start VM instance {"id":3,"instanceName":"i-2-3-VM","state":"Stopped","type":"User","uuid":"720f7fad-a162-4145-9d33-858e5f517f33"} due to [Template not found with ID: 99999].
Summary
| Aspect | Before PR | After PR |
|---|---|---|
| API Error | Generic "Internal Server Error" | Orchestration failure with VM details |
| Log Message | NullPointerException (unhelpful) | Template not found with ID: 99999 (clear and actionable) |
| Root Cause Visible | No | Yes |
The fix correctly throws a CloudRuntimeException with a descriptive message when a null templateVO is encountered, making it much easier for administrators to diagnose issues related to orphaned ISO/template references.
* 4.22: fix install path for systemvm templates when introducing new sec storage (#11605) fix Sensitive Data Exposure Through Exception Logging in OVM Hypervis… (#12032) Fix snapshot physical size after migration (#12166) ConfigDrive: use file absolute path instead of canonical path to create ISO (#11623) Add log for null templateVO (#12406) snapshot: fix listSnapshots for volume which got delete and whose storage pool got deleted (#12433) Notify user if template upgrade is not required (#12483) Fix: proper permissions for systemvm template registrations on hardened systems (#12098) Allow modification of user vm details if user.vm.readonly.details is empty (#10456) NPE fix while deleting storage pool when pool has detached volumes (#12451)
Description
This PR fixes #12171
Throw an exception when null templateVO is encountered.
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?