Skip to content

Commit 2adc88c

Browse files
Committed missed test files
1 parent fe6074b commit 2adc88c

2 files changed

Lines changed: 38 additions & 31 deletions

File tree

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import java.util.Map;
5454
import java.util.List;
5555
import java.util.ArrayList;
56-
import com.cloud.utils.Pair;
56+
import java.util.HashMap;
5757
import static org.mockito.ArgumentMatchers.any;
5858
import static org.mockito.ArgumentMatchers.anyLong;
5959
import static org.mockito.ArgumentMatchers.eq;
@@ -142,7 +142,8 @@ void setUp() {
142142
node.setName("node-a");
143143
aggregate.setNode(node);
144144
when(storageStrategy.chooseAggregate(any())).thenReturn(aggregate);
145-
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("testNetworkInterface", null));
145+
when(storageStrategy.getNetworkInterface(any())).thenReturn(
146+
Map.of(OntapStorageConstants.DATA_LIF, "testNetworkInterface"));
146147

147148
Volume volume = new Volume();
148149
volume.setUuid("test-volume-uuid");
@@ -507,7 +508,7 @@ public void testInitialize_unexpectedDetailKey() {
507508

508509
@Test
509510
public void testInitialize_dataLifWithWarning() {
510-
// Test when getNetworkInterface returns a warning in the Pair's second value
511+
// Test when getNetworkInterface returns a warning in LIF_WARNING
511512
// This exercises the processDataLifSelection path for non-null warning
512513
HashMap<String, String> detailsMap = new HashMap<>();
513514
detailsMap.put(OntapStorageConstants.USERNAME, "testUser");
@@ -529,7 +530,9 @@ public void testInitialize_dataLifWithWarning() {
529530
dsInfos.put("details", detailsMap);
530531

531532
String warningMessage = "LIF on node-b; expected on node-a;Details about LIF failover";
532-
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("10.0.0.1", warningMessage));
533+
when(storageStrategy.getNetworkInterface(any())).thenReturn(Map.of(
534+
OntapStorageConstants.DATA_LIF, "10.0.0.1",
535+
OntapStorageConstants.LIF_WARNING, warningMessage));
533536

534537
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class);
535538
MockedStatic<OntapStorageUtils> utilityMock = Mockito.mockStatic(OntapStorageUtils.class)) {
@@ -544,7 +547,7 @@ public void testInitialize_dataLifWithWarning() {
544547

545548
@Test
546549
public void testInitialize_nullDataLif() {
547-
// Test when lifResult.first() returns null
550+
// Test when DATA_LIF is missing from the result map
548551
HashMap<String, String> detailsMap = new HashMap<>();
549552
detailsMap.put(OntapStorageConstants.USERNAME, "testUser");
550553
detailsMap.put(OntapStorageConstants.PASSWORD, "testPassword");
@@ -564,7 +567,7 @@ public void testInitialize_nullDataLif() {
564567
dsInfos.put("isTagARule", false);
565568
dsInfos.put("details", detailsMap);
566569

567-
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>(null, null));
570+
when(storageStrategy.getNetworkInterface(any())).thenReturn(new HashMap<>());
568571

569572
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
570573
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
@@ -576,7 +579,7 @@ public void testInitialize_nullDataLif() {
576579

577580
@Test
578581
public void testInitialize_emptyDataLif() {
579-
// Test when lifResult.first() returns empty string
582+
// Test when DATA_LIF is an empty string
580583
HashMap<String, String> detailsMap = new HashMap<>();
581584
detailsMap.put(OntapStorageConstants.USERNAME, "testUser");
582585
detailsMap.put(OntapStorageConstants.PASSWORD, "testPassword");
@@ -596,7 +599,8 @@ public void testInitialize_emptyDataLif() {
596599
dsInfos.put("isTagARule", false);
597600
dsInfos.put("details", detailsMap);
598601

599-
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>("", null));
602+
when(storageStrategy.getNetworkInterface(any())).thenReturn(
603+
Map.of(OntapStorageConstants.DATA_LIF, ""));
600604

601605
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {
602606
storageProviderFactory.when(() -> StorageProviderFactory.getStrategy(any())).thenReturn(storageStrategy);
@@ -725,7 +729,8 @@ public void testInitialize_positiveWithDetailAssertions() {
725729
dsInfos.put("details", detailsMap);
726730

727731
String expectedDataLif = "192.168.1.100";
728-
when(storageStrategy.getNetworkInterface(any())).thenReturn(new Pair<>(expectedDataLif, null));
732+
when(storageStrategy.getNetworkInterface(any())).thenReturn(
733+
Map.of(OntapStorageConstants.DATA_LIF, expectedDataLif));
729734
when(storageStrategy.getStoragePath()).thenReturn("/vol/testVolume");
730735

731736
try (MockedStatic<StorageProviderFactory> storageProviderFactory = Mockito.mockStatic(StorageProviderFactory.class)) {

‎plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/service/StorageStrategyTest.java‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import org.mockito.junit.jupiter.MockitoSettings;
7373
import org.mockito.quality.Strictness;
7474

75-
import com.cloud.utils.Pair;
7675
import com.cloud.utils.exception.CloudRuntimeException;
7776

7877
import feign.FeignException;
@@ -966,12 +965,13 @@ public void testGetNetworkInterface_nfs() {
966965
.thenReturn(interfaceResponse);
967966

968967
// Execute
969-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
968+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
970969

971970
// Verify
972971
assertNotNull(result);
973-
assertEquals("192.168.1.50", result.first());
974-
assertTrue(result.second() == null, "Expect no warning when a suitable LIF is found");
972+
assertEquals("192.168.1.50", result.get(OntapStorageConstants.DATA_LIF));
973+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) == null,
974+
"Expect no warning when a suitable LIF is found");
975975
verify(networkFeignClient, times(1)).getNetworkIpInterfaces(anyString(), anyMap());
976976
}
977977

@@ -1008,12 +1008,13 @@ public void testGetNetworkInterface_iscsi() {
10081008
.thenReturn(interfaceResponse);
10091009

10101010
// Execute
1011-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
1011+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
10121012

10131013
// Verify
10141014
assertNotNull(result);
1015-
assertEquals("192.168.1.51", result.first());
1016-
assertTrue(result.second() == null, "Expect no warning when a suitable LIF is found");
1015+
assertEquals("192.168.1.51", result.get(OntapStorageConstants.DATA_LIF));
1016+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) == null,
1017+
"Expect no warning when a suitable LIF is found");
10171018
}
10181019

10191020
@Test
@@ -1141,10 +1142,10 @@ public void testGetNetworkInterface_nfs_tier1_homeNodeMatch() {
11411142
when(networkFeignClient.getNetworkIpInterfaces(anyString(), anyMap()))
11421143
.thenReturn(wrapLifs(List.of(lif)));
11431144

1144-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
1145+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
11451146

1146-
assertEquals("10.0.0.1", result.first());
1147-
assertTrue(result.second() == null, "Tier 1 should produce no warning");
1147+
assertEquals("10.0.0.1", result.get(OntapStorageConstants.DATA_LIF));
1148+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) == null, "Tier 1 should produce no warning");
11481149
}
11491150

11501151
/**
@@ -1160,11 +1161,11 @@ public void testGetNetworkInterface_nfs_tier2_currentNodeMatch() {
11601161
when(networkFeignClient.getNetworkIpInterfaces(anyString(), anyMap()))
11611162
.thenReturn(wrapLifs(List.of(lif)));
11621163

1163-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
1164+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
11641165

1165-
assertEquals("10.0.0.2", result.first());
1166-
assertTrue(result.second() != null, "Tier 2 should produce a warning");
1167-
assertTrue(result.second().contains("node-a"));
1166+
assertEquals("10.0.0.2", result.get(OntapStorageConstants.DATA_LIF));
1167+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) != null, "Tier 2 should produce a warning");
1168+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING).contains("node-a"));
11681169
}
11691170

11701171
/**
@@ -1181,13 +1182,13 @@ public void testGetNetworkInterface_nfs_tier3_crossNodeFallback() {
11811182
when(networkFeignClient.getNetworkIpInterfaces(anyString(), anyMap()))
11821183
.thenReturn(wrapLifs(List.of(lif)));
11831184

1184-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
1185+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
11851186

1186-
assertEquals("10.0.0.3", result.first());
1187-
assertTrue(result.second() != null, "Tier 3 fallback should produce a warning");
1188-
assertTrue(result.second().contains("node-a"),
1187+
assertEquals("10.0.0.3", result.get(OntapStorageConstants.DATA_LIF));
1188+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) != null, "Tier 3 fallback should produce a warning");
1189+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING).contains("node-a"),
11891190
"Warning should mention the expected node");
1190-
assertTrue(result.second().contains("10.0.0.3"),
1191+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING).contains("10.0.0.3"),
11911192
"Warning should mention the fallback LIF IP");
11921193
}
11931194

@@ -1225,10 +1226,11 @@ public void testGetNetworkInterface_nfs_tier1Down_tier2Used() {
12251226
when(networkFeignClient.getNetworkIpInterfaces(anyString(), anyMap()))
12261227
.thenReturn(wrapLifs(List.of(lifDown, lifFailover)));
12271228

1228-
Pair<String, String> result = storageStrategy.getNetworkInterface(aggregate);
1229+
Map<String, String> result = storageStrategy.getNetworkInterface(aggregate);
12291230

1230-
assertEquals("10.0.0.6", result.first());
1231-
assertTrue(result.second() != null, "Should warn that the home-node LIF is not in use");
1231+
assertEquals("10.0.0.6", result.get(OntapStorageConstants.DATA_LIF));
1232+
assertTrue(result.get(OntapStorageConstants.LIF_WARNING) != null,
1233+
"Should warn that the home-node LIF is not in use");
12321234
}
12331235

12341236
// ========== Helper Methods ==========

0 commit comments

Comments
 (0)