Skip to content

Commit ee12d80

Browse files
Update ONTAP UTs for chooseAggregate/LIF-before-volume create signatures.
Align StorageStrategy and lifecycle tests with the Aggregate-based APIs and assert volume create is skipped when LIF selection fails. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3dce185 commit ee12d80

2 files changed

Lines changed: 196 additions & 129 deletions

File tree

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.mockito.junit.jupiter.MockitoExtension;
3131
import org.mockito.junit.jupiter.MockitoSettings;
3232
import org.mockito.quality.Strictness;
33+
import org.apache.cloudstack.storage.feign.model.Aggregate;
3334
import org.apache.cloudstack.storage.feign.model.Volume;
3435
import com.cloud.dc.dao.ClusterDao;
3536
import com.cloud.utils.exception.CloudRuntimeException;
@@ -55,7 +56,10 @@
5556
import static org.mockito.Mockito.when;
5657
import static org.mockito.Mockito.verify;
5758
import static org.mockito.Mockito.times;
59+
import static org.mockito.Mockito.never;
60+
import static org.mockito.Mockito.inOrder;
5861
import static org.mockito.Mockito.withSettings;
62+
import org.mockito.InOrder;
5963
import static org.mockito.ArgumentMatchers.contains;
6064
import static org.junit.jupiter.api.Assertions.assertThrows;
6165
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -122,12 +126,19 @@ void setUp() {
122126
when(_clusterDao.findById(1L)).thenReturn(clusterVO);
123127

124128
when(storageStrategy.connect()).thenReturn(true);
125-
when(storageStrategy.getNetworkInterface()).thenReturn(new Pair<>("testNetworkInterface", null));
129+
Aggregate aggregate = new Aggregate();
130+
aggregate.setName("aggr1");
131+
aggregate.setUuid("aggr-uuid-1");
132+
Aggregate.Node node = new Aggregate.Node();
133+
node.setName("node-a");
134+
aggregate.setNode(node);
135+
when(storageStrategy.chooseAggregate(any())).thenReturn(aggregate);
136+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("testNetworkInterface", null));
126137

127138
Volume volume = new Volume();
128139
volume.setUuid("test-volume-uuid");
129140
volume.setName("testVolume");
130-
when(storageStrategy.createStorageVolume(any(), any())).thenReturn(volume);
141+
when(storageStrategy.createStorageVolume(any(), any(), any())).thenReturn(volume);
131142

132143
// Setup for attachCluster tests
133144
// Configure dataStore mock with necessary methods (works for both DataStore and PrimaryDataStoreInfo)
@@ -435,7 +446,7 @@ public void testInitialize_dataLifWithWarning() {
435446
dsInfos.put("details", detailsMap);
436447

437448
String warningMessage = "LIF on node-b; expected on node-a;Details about LIF failover";
438-
when(storageStrategy.getNetworkInterface()).thenReturn(new Pair<>("10.0.0.1", warningMessage));
449+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("10.0.0.1", warningMessage));
439450

440451
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class);
441452
MockedStatic<OntapStorageUtils> utilityMock = Mockito.mockStatic(OntapStorageUtils.class)) {
@@ -470,12 +481,13 @@ public void testInitialize_nullDataLif() {
470481
dsInfos.put("isTagARule", false);
471482
dsInfos.put("details", detailsMap);
472483

473-
when(storageStrategy.getNetworkInterface()).thenReturn(new Pair<>(null, null));
484+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>(null, null));
474485

475486
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
476487
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
477488
Exception ex = assertThrows(CloudRuntimeException.class, () -> ontapPrimaryDatastoreLifecycle.initialize(dsInfos));
478489
assertTrue(ex.getMessage().contains("Failed to retrieve Data LIF from ONTAP, cannot create primary storage"));
490+
verify(storageStrategy, never()).createStorageVolume(any(), any(), any());
479491
}
480492
}
481493

@@ -501,12 +513,13 @@ public void testInitialize_emptyDataLif() {
501513
dsInfos.put("isTagARule", false);
502514
dsInfos.put("details", detailsMap);
503515

504-
when(storageStrategy.getNetworkInterface()).thenReturn(new Pair<>("", null));
516+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("", null));
505517

506518
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
507519
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
508520
Exception ex = assertThrows(CloudRuntimeException.class, () -> ontapPrimaryDatastoreLifecycle.initialize(dsInfos));
509521
assertTrue(ex.getMessage().contains("Failed to retrieve Data LIF from ONTAP, cannot create primary storage"));
522+
verify(storageStrategy, never()).createStorageVolume(any(), any(), any());
510523
}
511524
}
512525

@@ -532,13 +545,14 @@ public void testInitialize_getNetworkInterfaceException() {
532545
dsInfos.put("isTagARule", false);
533546
dsInfos.put("details", detailsMap);
534547

535-
when(storageStrategy.getNetworkInterface()).thenThrow(new RuntimeException("ONTAP API error"));
548+
when(storageStrategy.getNetworkInterface(any())).thenThrow(new RuntimeException("ONTAP API error"));
536549

537550
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
538551
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
539552
Exception ex = assertThrows(CloudRuntimeException.class, () -> ontapPrimaryDatastoreLifecycle.initialize(dsInfos));
540553
assertTrue(ex.getMessage().contains("Failed to retrieve Data LIF from ONTAP"));
541554
assertTrue(ex.getCause() != null && ex.getCause().getMessage().contains("ONTAP API error"));
555+
verify(storageStrategy, never()).createStorageVolume(any(), any(), any());
542556
}
543557
}
544558

@@ -564,7 +578,7 @@ public void testInitialize_volumeCreationFailure_nullVolume() {
564578
dsInfos.put("isTagARule", false);
565579
dsInfos.put("details", detailsMap);
566580

567-
when(storageStrategy.createStorageVolume(any(), any())).thenReturn(null);
581+
when(storageStrategy.createStorageVolume(any(), any(), any())).thenReturn(null);
568582

569583
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
570584
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
@@ -595,7 +609,7 @@ public void testInitialize_volumeCreationException() {
595609
dsInfos.put("isTagARule", false);
596610
dsInfos.put("details", detailsMap);
597611

598-
when(storageStrategy.createStorageVolume(any(), any())).thenThrow(new RuntimeException("Volume creation failed"));
612+
when(storageStrategy.createStorageVolume(any(), any(), any())).thenThrow(new RuntimeException("Volume creation failed"));
599613

600614
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
601615
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
@@ -628,13 +642,19 @@ public void testInitialize_positiveWithDetailAssertions() {
628642
dsInfos.put("details", detailsMap);
629643

630644
String expectedDataLif = "192.168.1.100";
631-
when(storageStrategy.getNetworkInterface()).thenReturn(new Pair<>(expectedDataLif, null));
645+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>(expectedDataLif, null));
632646
when(storageStrategy.getStoragePath()).thenReturn("/vol/testVolume");
633647

634648
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
635649
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
636650
ontapPrimaryDatastoreLifecycle.initialize(dsInfos);
637651

652+
// Verify LIF selection completes before FlexVol creation
653+
InOrder inOrder = inOrder(storageStrategy);
654+
inOrder.verify(storageStrategy).chooseAggregate(any());
655+
inOrder.verify(storageStrategy).getNetworkInterface(any());
656+
inOrder.verify(storageStrategy).createStorageVolume(any(), any(), any());
657+
638658
// Verify that createPrimaryDataStore was called and host parameter contains the DATA_LIF
639659
verify(_dataStoreHelper, times(1)).createPrimaryDataStore(any());
640660
}

0 commit comments

Comments
 (0)