Skip to content

Commit 409e320

Browse files
authored
Fix and enable tests for storage plugins (#7657)
1 parent 0466bf9 commit 409e320

File tree

12 files changed

+27
-52
lines changed

12 files changed

+27
-52
lines changed

plugins/storage/image/default/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
<plugins>
5454
<plugin>
5555
<artifactId>maven-surefire-plugin</artifactId>
56-
<configuration>
57-
<skipTests>true</skipTests>
58-
</configuration>
5956
<executions>
6057
<execution>
6158
<phase>integration-test</phase>

plugins/storage/image/sample/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
<plugins>
5454
<plugin>
5555
<artifactId>maven-surefire-plugin</artifactId>
56-
<configuration>
57-
<skipTests>true</skipTests>
58-
</configuration>
5956
<executions>
6057
<execution>
6158
<phase>integration-test</phase>

plugins/storage/image/swift/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
<plugins>
5454
<plugin>
5555
<artifactId>maven-surefire-plugin</artifactId>
56-
<configuration>
57-
<skipTests>true</skipTests>
58-
</configuration>
5956
<executions>
6057
<execution>
6158
<phase>integration-test</phase>

plugins/storage/volume/cloudbyte/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
<plugins>
5858
<plugin>
5959
<artifactId>maven-surefire-plugin</artifactId>
60-
<configuration>
61-
<skipTests>true</skipTests>
62-
</configuration>
6360
<executions>
6461
<execution>
6562
<phase>integration-test</phase>

plugins/storage/volume/datera/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
<plugins>
5050
<plugin>
5151
<artifactId>maven-surefire-plugin</artifactId>
52-
<configuration>
53-
<skipTests>true</skipTests>
54-
</configuration>
5552
<executions>
5653
<execution>
5754
<phase>integration-test</phase>

plugins/storage/volume/default/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
<plugins>
3939
<plugin>
4040
<artifactId>maven-surefire-plugin</artifactId>
41-
<configuration>
42-
<skipTests>true</skipTests>
43-
</configuration>
4441
<executions>
4542
<execution>
4643
<phase>integration-test</phase>

plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.cloud.agent.api.ModifyStoragePoolAnswer;
2424
import com.cloud.agent.api.ModifyStoragePoolCommand;
2525
import com.cloud.agent.api.StoragePoolInfo;
26+
import com.cloud.exception.StorageConflictException;
2627
import com.cloud.host.Host;
2728
import com.cloud.host.HostVO;
2829
import com.cloud.host.Status;
@@ -32,7 +33,6 @@
3233
import com.cloud.storage.Storage;
3334
import com.cloud.storage.StorageManager;
3435
import com.cloud.storage.StorageManagerImpl;
35-
import com.cloud.storage.StoragePoolHostVO;
3636
import com.cloud.storage.dao.StoragePoolHostDao;
3737
import junit.framework.TestCase;
3838
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
@@ -45,17 +45,18 @@
4545
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
4646
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4747
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
48-
import org.apache.cloudstack.storage.datastore.provider.DefaultHostListener;
4948
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
49+
import org.junit.After;
50+
import org.junit.Assert;
5051
import org.junit.Before;
5152
import org.junit.Test;
5253
import org.junit.runner.RunWith;
5354
import org.mockito.InjectMocks;
5455
import org.mockito.Mock;
5556
import org.mockito.Mockito;
5657
import org.mockito.MockitoAnnotations;
57-
import org.mockito.Spy;
5858
import org.mockito.runners.MockitoJUnitRunner;
59+
import org.springframework.test.util.ReflectionTestUtils;
5960

6061
import java.util.ArrayList;
6162
import java.util.List;
@@ -64,8 +65,6 @@
6465
import static org.mockito.Matchers.anyLong;
6566
import static org.mockito.Matchers.anyString;
6667
import static org.mockito.Matchers.eq;
67-
import static org.mockito.Mockito.times;
68-
import static org.mockito.Mockito.verify;
6968
import static org.mockito.Mockito.when;
7069

7170
/**
@@ -77,7 +76,6 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
7776
@InjectMocks
7877
PrimaryDataStoreLifeCycle _cloudStackPrimaryDataStoreLifeCycle = new CloudStackPrimaryDataStoreLifeCycleImpl();
7978

80-
@Spy
8179
@InjectMocks
8280
StorageManager storageMgr = new StorageManagerImpl();
8381

@@ -93,9 +91,8 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
9391
@Mock
9492
DataStoreProviderManager _dataStoreProviderMgr;
9593

96-
@Spy
97-
@InjectMocks
98-
HypervisorHostListener hostListener = new DefaultHostListener();
94+
@Mock
95+
HypervisorHostListener hostListener;
9996

10097
@Mock
10198
StoragePoolHostDao storagePoolHostDao;
@@ -121,10 +118,16 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
121118
@Mock
122119
PrimaryDataStoreHelper primaryDataStoreHelper;
123120

121+
AutoCloseable closeable;
122+
124123
@Before
125-
public void initMocks() {
124+
public void initMocks() throws StorageConflictException {
125+
closeable = MockitoAnnotations.openMocks(this);
126126

127-
MockitoAnnotations.initMocks(this);
127+
ReflectionTestUtils.setField(storageMgr, "_storagePoolDao", primaryStoreDao);
128+
ReflectionTestUtils.setField(storageMgr, "_dataStoreProviderMgr", _dataStoreProviderMgr);
129+
ReflectionTestUtils.setField(storageMgr, "_dataStoreMgr", _dataStoreMgr);
130+
ReflectionTestUtils.setField(_cloudStackPrimaryDataStoreLifeCycle, "storageMgr", storageMgr);
128131

129132
List<HostVO> hostList = new ArrayList<HostVO>();
130133
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 void initMocks() {
141144
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
142145
when(store.isShared()).thenReturn(true);
143146
when(store.getName()).thenReturn("newPool");
147+
when(store.getStorageProviderName()).thenReturn("default");
148+
144149

145150
when(_dataStoreProviderMgr.getDataStoreProvider(anyString())).thenReturn(dataStoreProvider);
146151
when(dataStoreProvider.getName()).thenReturn("default");
147-
((StorageManagerImpl)storageMgr).registerHostListener("default", hostListener);
152+
153+
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
154+
storageMgr.registerHostListener("default", hostListener);
155+
148156

149157
when(_resourceMgr.listAllUpHosts(eq(Host.Type.Routing), anyLong(), anyLong(), anyLong())).thenReturn(hostList);
150158
when(agentMgr.easySend(anyLong(), Mockito.any(ModifyStoragePoolCommand.class))).thenReturn(answer);
151159
when(answer.getResult()).thenReturn(true);
152-
when(answer.getPoolInfo()).thenReturn(info);
153-
154-
when(info.getLocalPath()).thenReturn("/mnt/1");
155-
when(info.getCapacityBytes()).thenReturn(0L);
156-
when(info.getAvailableBytes()).thenReturn(0L);
157160

158-
when(storagePoolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(null);
159161
when(primaryStoreDao.findById(anyLong())).thenReturn(storagePool);
160-
when(primaryStoreDao.update(anyLong(), Mockito.any(StoragePoolVO.class))).thenReturn(true);
161162
when(primaryDataStoreHelper.attachCluster(Mockito.any(DataStore.class))).thenReturn(null);
162163
}
163164

165+
@After
166+
public void tearDown() throws Exception {
167+
closeable.close();
168+
}
169+
164170
@Test
165171
public void testAttachCluster() throws Exception {
166-
_cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L));
167-
verify(storagePoolHostDao,times(2)).persist(Mockito.any(StoragePoolHostVO.class));
168-
172+
Assert.assertTrue(_cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L)));
169173
}
170174
}

plugins/storage/volume/linstor/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
<plugins>
4949
<plugin>
5050
<artifactId>maven-surefire-plugin</artifactId>
51-
<configuration>
52-
<skipTests>true</skipTests>
53-
</configuration>
5451
<executions>
5552
<execution>
5653
<phase>integration-test</phase>

plugins/storage/volume/nexenta/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
<plugins>
3939
<plugin>
4040
<artifactId>maven-surefire-plugin</artifactId>
41-
<configuration>
42-
<skipTests>true</skipTests>
43-
</configuration>
4441
<executions>
4542
<execution>
4643
<phase>integration-test</phase>

plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public void testIsIscsiTargetGroupExists() {
119119
when(client.execute(ListOfStringsNmsResponse.class, "stmf", "list_targetgroups")).thenReturn(null);
120120
assertFalse(appliance.isIscsiTargetGroupExists(targetGroup));
121121

122-
when(client.execute(ListOfIscsiTargetsNmsResponse.class, "stmf", "list_targetgroups")).thenReturn(new ListOfIscsiTargetsNmsResponse());
123122
assertFalse(appliance.isIscsiTargetGroupExists(targetGroup));
124123

125124
LinkedList<String> result = new LinkedList<String>();

0 commit comments

Comments
 (0)