Skip to content

Commit c82bc16

Browse files
authored
test: enable and fix scaleio unit tests (apache#289)
Fixes apache#275 Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 4cceabe commit c82bc16

File tree

4 files changed

+41
-54
lines changed

4 files changed

+41
-54
lines changed

plugins/storage/volume/scaleio/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
<plugins>
4545
<plugin>
4646
<artifactId>maven-surefire-plugin</artifactId>
47-
<configuration>
48-
<skipTests>true</skipTests>
49-
</configuration>
5047
<executions>
5148
<execution>
5249
<phase>integration-test</phase>

plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
@RunWith(MockitoJUnitRunner.class)
5050
public class ScaleIOGatewayClientImplTest {
51-
private final int port = 443;
51+
private final int port = 8443;
5252
private final int timeout = 30;
5353
private final int maxConnections = 50;
5454
private final String username = "admin";
@@ -70,7 +70,7 @@ public void setUp() throws Exception {
7070
.withHeader("Content-Type", "application/json;charset=UTF-8")
7171
.withBody(sessionKey)));
7272

73-
client = new ScaleIOGatewayClientImpl("https://localhost/api", username, password, false, timeout, maxConnections);
73+
client = new ScaleIOGatewayClientImpl(String.format("https://localhost:%d/api", port), username, password, false, timeout, maxConnections);
7474

7575
wireMockRule.stubFor(post("/api/types/Volume/instances")
7676
.willReturn(aResponse()

plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,13 @@
1919

2020
package org.apache.cloudstack.storage.datastore.driver;
2121

22-
import com.cloud.agent.api.Answer;
23-
import com.cloud.agent.api.storage.MigrateVolumeAnswer;
24-
import com.cloud.agent.api.to.DataTO;
25-
import com.cloud.agent.api.to.DiskTO;
26-
import com.cloud.configuration.Config;
27-
import com.cloud.host.Host;
28-
import com.cloud.host.HostVO;
29-
import com.cloud.host.dao.HostDao;
30-
import com.cloud.storage.Storage;
31-
import com.cloud.storage.Volume;
32-
import com.cloud.storage.VolumeVO;
33-
import com.cloud.storage.dao.VolumeDao;
34-
import com.cloud.storage.dao.VolumeDetailsDao;
35-
import com.cloud.utils.exception.CloudRuntimeException;
36-
import com.cloud.vm.VMInstanceVO;
37-
import com.cloud.vm.VirtualMachine;
38-
import com.cloud.vm.dao.VMInstanceDao;
22+
import static org.mockito.ArgumentMatchers.any;
23+
import static org.mockito.Mockito.doNothing;
24+
import static org.mockito.Mockito.doReturn;
25+
import static org.mockito.Mockito.when;
26+
27+
import java.util.Optional;
28+
3929
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
4030
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
4131
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@@ -62,12 +52,23 @@
6252
import org.powermock.core.classloader.annotations.PrepareForTest;
6353
import org.powermock.modules.junit4.PowerMockRunner;
6454

65-
import java.util.Optional;
66-
67-
import static org.mockito.ArgumentMatchers.any;
68-
import static org.mockito.Mockito.doNothing;
69-
import static org.mockito.Mockito.doReturn;
70-
import static org.mockito.Mockito.when;
55+
import com.cloud.agent.api.Answer;
56+
import com.cloud.agent.api.storage.MigrateVolumeAnswer;
57+
import com.cloud.agent.api.to.DataTO;
58+
import com.cloud.agent.api.to.DiskTO;
59+
import com.cloud.configuration.Config;
60+
import com.cloud.host.Host;
61+
import com.cloud.host.HostVO;
62+
import com.cloud.host.dao.HostDao;
63+
import com.cloud.storage.Storage;
64+
import com.cloud.storage.Volume;
65+
import com.cloud.storage.VolumeVO;
66+
import com.cloud.storage.dao.VolumeDao;
67+
import com.cloud.storage.dao.VolumeDetailsDao;
68+
import com.cloud.utils.exception.CloudRuntimeException;
69+
import com.cloud.vm.VMInstanceVO;
70+
import com.cloud.vm.VirtualMachine;
71+
import com.cloud.vm.dao.VMInstanceDao;
7172

7273
@RunWith(PowerMockRunner.class)
7374
@PrepareForTest(RemoteHostEndPoint.class)

plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import static org.mockito.ArgumentMatchers.anyLong;
2525
import static org.mockito.ArgumentMatchers.eq;
2626
import static org.mockito.Mockito.mock;
27-
import static org.mockito.Mockito.times;
28-
import static org.mockito.Mockito.verify;
2927
import static org.mockito.Mockito.when;
3028
import static org.mockito.MockitoAnnotations.initMocks;
3129

@@ -40,13 +38,11 @@
4038
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
4139
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
4240
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
43-
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
4441
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
4542
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientImpl;
4643
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4744
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
4845
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
49-
import org.apache.cloudstack.storage.datastore.provider.ScaleIOHostListener;
5046
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
5147
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
5248
import org.junit.Before;
@@ -55,14 +51,14 @@
5551
import org.mockito.InjectMocks;
5652
import org.mockito.Mock;
5753
import org.mockito.Mockito;
58-
import org.mockito.Spy;
54+
import org.mockito.stubbing.Answer;
5955
import org.powermock.api.mockito.PowerMockito;
6056
import org.powermock.core.classloader.annotations.PrepareForTest;
6157
import org.powermock.modules.junit4.PowerMockRunner;
58+
import org.springframework.test.util.ReflectionTestUtils;
6259

6360
import com.cloud.agent.AgentManager;
6461
import com.cloud.agent.api.ModifyStoragePoolAnswer;
65-
import com.cloud.agent.api.ModifyStoragePoolCommand;
6662
import com.cloud.host.Host;
6763
import com.cloud.host.HostVO;
6864
import com.cloud.host.Status;
@@ -81,7 +77,7 @@
8177
import com.cloud.template.TemplateManager;
8278
import com.cloud.utils.exception.CloudRuntimeException;
8379

84-
@PrepareForTest(ScaleIOGatewayClient.class)
80+
@PrepareForTest(ScaleIOGatewayClientConnectionPool.class)
8581
@RunWith(PowerMockRunner.class)
8682
public class ScaleIOPrimaryDataStoreLifeCycleTest {
8783

@@ -114,30 +110,28 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
114110
@Mock
115111
ModifyStoragePoolAnswer answer;
116112

117-
@Spy
118113
@InjectMocks
119114
private StorageManager storageMgr = new StorageManagerImpl();
120115

121-
@Spy
122-
@InjectMocks
123-
private HypervisorHostListener hostListener = new ScaleIOHostListener();
124-
125116
@InjectMocks
126117
private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest;
127118

128119
@Before
129120
public void setUp() {
130121
initMocks(this);
122+
ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr);
131123
}
132124

133125
@Test
134126
public void testAttachZone() throws Exception {
135127
final DataStore dataStore = mock(DataStore.class);
136128
when(dataStore.getId()).thenReturn(1L);
137129

138-
PowerMockito.mockStatic(ScaleIOGatewayClient.class);
130+
PowerMockito.mockStatic(ScaleIOGatewayClientConnectionPool.class);
139131
ScaleIOGatewayClientImpl client = mock(ScaleIOGatewayClientImpl.class);
140-
when(ScaleIOGatewayClientConnectionPool.getInstance().getClient(1L, storagePoolDetailsDao)).thenReturn(client);
132+
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
133+
when(pool.getClient(1L, storagePoolDetailsDao)).thenReturn(client);
134+
when(ScaleIOGatewayClientConnectionPool.getInstance()).thenAnswer((Answer<ScaleIOGatewayClientConnectionPool>) invocation -> pool);
141135

142136
when(client.haveConnectedSdcs()).thenReturn(true);
143137

@@ -157,28 +151,20 @@ public void testAttachZone() throws Exception {
157151

158152
when(dataStoreMgr.getDataStore(anyLong(), eq(DataStoreRole.Primary))).thenReturn(store);
159153
when(store.getId()).thenReturn(1L);
160-
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.PowerFlex);
161154
when(store.isShared()).thenReturn(true);
162155
when(store.getName()).thenReturn("ScaleIOPool");
163156
when(store.getStorageProviderName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
164157

165158
when(dataStoreProviderMgr.getDataStoreProvider(ScaleIOUtil.PROVIDER_NAME)).thenReturn(dataStoreProvider);
166159
when(dataStoreProvider.getName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
160+
HypervisorHostListener hostListener = Mockito.mock(HypervisorHostListener.class);
161+
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
167162
storageMgr.registerHostListener(ScaleIOUtil.PROVIDER_NAME, hostListener);
168163

169-
when(agentMgr.easySend(anyLong(), Mockito.any(ModifyStoragePoolCommand.class))).thenReturn(answer);
170-
when(answer.getResult()).thenReturn(true);
171-
172-
when(storagePoolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(null);
173-
174-
when(hostDao.findById(1L)).thenReturn(host1);
175-
when(hostDao.findById(2L)).thenReturn(host2);
176-
177164
when(dataStoreHelper.attachZone(Mockito.any(DataStore.class))).thenReturn(null);
178165

179-
scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.KVM);
180-
verify(storageMgr,times(2)).connectHostToSharedPool(Mockito.any(Long.class), Mockito.any(Long.class));
181-
verify(storagePoolHostDao,times(2)).persist(Mockito.any(StoragePoolHostVO.class));
166+
boolean result = scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.KVM);
167+
assertThat(result).isTrue();
182168
}
183169

184170
@Test(expected = CloudRuntimeException.class)
@@ -239,6 +225,9 @@ public void testDeleteDataStore() {
239225
List<StoragePoolHostVO> poolHostVOs = new ArrayList<>();
240226
when(storagePoolHostDao.listByPoolId(anyLong())).thenReturn(poolHostVOs);
241227
when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
228+
PowerMockito.mockStatic(ScaleIOGatewayClientConnectionPool.class);
229+
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
230+
when(ScaleIOGatewayClientConnectionPool.getInstance()).thenAnswer((Answer<ScaleIOGatewayClientConnectionPool>) invocation -> pool);
242231
final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
243232
assertThat(result).isTrue();
244233
}

0 commit comments

Comments
 (0)