Skip to content

Commit 27b0a64

Browse files
Fix scaleio tests (#7622)
Co-authored-by: Wei Zhou <weizhou@apache.org>
1 parent 5fa9b8f commit 27b0a64

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
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/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
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;
27+
import static org.mockito.Mockito.mockStatic;
2928
import static org.mockito.Mockito.when;
3029
import static org.mockito.MockitoAnnotations.initMocks;
3130

@@ -40,33 +39,26 @@
4039
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
4140
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
4241
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
43-
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
4442
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
4543
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientImpl;
4644
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4745
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
4846
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
49-
import org.apache.cloudstack.storage.datastore.provider.ScaleIOHostListener;
5047
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
5148
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
5249
import org.junit.Before;
5350
import org.junit.Test;
5451
import org.junit.runner.RunWith;
5552
import org.mockito.InjectMocks;
5653
import org.mockito.Mock;
54+
import org.mockito.MockedStatic;
5755
import org.mockito.Mockito;
5856
import org.mockito.Spy;
59-
import org.powermock.api.mockito.PowerMockito;
60-
import org.powermock.core.classloader.annotations.PrepareForTest;
61-
import org.powermock.modules.junit4.PowerMockRunner;
57+
import org.mockito.junit.MockitoJUnitRunner;
6258

63-
import com.cloud.agent.AgentManager;
64-
import com.cloud.agent.api.ModifyStoragePoolAnswer;
65-
import com.cloud.agent.api.ModifyStoragePoolCommand;
6659
import com.cloud.host.Host;
6760
import com.cloud.host.HostVO;
6861
import com.cloud.host.Status;
69-
import com.cloud.host.dao.HostDao;
7062
import com.cloud.hypervisor.Hypervisor;
7163
import com.cloud.resource.ResourceManager;
7264
import com.cloud.resource.ResourceState;
@@ -80,9 +72,9 @@
8072
import com.cloud.storage.dao.StoragePoolHostDao;
8173
import com.cloud.template.TemplateManager;
8274
import com.cloud.utils.exception.CloudRuntimeException;
75+
import org.springframework.test.util.ReflectionTestUtils;
8376

84-
@PrepareForTest(ScaleIOGatewayClient.class)
85-
@RunWith(PowerMockRunner.class)
77+
@RunWith(MockitoJUnitRunner.class)
8678
public class ScaleIOPrimaryDataStoreLifeCycleTest {
8779

8880
@Mock
@@ -96,8 +88,6 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
9688
@Mock
9789
private StoragePoolAutomation storagePoolAutomation;
9890
@Mock
99-
private HostDao hostDao;
100-
@Mock
10191
private StoragePoolHostDao storagePoolHostDao;
10292
@Mock
10393
private DataStoreProviderManager dataStoreProviderMgr;
@@ -109,35 +99,32 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
10999
private PrimaryDataStore store;
110100
@Mock
111101
private TemplateManager templateMgr;
112-
@Mock
113-
private AgentManager agentMgr;
114-
@Mock
115-
ModifyStoragePoolAnswer answer;
116102

117-
@Spy
118103
@InjectMocks
119104
private StorageManager storageMgr = new StorageManagerImpl();
120105

121106
@Spy
122-
@InjectMocks
123-
private HypervisorHostListener hostListener = new ScaleIOHostListener();
107+
private HypervisorHostListener hostListener;
124108

125109
@InjectMocks
126110
private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest;
127111

128112
@Before
129113
public void setUp() {
130114
initMocks(this);
115+
ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr);
131116
}
132117

133118
@Test
134119
public void testAttachZone() throws Exception {
135120
final DataStore dataStore = mock(DataStore.class);
136121
when(dataStore.getId()).thenReturn(1L);
137122

138-
PowerMockito.mockStatic(ScaleIOGatewayClient.class);
123+
MockedStatic<ScaleIOGatewayClientConnectionPool> scaleIOGatewayClientConnectionPoolMocked = mockStatic(ScaleIOGatewayClientConnectionPool.class);
139124
ScaleIOGatewayClientImpl client = mock(ScaleIOGatewayClientImpl.class);
140-
when(ScaleIOGatewayClientConnectionPool.getInstance().getClient(1L, storagePoolDetailsDao)).thenReturn(client);
125+
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
126+
scaleIOGatewayClientConnectionPoolMocked.when(() -> ScaleIOGatewayClientConnectionPool.getInstance()).thenReturn(pool);
127+
when(pool.getClient(1L, storagePoolDetailsDao)).thenReturn(client);
141128

142129
when(client.haveConnectedSdcs()).thenReturn(true);
143130

@@ -157,28 +144,19 @@ public void testAttachZone() throws Exception {
157144

158145
when(dataStoreMgr.getDataStore(anyLong(), eq(DataStoreRole.Primary))).thenReturn(store);
159146
when(store.getId()).thenReturn(1L);
160-
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.PowerFlex);
161147
when(store.isShared()).thenReturn(true);
162148
when(store.getName()).thenReturn("ScaleIOPool");
163149
when(store.getStorageProviderName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
164150

165151
when(dataStoreProviderMgr.getDataStoreProvider(ScaleIOUtil.PROVIDER_NAME)).thenReturn(dataStoreProvider);
166152
when(dataStoreProvider.getName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
153+
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
167154
storageMgr.registerHostListener(ScaleIOUtil.PROVIDER_NAME, hostListener);
168155

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-
177156
when(dataStoreHelper.attachZone(Mockito.any(DataStore.class))).thenReturn(null);
178157

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));
158+
boolean result = scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.KVM);
159+
assertThat(result).isTrue();
182160
}
183161

184162
@Test(expected = CloudRuntimeException.class)
@@ -224,7 +202,6 @@ public void testDisableStoragePool() {
224202
public void testDeleteDataStoreWithStoragePoolNull() {
225203
final PrimaryDataStore store = mock(PrimaryDataStore.class);
226204
when(primaryDataStoreDao.findById(anyLong())).thenReturn(null);
227-
when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
228205
final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
229206
assertThat(result).isFalse();
230207
}
@@ -233,6 +210,7 @@ public void testDeleteDataStoreWithStoragePoolNull() {
233210
public void testDeleteDataStore() {
234211
final PrimaryDataStore store = mock(PrimaryDataStore.class);
235212
final StoragePoolVO storagePoolVO = mock(StoragePoolVO.class);
213+
when(store.getId()).thenReturn(1L);
236214
when(primaryDataStoreDao.findById(anyLong())).thenReturn(storagePoolVO);
237215
List<VMTemplateStoragePoolVO> unusedTemplates = new ArrayList<>();
238216
when(templateMgr.getUnusedTemplatesInPool(storagePoolVO)).thenReturn(unusedTemplates);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-maker-inline

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@
10621062
<exclude>ui/public/**</exclude>
10631063
<exclude>ui/legacy/**</exclude>
10641064
<exclude>utils/testsmallfileinactive</exclude>
1065-
<exclude>utils/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker</exclude>
1065+
<exclude>**/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker</exclude>
10661066
</excludes>
10671067
</configuration>
10681068
</plugin>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mock-maker-inline
1+
mock-maker-inline

0 commit comments

Comments
 (0)