Fix and enable tests for storage plugins (#7657)

This commit is contained in:
Vishesh 2023-06-23 17:16:14 +05:30 committed by GitHub
parent 0466bf9d47
commit 409e3202a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,6 +23,7 @@ import com.cloud.agent.AgentManager;
import com.cloud.agent.api.ModifyStoragePoolAnswer;
import com.cloud.agent.api.ModifyStoragePoolCommand;
import com.cloud.agent.api.StoragePoolInfo;
import com.cloud.exception.StorageConflictException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
@ -32,7 +33,6 @@ import com.cloud.storage.DataStoreRole;
import com.cloud.storage.Storage;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StorageManagerImpl;
import com.cloud.storage.StoragePoolHostVO;
import com.cloud.storage.dao.StoragePoolHostDao;
import junit.framework.TestCase;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
@ -45,8 +45,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.provider.DefaultHostListener;
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -54,8 +55,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList;
import java.util.List;
@ -64,8 +65,6 @@ import java.util.UUID;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
@ -77,7 +76,6 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
@InjectMocks
PrimaryDataStoreLifeCycle _cloudStackPrimaryDataStoreLifeCycle = new CloudStackPrimaryDataStoreLifeCycleImpl();
@Spy
@InjectMocks
StorageManager storageMgr = new StorageManagerImpl();
@ -93,9 +91,8 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
@Mock
DataStoreProviderManager _dataStoreProviderMgr;
@Spy
@InjectMocks
HypervisorHostListener hostListener = new DefaultHostListener();
@Mock
HypervisorHostListener hostListener;
@Mock
StoragePoolHostDao storagePoolHostDao;
@ -121,10 +118,16 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
@Mock
PrimaryDataStoreHelper primaryDataStoreHelper;
@Before
public void initMocks() {
AutoCloseable closeable;
MockitoAnnotations.initMocks(this);
@Before
public void initMocks() throws StorageConflictException {
closeable = MockitoAnnotations.openMocks(this);
ReflectionTestUtils.setField(storageMgr, "_storagePoolDao", primaryStoreDao);
ReflectionTestUtils.setField(storageMgr, "_dataStoreProviderMgr", _dataStoreProviderMgr);
ReflectionTestUtils.setField(storageMgr, "_dataStoreMgr", _dataStoreMgr);
ReflectionTestUtils.setField(_cloudStackPrimaryDataStoreLifeCycle, "storageMgr", storageMgr);
List<HostVO> hostList = new ArrayList<HostVO>();
HostVO host1 = new HostVO(1L, "aa01", Host.Type.Routing, "192.168.1.1", "255.255.255.0", null, null, null, null, null, null, null, null, null, null,
@ -141,30 +144,31 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
when(store.isShared()).thenReturn(true);
when(store.getName()).thenReturn("newPool");
when(store.getStorageProviderName()).thenReturn("default");
when(_dataStoreProviderMgr.getDataStoreProvider(anyString())).thenReturn(dataStoreProvider);
when(dataStoreProvider.getName()).thenReturn("default");
((StorageManagerImpl)storageMgr).registerHostListener("default", hostListener);
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
storageMgr.registerHostListener("default", hostListener);
when(_resourceMgr.listAllUpHosts(eq(Host.Type.Routing), anyLong(), anyLong(), anyLong())).thenReturn(hostList);
when(agentMgr.easySend(anyLong(), Mockito.any(ModifyStoragePoolCommand.class))).thenReturn(answer);
when(answer.getResult()).thenReturn(true);
when(answer.getPoolInfo()).thenReturn(info);
when(info.getLocalPath()).thenReturn("/mnt/1");
when(info.getCapacityBytes()).thenReturn(0L);
when(info.getAvailableBytes()).thenReturn(0L);
when(storagePoolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(null);
when(primaryStoreDao.findById(anyLong())).thenReturn(storagePool);
when(primaryStoreDao.update(anyLong(), Mockito.any(StoragePoolVO.class))).thenReturn(true);
when(primaryDataStoreHelper.attachCluster(Mockito.any(DataStore.class))).thenReturn(null);
}
@After
public void tearDown() throws Exception {
closeable.close();
}
@Test
public void testAttachCluster() throws Exception {
_cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L));
verify(storagePoolHostDao,times(2)).persist(Mockito.any(StoragePoolHostVO.class));
Assert.assertTrue(_cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L)));
}
}

View File

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

View File

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

View File

@ -119,7 +119,6 @@ public class NexentaStorApplianceTest {
when(client.execute(ListOfStringsNmsResponse.class, "stmf", "list_targetgroups")).thenReturn(null);
assertFalse(appliance.isIscsiTargetGroupExists(targetGroup));
when(client.execute(ListOfIscsiTargetsNmsResponse.class, "stmf", "list_targetgroups")).thenReturn(new ListOfIscsiTargetsNmsResponse());
assertFalse(appliance.isIscsiTargetGroupExists(targetGroup));
LinkedList<String> result = new LinkedList<String>();

View File

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

View File

@ -53,7 +53,6 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import com.cloud.host.Host;
@ -103,7 +102,7 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest {
@InjectMocks
private StorageManager storageMgr = new StorageManagerImpl();
@Spy
@Mock
private HypervisorHostListener hostListener;
@InjectMocks