This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 409e3202a3c Fix and enable tests for storage plugins (#7657)
409e3202a3c is described below
commit 409e3202a3c00f22ca885976edaab12e050c6dab
Author: Vishesh <[email protected]>
AuthorDate: Fri Jun 23 17:16:14 2023 +0530
Fix and enable tests for storage plugins (#7657)
---
plugins/storage/image/default/pom.xml | 3 --
plugins/storage/image/sample/pom.xml | 3 --
plugins/storage/image/swift/pom.xml | 3 --
plugins/storage/volume/cloudbyte/pom.xml | 3 --
plugins/storage/volume/datera/pom.xml | 3 --
plugins/storage/volume/default/pom.xml | 3 --
...loudStackPrimaryDataStoreLifeCycleImplTest.java | 48 ++++++++++++----------
plugins/storage/volume/linstor/pom.xml | 3 --
plugins/storage/volume/nexenta/pom.xml | 3 --
.../datastore/util/NexentaStorApplianceTest.java | 1 -
plugins/storage/volume/sample/pom.xml | 3 --
.../ScaleIOPrimaryDataStoreLifeCycleTest.java | 3 +-
12 files changed, 27 insertions(+), 52 deletions(-)
diff --git a/plugins/storage/image/default/pom.xml
b/plugins/storage/image/default/pom.xml
index 20ade73b449..4f2b1ab2da5 100644
--- a/plugins/storage/image/default/pom.xml
+++ b/plugins/storage/image/default/pom.xml
@@ -53,9 +53,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/image/sample/pom.xml
b/plugins/storage/image/sample/pom.xml
index 781a2b6eaa7..29bb51417b9 100644
--- a/plugins/storage/image/sample/pom.xml
+++ b/plugins/storage/image/sample/pom.xml
@@ -53,9 +53,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/image/swift/pom.xml
b/plugins/storage/image/swift/pom.xml
index e15d6465974..5f2563b6d0b 100644
--- a/plugins/storage/image/swift/pom.xml
+++ b/plugins/storage/image/swift/pom.xml
@@ -53,9 +53,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/volume/cloudbyte/pom.xml
b/plugins/storage/volume/cloudbyte/pom.xml
index 2cae682f6f8..2313bfd75c2 100644
--- a/plugins/storage/volume/cloudbyte/pom.xml
+++ b/plugins/storage/volume/cloudbyte/pom.xml
@@ -57,9 +57,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/volume/datera/pom.xml
b/plugins/storage/volume/datera/pom.xml
index 8da4ac83b55..e3a53e74f7d 100644
--- a/plugins/storage/volume/datera/pom.xml
+++ b/plugins/storage/volume/datera/pom.xml
@@ -49,9 +49,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/volume/default/pom.xml
b/plugins/storage/volume/default/pom.xml
index 385ae7d30eb..66f9f6bf946 100644
--- a/plugins/storage/volume/default/pom.xml
+++ b/plugins/storage/volume/default/pom.xml
@@ -38,9 +38,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git
a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java
b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java
index ffdc5143e8c..dbd13d8f0de 100644
---
a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java
+++
b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java
@@ -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;
+ AutoCloseable closeable;
+
@Before
- public void initMocks() {
+ public void initMocks() throws StorageConflictException {
+ closeable = MockitoAnnotations.openMocks(this);
- MockitoAnnotations.initMocks(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)));
}
}
diff --git a/plugins/storage/volume/linstor/pom.xml
b/plugins/storage/volume/linstor/pom.xml
index e3ebb436a03..69de4ff3d67 100644
--- a/plugins/storage/volume/linstor/pom.xml
+++ b/plugins/storage/volume/linstor/pom.xml
@@ -48,9 +48,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git a/plugins/storage/volume/nexenta/pom.xml
b/plugins/storage/volume/nexenta/pom.xml
index 6a8f548d6e0..33c0ffe5987 100644
--- a/plugins/storage/volume/nexenta/pom.xml
+++ b/plugins/storage/volume/nexenta/pom.xml
@@ -38,9 +38,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git
a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java
b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java
index 6dc59ebd0af..749c04b8ebe 100644
---
a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java
+++
b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java
@@ -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>();
diff --git a/plugins/storage/volume/sample/pom.xml
b/plugins/storage/volume/sample/pom.xml
index 4e919110477..bb96b60a338 100644
--- a/plugins/storage/volume/sample/pom.xml
+++ b/plugins/storage/volume/sample/pom.xml
@@ -38,9 +38,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
<executions>
<execution>
<phase>integration-test</phase>
diff --git
a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java
b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java
index 17d0c9b9edf..4a6e73a327d 100644
---
a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java
+++
b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java
@@ -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