Fix scaleio tests (#7622)

Co-authored-by: Wei Zhou <weizhou@apache.org>
This commit is contained in:
Vishesh 2023-06-15 15:23:10 +05:30 committed by GitHub
parent 5fa9b8f683
commit 27b0a64b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 44 deletions

View File

@ -44,9 +44,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>

View File

@ -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()

View File

@ -24,8 +24,7 @@ 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.mockStatic;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@ -40,13 +39,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;
@ -54,19 +51,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
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;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
@ -80,9 +72,9 @@ import com.cloud.storage.VMTemplateStoragePoolVO;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.template.TemplateManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.springframework.test.util.ReflectionTestUtils;
@PrepareForTest(ScaleIOGatewayClient.class)
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class ScaleIOPrimaryDataStoreLifeCycleTest {
@Mock
@ -96,8 +88,6 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
@Mock
private StoragePoolAutomation storagePoolAutomation;
@Mock
private HostDao hostDao;
@Mock
private StoragePoolHostDao storagePoolHostDao;
@Mock
private DataStoreProviderManager dataStoreProviderMgr;
@ -109,18 +99,12 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
private PrimaryDataStore store;
@Mock
private TemplateManager templateMgr;
@Mock
private AgentManager agentMgr;
@Mock
ModifyStoragePoolAnswer answer;
@Spy
@InjectMocks
private StorageManager storageMgr = new StorageManagerImpl();
@Spy
@InjectMocks
private HypervisorHostListener hostListener = new ScaleIOHostListener();
private HypervisorHostListener hostListener;
@InjectMocks
private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest;
@ -128,6 +112,7 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
@Before
public void setUp() {
initMocks(this);
ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr);
}
@Test
@ -135,9 +120,11 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
final DataStore dataStore = mock(DataStore.class);
when(dataStore.getId()).thenReturn(1L);
PowerMockito.mockStatic(ScaleIOGatewayClient.class);
MockedStatic<ScaleIOGatewayClientConnectionPool> scaleIOGatewayClientConnectionPoolMocked = mockStatic(ScaleIOGatewayClientConnectionPool.class);
ScaleIOGatewayClientImpl client = mock(ScaleIOGatewayClientImpl.class);
when(ScaleIOGatewayClientConnectionPool.getInstance().getClient(1L, storagePoolDetailsDao)).thenReturn(client);
ScaleIOGatewayClientConnectionPool pool = mock(ScaleIOGatewayClientConnectionPool.class);
scaleIOGatewayClientConnectionPoolMocked.when(() -> ScaleIOGatewayClientConnectionPool.getInstance()).thenReturn(pool);
when(pool.getClient(1L, storagePoolDetailsDao)).thenReturn(client);
when(client.haveConnectedSdcs()).thenReturn(true);
@ -157,28 +144,19 @@ 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);
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)
@ -224,7 +202,6 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
public void testDeleteDataStoreWithStoragePoolNull() {
final PrimaryDataStore store = mock(PrimaryDataStore.class);
when(primaryDataStoreDao.findById(anyLong())).thenReturn(null);
when(dataStoreHelper.deletePrimaryDataStore(any(DataStore.class))).thenReturn(true);
final boolean result = scaleIOPrimaryDataStoreLifeCycleTest.deleteDataStore(store);
assertThat(result).isFalse();
}
@ -233,6 +210,7 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
public void testDeleteDataStore() {
final PrimaryDataStore store = mock(PrimaryDataStore.class);
final StoragePoolVO storagePoolVO = mock(StoragePoolVO.class);
when(store.getId()).thenReturn(1L);
when(primaryDataStoreDao.findById(anyLong())).thenReturn(storagePoolVO);
List<VMTemplateStoragePoolVO> unusedTemplates = new ArrayList<>();
when(templateMgr.getUnusedTemplatesInPool(storagePoolVO)).thenReturn(unusedTemplates);

View File

@ -1062,7 +1062,7 @@
<exclude>ui/public/**</exclude>
<exclude>ui/legacy/**</exclude>
<exclude>utils/testsmallfileinactive</exclude>
<exclude>utils/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker</exclude>
<exclude>**/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker</exclude>
</excludes>
</configuration>
</plugin>

View File

@ -1 +1 @@
mock-maker-inline
mock-maker-inline