Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ protected Void managedCopyBaseImageCallback(AsyncCallbackDispatcher<VolumeServic
volume.setPath(templateObjectTo.getPath());

if (templateObjectTo.getFormat() != null) {
volume.setFormat(templateObjectTo.getFormat());
PrimaryDataStore primaryDataStore = context.getPrimaryDataStore();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of fetching the datastore from context use volume

boolean isOntap = primaryDataStore != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(primaryDataStore.getStorageProviderName());
if (!isOntap || volume.getFormat() == null) {
volume.setFormat(templateObjectTo.getFormat());
}
}

volDao.update(volume.getId(), volume);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +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());
volumeVO.setFormat(getImageFormatByHypervisorAndProtocol(storagePool.getHypervisor(), details.get(OntapStorageConstants.PROTOCOL)));
logger.info("createAsync: Volume format set to [{}] for hypervisor [{}] and protocol [{}]", volumeVO.getFormat(), storagePool.getHypervisor(), details.get(OntapStorageConstants.PROTOCOL));

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


private Storage.ImageFormat getImageFormatByHypervisor(HypervisorType hypervisorType) {
private Storage.ImageFormat getImageFormatByHypervisorAndProtocol(HypervisorType hypervisorType, String protocol) {
if (HypervisorType.KVM.equals(hypervisorType)) {
Comment thread
sathvikaragi marked this conversation as resolved.
return Storage.ImageFormat.QCOW2;
ProtocolType protocolType = ProtocolType.valueOf(protocol);
switch (protocolType) {
case NFS3:
return Storage.ImageFormat.QCOW2;
case ISCSI:
return Storage.ImageFormat.RAW;
default:
throw new CloudRuntimeException("Unsupported protocol [" + protocol + "] for ONTAP image format resolution");
}
}
throw new CloudRuntimeException("Unsupported hypervisor [" + hypervisorType + "] for ONTAP image format resolution");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.feign.model.Igroup;
import org.apache.cloudstack.storage.feign.model.Lun;
import org.apache.cloudstack.storage.service.UnifiedNASStrategy;
import org.apache.cloudstack.storage.service.UnifiedSANStrategy;
import org.apache.cloudstack.storage.service.model.AccessGroup;
import org.apache.cloudstack.storage.service.model.CloudStackVolume;
Expand Down Expand Up @@ -108,6 +109,9 @@ class OntapPrimaryDatastoreDriverTest {
@Mock
private UnifiedSANStrategy sanStrategy;

@Mock
private UnifiedNASStrategy nasStrategy;

@Mock
private AsyncCompletionCallback<CreateCmdResult> createCallback;

Expand Down Expand Up @@ -167,7 +171,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.getPoolType()).thenReturn(Storage.StoragePoolType.Iscsi);
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.KVM);

when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
Expand Down Expand Up @@ -204,7 +208,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(volumeVO).setFormat(Storage.ImageFormat.RAW);
verify(volumeDao).update(eq(100L), any(VolumeVO.class));
}
}
Expand Down Expand Up @@ -232,11 +236,11 @@ void testCreateAsync_VolumeWithNFS_Success() {

try (MockedStatic<OntapStorageUtils> utilityMock = mockStatic(OntapStorageUtils.class)) {
utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(storagePoolDetails))
.thenReturn(sanStrategy);
.thenReturn(nasStrategy);
utilityMock.when(() -> OntapStorageUtils.createCloudStackVolumeRequestByProtocol(
any(), any(), any())).thenReturn(mockCloudStackVolume);

when(sanStrategy.createCloudStackVolume(any())).thenReturn(mockCloudStackVolume);
when(nasStrategy.createCloudStackVolume(any())).thenReturn(mockCloudStackVolume);

// Execute
driver.createAsync(dataStore, volumeInfo, createCallback);
Expand All @@ -253,6 +257,62 @@ void testCreateAsync_VolumeWithNFS_Success() {
}
}

@Test
void testCreateAsync_UnsupportedHypervisor_FailsWithError() {
storagePoolDetails.put(OntapStorageConstants.PROTOCOL, ProtocolType.ISCSI.name());

when(dataStore.getId()).thenReturn(1L);
when(dataStore.getName()).thenReturn("ontap-pool");
when(volumeInfo.getType()).thenReturn(VOLUME);
when(volumeInfo.getId()).thenReturn(100L);
when(volumeInfo.getName()).thenReturn("test-volume");

when(storagePoolDao.findById(1L)).thenReturn(storagePool);
when(storagePool.getId()).thenReturn(1L);
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.VMware);
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
when(volumeDao.findById(100L)).thenReturn(volumeVO);

try (MockedStatic<OntapStorageUtils> utilityMock = mockStatic(OntapStorageUtils.class)) {
utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(any())).thenReturn(sanStrategy);

driver.createAsync(dataStore, volumeInfo, createCallback);

ArgumentCaptor<CreateCmdResult> resultCaptor = ArgumentCaptor.forClass(CreateCmdResult.class);
verify(createCallback).complete(resultCaptor.capture());
assertFalse(resultCaptor.getValue().isSuccess());
assertTrue(resultCaptor.getValue().getResult().contains("Unsupported hypervisor [VMware]"));
}
}

@Test
void testCreateAsync_KvmUnsupportedProtocol_FailsWithError() {
storagePoolDetails.put(OntapStorageConstants.PROTOCOL, "FC");

when(dataStore.getId()).thenReturn(1L);
when(dataStore.getName()).thenReturn("ontap-pool");
when(volumeInfo.getType()).thenReturn(VOLUME);
when(volumeInfo.getId()).thenReturn(100L);
when(volumeInfo.getName()).thenReturn("test-volume");

when(storagePoolDao.findById(1L)).thenReturn(storagePool);
when(storagePool.getId()).thenReturn(1L);
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.KVM);
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
when(volumeDao.findById(100L)).thenReturn(volumeVO);

try (MockedStatic<OntapStorageUtils> utilityMock = mockStatic(OntapStorageUtils.class)) {
utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(any())).thenReturn(sanStrategy);

driver.createAsync(dataStore, volumeInfo, createCallback);

ArgumentCaptor<CreateCmdResult> resultCaptor = ArgumentCaptor.forClass(CreateCmdResult.class);
verify(createCallback).complete(resultCaptor.capture());
assertFalse(resultCaptor.getValue().isSuccess());
assertTrue(resultCaptor.getValue().getResult().contains("No enum constant"));
}
}

@Test
void testDeleteAsync_NullStore_ThrowsException() {
ArgumentCaptor<CommandResult> resultCaptor = ArgumentCaptor.forClass(CommandResult.class);
Expand Down
Loading