Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Storage;
import com.cloud.storage.StoragePool;
import com.cloud.storage.Volume;
Expand Down Expand Up @@ -159,6 +160,8 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet

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());
Comment thread
sathvikaragi marked this conversation as resolved.
Comment on lines 161 to +164

if (ProtocolType.ISCSI.name().equalsIgnoreCase(details.get(OntapStorageConstants.PROTOCOL))) {
String lunName = created != null && created.getLun() != null ? created.getLun().getName() : null;
Expand Down Expand Up @@ -1004,6 +1007,12 @@ private String buildSnapshotName(String cloudStackSnapshotName, long snapshotId)
}


private Storage.ImageFormat getImageFormatByHypervisor(HypervisorType hypervisorType) {
if (HypervisorType.KVM.equals(hypervisorType)) {
return Storage.ImageFormat.QCOW2;
}
throw new CloudRuntimeException("Unsupported hypervisor [" + hypervisorType + "] for ONTAP image format resolution");
}
/**
* Persists snapshot metadata in snapshot_details table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.storage.ScopeType;
import com.cloud.storage.Storage;
import com.cloud.storage.VolumeVO;
Expand Down Expand Up @@ -167,6 +168,7 @@ void testCreateAsync_VolumeWithISCSI_Success() {
when(storagePoolDao.findById(1L)).thenReturn(storagePool);
when(storagePool.getId()).thenReturn(1L);
when(storagePool.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.KVM);
Comment thread
sathvikaragi marked this conversation as resolved.

when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
when(volumeDao.findById(100L)).thenReturn(volumeVO);
Expand Down Expand Up @@ -202,6 +204,7 @@ void testCreateAsync_VolumeWithISCSI_Success() {

verify(volumeDetailsDao).addDetail(eq(100L), eq(OntapStorageConstants.LUN_DOT_UUID), eq("lun-uuid-123"), eq(false));
verify(volumeDetailsDao).addDetail(eq(100L), eq(OntapStorageConstants.LUN_DOT_NAME), eq("/vol/vol1/lun1"), eq(false));
verify(volumeVO).setFormat(Storage.ImageFormat.QCOW2);
verify(volumeDao).update(eq(100L), any(VolumeVO.class));
}
}
Expand All @@ -220,6 +223,7 @@ void testCreateAsync_VolumeWithNFS_Success() {
when(storagePoolDao.findById(1L)).thenReturn(storagePool);
when(storagePool.getId()).thenReturn(1L);
when(storagePool.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.KVM);
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
when(volumeDao.findById(100L)).thenReturn(volumeVO);
when(volumeVO.getId()).thenReturn(100L);
Expand All @@ -244,6 +248,7 @@ void testCreateAsync_VolumeWithNFS_Success() {
CreateCmdResult result = resultCaptor.getValue();
assertNotNull(result);
assertTrue(result.isSuccess());
verify(volumeVO).setFormat(Storage.ImageFormat.QCOW2);
verify(volumeDao).update(eq(100L), any(VolumeVO.class));
}
}
Expand Down
Loading