mirror of https://github.com/apache/cloudstack.git
test: enable and fix scaleio unit tests (#289)
Fixes #275 Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> (cherry picked from commit c82bc16a20527d5d07c323d5323bccd56fc604e0) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
5604638b84
commit
0d9aa70edd
|
|
@ -44,9 +44,6 @@
|
|||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
|||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ScaleIOGatewayClientImplTest {
|
||||
private final int port = 443;
|
||||
private final int port = 8443;
|
||||
private final int timeout = 30;
|
||||
private final int maxConnections = 50;
|
||||
private final String username = "admin";
|
||||
|
|
@ -70,7 +70,7 @@ public class ScaleIOGatewayClientImplTest {
|
|||
.withHeader("content-type", "application/json;charset=UTF-8")
|
||||
.withBody(sessionKey)));
|
||||
|
||||
client = new ScaleIOGatewayClientImpl("https://localhost/api", username, password, false, timeout, maxConnections);
|
||||
client = new ScaleIOGatewayClientImpl(String.format("https://localhost:%d/api", port), username, password, false, timeout, maxConnections);
|
||||
|
||||
wireMockRule.stubFor(post("/api/types/Volume/instances")
|
||||
.willReturn(aResponse()
|
||||
|
|
|
|||
|
|
@ -19,23 +19,13 @@
|
|||
|
||||
package org.apache.cloudstack.storage.datastore.driver;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.storage.MigrateVolumeAnswer;
|
||||
import com.cloud.agent.api.to.DataTO;
|
||||
import com.cloud.agent.api.to.DiskTO;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
|
|
@ -62,12 +52,23 @@ import org.powermock.api.mockito.PowerMockito;
|
|||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.storage.MigrateVolumeAnswer;
|
||||
import com.cloud.agent.api.to.DataTO;
|
||||
import com.cloud.agent.api.to.DiskTO;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.dao.VolumeDetailsDao;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(RemoteHostEndPoint.class)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
|
|
@ -40,13 +38,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManag
|
|||
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
|
||||
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
|
||||
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientImpl;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.datastore.provider.ScaleIOHostListener;
|
||||
import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil;
|
||||
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
|
||||
import org.junit.Before;
|
||||
|
|
@ -55,14 +51,14 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
|
|
@ -81,7 +77,7 @@ import com.cloud.storage.dao.StoragePoolHostDao;
|
|||
import com.cloud.template.TemplateManager;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@PrepareForTest(ScaleIOGatewayClient.class)
|
||||
@PrepareForTest(ScaleIOGatewayClientConnectionPool.class)
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class ScaleIOPrimaryDataStoreLifeCycleTest {
|
||||
|
||||
|
|
@ -114,20 +110,16 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
|
|||
@Mock
|
||||
ModifyStoragePoolAnswer answer;
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private StorageManager storageMgr = new StorageManagerImpl();
|
||||
|
||||
@Spy
|
||||
@InjectMocks
|
||||
private HypervisorHostListener hostListener = new ScaleIOHostListener();
|
||||
|
||||
@InjectMocks
|
||||
private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
initMocks(this);
|
||||
ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -135,9 +127,11 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
|
|||
final DataStore dataStore = mock(DataStore.class);
|
||||
when(dataStore.getId()).thenReturn(1L);
|
||||
|
||||
PowerMockito.mockStatic(ScaleIOGatewayClient.class);
|
||||
PowerMockito.mockStatic(ScaleIOGatewayClientConnectionPool.class);
|
||||
ScaleIOGatewayClientImpl client = mock(ScaleIOGatewayClientImpl.class);
|
||||
when(ScaleIOGatewayClientConnectionPool.getInstance().getClient(1L, storagePoolDetailsDao)).thenReturn(client);
|
||||
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
|
||||
when(pool.getClient(1L, storagePoolDetailsDao)).thenReturn(client);
|
||||
when(ScaleIOGatewayClientConnectionPool.getInstance()).thenAnswer((Answer<ScaleIOGatewayClientConnectionPool>) invocation -> pool);
|
||||
|
||||
when(client.haveConnectedSdcs()).thenReturn(true);
|
||||
|
||||
|
|
@ -157,28 +151,20 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
|
|||
|
||||
when(dataStoreMgr.getDataStore(anyLong(), eq(DataStoreRole.Primary))).thenReturn(store);
|
||||
when(store.getId()).thenReturn(1L);
|
||||
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.PowerFlex);
|
||||
when(store.isShared()).thenReturn(true);
|
||||
when(store.getName()).thenReturn("ScaleIOPool");
|
||||
when(store.getStorageProviderName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
|
||||
|
||||
when(dataStoreProviderMgr.getDataStoreProvider(ScaleIOUtil.PROVIDER_NAME)).thenReturn(dataStoreProvider);
|
||||
when(dataStoreProvider.getName()).thenReturn(ScaleIOUtil.PROVIDER_NAME);
|
||||
HypervisorHostListener hostListener = Mockito.mock(HypervisorHostListener.class);
|
||||
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
|
||||
storageMgr.registerHostListener(ScaleIOUtil.PROVIDER_NAME, hostListener);
|
||||
|
||||
when(agentMgr.easySend(anyLong(), Mockito.any(ModifyStoragePoolCommand.class))).thenReturn(answer);
|
||||
when(answer.getResult()).thenReturn(true);
|
||||
|
||||
when(storagePoolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(null);
|
||||
|
||||
when(hostDao.findById(1L)).thenReturn(host1);
|
||||
when(hostDao.findById(2L)).thenReturn(host2);
|
||||
|
||||
when(dataStoreHelper.attachZone(Mockito.any(DataStore.class))).thenReturn(null);
|
||||
|
||||
scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.KVM);
|
||||
verify(storageMgr,times(2)).connectHostToSharedPool(Mockito.any(Long.class), Mockito.any(Long.class));
|
||||
verify(storagePoolHostDao,times(2)).persist(Mockito.any(StoragePoolHostVO.class));
|
||||
boolean result = scaleIOPrimaryDataStoreLifeCycleTest.attachZone(dataStore, scope, Hypervisor.HypervisorType.KVM);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
|
|
@ -239,6 +225,9 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
|
|||
List<StoragePoolHostVO> poolHostVOs = new ArrayList<>();
|
||||
when(storagePoolHostDao.listByPoolId(anyLong())).thenReturn(poolHostVOs);
|
||||
when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
|
||||
PowerMockito.mockStatic(ScaleIOGatewayClientConnectionPool.class);
|
||||
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
|
||||
when(ScaleIOGatewayClientConnectionPool.getInstance()).thenAnswer((Answer<ScaleIOGatewayClientConnectionPool>) invocation -> pool);
|
||||
final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue