CSTACKEX-212: fix for snapshot failure for attached cs volumes nfs an… - #77
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes snapshot failures for ONTAP-backed volumes that are created-and-attached to running VMs in a single step by ensuring the volume’s image format is set consistently (KVM → QCOW2) during ONTAP volume creation.
Changes:
- Set
VolumeVO.formatduringcreateAsync()for both iSCSI and NFS3 ONTAP-managed volumes based on the pool hypervisor. - Add unit-test stubbing for
StoragePool.getHypervisor()to support the new format-resolution logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java | Set volume format during creation and add hypervisor→image-format resolution helper. |
| plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java | Update tests to provide pool hypervisor needed by the new format-setting logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sandeeplocharla
left a comment
There was a problem hiding this comment.
Awesome work!!!
8856437
| VolumeVO volVO = _volsDao.findById(volumeInfo.getId()); | ||
| if (volVO.getFormat() == null) { | ||
| HypervisorType hyperType = storagePool.getHypervisor(); | ||
| volVO.setFormat(getSupportedImageFormatForHypervisor(hyperType)); | ||
| } | ||
| _volsDao.update(volVO.getId(), volVO); | ||
| return volVO; |
| HypervisorType hyperType = storagePool.getHypervisor(); | ||
| ImageFormat format = getSupportedImageFormatForHypervisor(hyperType); | ||
| if (format != null) { |
| private ImageFormat getSupportedImageFormatForHypervisor(HypervisorType hyperType) { | ||
| if (hyperType == HypervisorType.XenServer) { | ||
| return ImageFormat.VHD; | ||
| } else if (hyperType == HypervisorType.KVM) { | ||
| return ImageFormat.QCOW2; | ||
| } else if (hyperType == HypervisorType.VMware) { | ||
| return ImageFormat.OVA; | ||
| } else if (hyperType == HypervisorType.Ovm) { | ||
| return ImageFormat.RAW; | ||
| } else if (hyperType == HypervisorType.Hyperv) { | ||
| return ImageFormat.VHDX; | ||
| } else { | ||
| return null; | ||
| } |
sandeeplocharla
left a comment
There was a problem hiding this comment.
'DefaultPrimary' plugin currently supports multiple hypervisors and storage protocols. It has snapshot capabilities for a long time. Can you check if even it has the same issue as our plugin and if these changes fix it?
If it works without these changes, maybe we need to understand how its handling it.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java:1014
- getImageFormatByHypervisor can throw a NullPointerException when storagePool.getHypervisor() returns null because it calls hypervisorType.equals(...). Since StoragePoolVO.getHypervisor() can be null, this can break volume creation with an NPE instead of a controlled failure. Guard against null and compare enums with == (or call equals on the constant).
private Storage.ImageFormat getImageFormatByHypervisor(HypervisorType hypervisorType) {
if (hypervisorType.equals(HypervisorType.KVM)) {
return Storage.ImageFormat.QCOW2;
}
throw new CloudRuntimeException("Unsupported hypervisor [" + hypervisorType + "] for ONTAP image format resolution");
suryag1201
left a comment
There was a problem hiding this comment.
also add assertion to check the format is set or not after createAsync
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java:1015
- getImageFormatByHypervisor uses hypervisorType.equals(...), which will throw a NullPointerException if StoragePool.getHypervisor() returns null. Since this method is used during createAsync, that would fail volume creation with an unhelpful NPE. Prefer enum-safe comparisons (==) and explicitly handle null with a clearer exception message.
if (hypervisorType.equals(HypervisorType.KVM)) {
return Storage.ImageFormat.QCOW2;
}
throw new CloudRuntimeException("Unsupported hypervisor [" + hypervisorType + "] for ONTAP image format resolution");
}
| volumeVO.setPoolType(storagePool.getPoolType()); | ||
| volumeVO.setPoolId(storagePool.getId()); | ||
| volumeVO.setFormat(getImageFormatByHypervisor(storagePool.getHypervisor())); | ||
| logger.info("createAsync: Volume format set to [{}] for hypervisor [{}]", volumeVO.getFormat(), storagePool.getHypervisor()); |
#77) ### Description Fix snapshot failure for CloudStack volumes attached to running VMs on ONTAP primary storage (both NFS3 and iSCSI protocols). This PR... <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. --> When a volume was created and attached to a running VM in a single step,by enabling create on storage and choose the storage pool tag the volume format was not being set correctly. The format is now determined by the hypervisor type (KVM → QCOW2) in ontapdriver via [getImageFormatByHypervisor(HypervisorType] mirroring the [getSupportedImageFormatForCluster] in VolumeOrchestrator file. <!-- For new features, provide link to FS, dev ML discussion etc. --> <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. --> <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged --> <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" --> <!-- Fixes: # --> <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [X] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [ ] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [ ] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [X] Major - [ ] Minor - [ ] Trivial ### How Has This Been Tested? Tested on a dev setup against these scenarios: Scenario A — Attach data disk to running VM, then snapshot - Create ONTAP primary storage pool (NFS3 or iSCSI) - Deploy VM with data disk using pool-tagged disk offering → VM reaches Running state - Create volume attached to the running VM by enabling create on storage and choose the storage pool tag - Take snapshot of attached volume — ✅ succeeds (was failing before fix) Scenario B — Attach volume to root-disk-only VM, then snapshot - Create ONTAP primary storage pool (NFS3 or iSCSI) - Deploy VM without data disk → VM reaches Running state - Create and attach volume to the running VM by enabling create on storage and choose the storage pool tag - Take snapshot of attached volume — ✅ succeeds (was failing before fix) scenarios-C-create a volume on storage pool but not attach to any vm - Create ONTAP primary storage pool (NFS3 or iSCSI) - Create volume by enabling create on storage and choose the storage pool tag - Take snapshot- — ✅ succeeds (was failing before fix) ### Screenshots (if appropriate): snapshots for when cs volume is attached to NFS and ISCSI instance that has both root and data disk and create on storage enabled: <img width="1464" height="436" alt="Screenshot 2026-07-15 at 12 28 32 AM" src="https://github.com/user-attachments/assets/69827e56-ac5d-4746-a2e9-f32ac8e95433" /> <img width="1472" height="414" alt="Screenshot 2026-07-15 at 12 28 38 AM" src="https://github.com/user-attachments/assets/799c8485-7023-4b1f-9eeb-3d0c4a745a57" /> verifying on ontap and db: <img width="1549" height="343" alt="Screenshot 2026-07-15 at 12 28 58 AM" src="https://github.com/user-attachments/assets/ee62e8b1-81a9-41b9-b5fb-639133a1cfff" /> <img width="1548" height="397" alt="Screenshot 2026-07-15 at 12 29 10 AM" src="https://github.com/user-attachments/assets/8f74ae08-437e-4ac6-aa24-49ef4675cd30" /> <img width="1720" height="175" alt="Screenshot 2026-07-15 at 12 30 43 AM" src="https://github.com/user-attachments/assets/088fbc14-581e-4ac9-85df-77bced054e3f" /> snapshots for when cs volume is attached to NFS and ISCSI instance that has only root and also case when they are not attached to any instance and create on storage enabled: <img width="1458" height="320" alt="Screenshot 2026-07-15 at 12 52 30 AM" src="https://github.com/user-attachments/assets/8150b81c-bc07-48e7-91ca-c93ef53b6e8a" /> <img width="1454" height="256" alt="Screenshot 2026-07-15 at 12 52 39 AM" src="https://github.com/user-attachments/assets/0408156a-6374-4026-b5aa-b51b070fd44f" /> <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> #### How did you try to break this feature and the system with this change? <!-- see how your change affects other areas of the code, etc. --> <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
#77) ### Description Fix snapshot failure for CloudStack volumes attached to running VMs on ONTAP primary storage (both NFS3 and iSCSI protocols). This PR... <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. --> When a volume was created and attached to a running VM in a single step,by enabling create on storage and choose the storage pool tag the volume format was not being set correctly. The format is now determined by the hypervisor type (KVM → QCOW2) in ontapdriver via [getImageFormatByHypervisor(HypervisorType] mirroring the [getSupportedImageFormatForCluster] in VolumeOrchestrator file. <!-- For new features, provide link to FS, dev ML discussion etc. --> <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. --> <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged --> <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" --> <!-- Fixes: # --> <!--- ******************************************************************************* --> <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. --> <!--- PLEASE PUT AN 'X' in only **ONE** box --> <!--- ******************************************************************************* --> ### Types of changes - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] New feature (non-breaking change which adds functionality) - [X] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [ ] Test (unit or integration test code) ### Feature/Enhancement Scale or Bug Severity #### Feature/Enhancement Scale - [ ] Major - [ ] Minor #### Bug Severity - [ ] BLOCKER - [ ] Critical - [X] Major - [ ] Minor - [ ] Trivial ### How Has This Been Tested? Tested on a dev setup against these scenarios: Scenario A — Attach data disk to running VM, then snapshot - Create ONTAP primary storage pool (NFS3 or iSCSI) - Deploy VM with data disk using pool-tagged disk offering → VM reaches Running state - Create volume attached to the running VM by enabling create on storage and choose the storage pool tag - Take snapshot of attached volume — ✅ succeeds (was failing before fix) Scenario B — Attach volume to root-disk-only VM, then snapshot - Create ONTAP primary storage pool (NFS3 or iSCSI) - Deploy VM without data disk → VM reaches Running state - Create and attach volume to the running VM by enabling create on storage and choose the storage pool tag - Take snapshot of attached volume — ✅ succeeds (was failing before fix) scenarios-C-create a volume on storage pool but not attach to any vm - Create ONTAP primary storage pool (NFS3 or iSCSI) - Create volume by enabling create on storage and choose the storage pool tag - Take snapshot- — ✅ succeeds (was failing before fix) ### Screenshots (if appropriate): snapshots for when cs volume is attached to NFS and ISCSI instance that has both root and data disk and create on storage enabled: <img width="1464" height="436" alt="Screenshot 2026-07-15 at 12 28 32 AM" src="https://github.com/user-attachments/assets/69827e56-ac5d-4746-a2e9-f32ac8e95433" /> <img width="1472" height="414" alt="Screenshot 2026-07-15 at 12 28 38 AM" src="https://github.com/user-attachments/assets/799c8485-7023-4b1f-9eeb-3d0c4a745a57" /> verifying on ontap and db: <img width="1549" height="343" alt="Screenshot 2026-07-15 at 12 28 58 AM" src="https://github.com/user-attachments/assets/ee62e8b1-81a9-41b9-b5fb-639133a1cfff" /> <img width="1548" height="397" alt="Screenshot 2026-07-15 at 12 29 10 AM" src="https://github.com/user-attachments/assets/8f74ae08-437e-4ac6-aa24-49ef4675cd30" /> <img width="1720" height="175" alt="Screenshot 2026-07-15 at 12 30 43 AM" src="https://github.com/user-attachments/assets/088fbc14-581e-4ac9-85df-77bced054e3f" /> snapshots for when cs volume is attached to NFS and ISCSI instance that has only root and also case when they are not attached to any instance and create on storage enabled: <img width="1458" height="320" alt="Screenshot 2026-07-15 at 12 52 30 AM" src="https://github.com/user-attachments/assets/8150b81c-bc07-48e7-91ca-c93ef53b6e8a" /> <img width="1454" height="256" alt="Screenshot 2026-07-15 at 12 52 39 AM" src="https://github.com/user-attachments/assets/0408156a-6374-4026-b5aa-b51b070fd44f" /> <!-- Please describe in detail how you tested your changes. --> <!-- Include details of your testing environment, and the tests you ran to --> #### How did you try to break this feature and the system with this change? <!-- see how your change affects other areas of the code, etc. --> <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
Description
Fix snapshot failure for CloudStack volumes attached to running VMs on ONTAP primary storage (both NFS3 and iSCSI protocols).
This PR...
When a volume was created and attached to a running VM in a single step,by enabling create on storage and choose the storage pool tag the volume format was not being set correctly. The format is now determined by the hypervisor type (KVM → QCOW2) in ontapdriver via [getImageFormatByHypervisor(HypervisorType] mirroring the [getSupportedImageFormatForCluster] in VolumeOrchestrator file.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
How Has This Been Tested?
Tested on a dev setup against these scenarios:
Scenario A — Attach data disk to running VM, then snapshot
Scenario B — Attach volume to root-disk-only VM, then snapshot
scenarios-C-create a volume on storage pool but not attach to any vm
Screenshots (if appropriate):
snapshots for when cs volume is attached to NFS and ISCSI instance that has both root and data disk and create on storage enabled:


verifying on ontap and db:



snapshots for when cs volume is attached to NFS and ISCSI instance that has only root and also case when they are not attached to any instance and create on storage enabled:


How did you try to break this feature and the system with this change?