Skip to content

Commit 1f847c3

Browse files
Srivastava, PiyushSrivastava, Piyush
authored andcommitted
feature/CSTACKEX-251: Update UTs failure
1 parent d46dc8d commit 1f847c3

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
import javax.inject.Inject;
7878
import java.util.ArrayList;
79+
import java.util.Arrays;
7980
import java.util.HashMap;
8081
import java.util.List;
8182
import java.util.Map;
@@ -148,6 +149,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
148149
}
149150

150151
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
152+
validateProtocol(details, dataStore);
151153

152154
if (dataObject.getType() == DataObjectType.VOLUME) {
153155
VolumeInfo volInfo = (VolumeInfo) dataObject;
@@ -987,6 +989,20 @@ private String buildSnapshotName(String cloudStackSnapshotName, long snapshotId)
987989
return OntapStorageUtils.buildOntapSnapshotName(cloudStackSnapshotName, OntapStorageConstants.CS + snapshotId);
988990
}
989991

992+
/**
993+
* Only ISCSI and NFS3 pools can be provisioned; any other protocol would fall through
994+
* createAsync without producing a result, leaving the caller with a null callback value.
995+
*/
996+
private void validateProtocol(Map<String, String> details, DataStore dataStore) {
997+
String protocol = details == null ? null : details.get(OntapStorageConstants.PROTOCOL);
998+
boolean supported = protocol != null && Arrays.stream(ProtocolType.values())
999+
.anyMatch(type -> type.name().equalsIgnoreCase(protocol));
1000+
if (!supported) {
1001+
throw new CloudRuntimeException("Unsupported protocol [" + protocol + "] on storage pool ["
1002+
+ dataStore.getName() + "]; supported protocols are " + Arrays.toString(ProtocolType.values()));
1003+
}
1004+
}
1005+
9901006
private Storage.ImageFormat getImageFormat(StoragePoolVO storagePool) {
9911007
HypervisorType hypervisorType = storagePool.getHypervisor();
9921008
if (!HypervisorType.KVM.equals(hypervisorType)) {

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriverTest.java‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,17 @@ void testCreateAsync_KvmUnsupportedProtocol_FailsWithError() {
292292
when(dataStore.getId()).thenReturn(1L);
293293
when(dataStore.getName()).thenReturn("ontap-pool");
294294
when(volumeInfo.getType()).thenReturn(VOLUME);
295-
when(volumeInfo.getId()).thenReturn(100L);
296295
when(volumeInfo.getName()).thenReturn("test-volume");
297296

298297
when(storagePoolDao.findById(1L)).thenReturn(storagePool);
299-
when(storagePool.getId()).thenReturn(1L);
300-
when(storagePool.getHypervisor()).thenReturn(Hypervisor.HypervisorType.KVM);
301298
when(storagePoolDetailsDao.listDetailsKeyPairs(1L)).thenReturn(storagePoolDetails);
302-
when(volumeDao.findById(100L)).thenReturn(volumeVO);
303-
304-
try (MockedStatic<OntapStorageUtils> utilityMock = mockStatic(OntapStorageUtils.class)) {
305-
utilityMock.when(() -> OntapStorageUtils.getStrategyByStoragePoolDetails(any())).thenReturn(sanStrategy);
306299

307-
driver.createAsync(dataStore, volumeInfo, createCallback);
300+
driver.createAsync(dataStore, volumeInfo, createCallback);
308301

309-
ArgumentCaptor<CreateCmdResult> resultCaptor = ArgumentCaptor.forClass(CreateCmdResult.class);
310-
verify(createCallback).complete(resultCaptor.capture());
311-
assertFalse(resultCaptor.getValue().isSuccess());
312-
assertTrue(resultCaptor.getValue().getResult().contains("No enum constant"));
313-
}
302+
ArgumentCaptor<CreateCmdResult> resultCaptor = ArgumentCaptor.forClass(CreateCmdResult.class);
303+
verify(createCallback).complete(resultCaptor.capture());
304+
assertFalse(resultCaptor.getValue().isSuccess());
305+
assertTrue(resultCaptor.getValue().getResult().contains("Unsupported protocol [FC]"));
314306
}
315307

316308
@Test

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/lifecycle/OntapPrimaryDatastoreLifecycleTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private Map<String, Object> buildDsInfosForProtocol(String protocol) {
209209
dsInfos.put("clusterId", 1L);
210210
dsInfos.put("name", "testStoragePool");
211211
dsInfos.put("providerName", "testProvider");
212-
dsInfos.put("capacityBytes", 200000L);
212+
dsInfos.put("capacityBytes", 1073741824L);
213213
dsInfos.put("managed", true);
214214
dsInfos.put("tags", "testTag");
215215
dsInfos.put("isTagARule", false);

0 commit comments

Comments
 (0)