Skip to content

Commit 3139967

Browse files
committed
Fix and enable tests for storage plugins
1 parent 27b0a64 commit 3139967

12 files changed

Lines changed: 27 additions & 50 deletions

File tree

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 & 21 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;
@@ -45,17 +46,18 @@
4546
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
4647
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4748
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
48-
import org.apache.cloudstack.storage.datastore.provider.DefaultHostListener;
4949
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
50+
import org.junit.After;
51+
import org.junit.Assert;
5052
import org.junit.Before;
5153
import org.junit.Test;
5254
import org.junit.runner.RunWith;
5355
import org.mockito.InjectMocks;
5456
import org.mockito.Mock;
5557
import org.mockito.Mockito;
5658
import org.mockito.MockitoAnnotations;
57-
import org.mockito.Spy;
5859
import org.mockito.runners.MockitoJUnitRunner;
60+
import org.springframework.test.util.ReflectionTestUtils;
5961

6062
import java.util.ArrayList;
6163
import java.util.List;
@@ -64,8 +66,6 @@
6466
import static org.mockito.Matchers.anyLong;
6567
import static org.mockito.Matchers.anyString;
6668
import static org.mockito.Matchers.eq;
67-
import static org.mockito.Mockito.times;
68-
import static org.mockito.Mockito.verify;
6969
import static org.mockito.Mockito.when;
7070

7171
/**
@@ -77,7 +77,6 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
7777
@InjectMocks
7878
PrimaryDataStoreLifeCycle _cloudStackPrimaryDataStoreLifeCycle = new CloudStackPrimaryDataStoreLifeCycleImpl();
7979

80-
@Spy
8180
@InjectMocks
8281
StorageManager storageMgr = new StorageManagerImpl();
8382

@@ -93,9 +92,8 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
9392
@Mock
9493
DataStoreProviderManager _dataStoreProviderMgr;
9594

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

10098
@Mock
10199
StoragePoolHostDao storagePoolHostDao;
@@ -121,10 +119,16 @@ public class CloudStackPrimaryDataStoreLifeCycleImplTest extends TestCase {
121119
@Mock
122120
PrimaryDataStoreHelper primaryDataStoreHelper;
123121

122+
AutoCloseable closeable;
123+
124124
@Before
125-
public void initMocks() {
125+
public void initMocks() throws StorageConflictException {
126+
closeable = MockitoAnnotations.openMocks(this);
126127

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

129133
List<HostVO> hostList = new ArrayList<HostVO>();
130134
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 +145,31 @@ public void initMocks() {
141145
when(store.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
142146
when(store.isShared()).thenReturn(true);
143147
when(store.getName()).thenReturn("newPool");
148+
when(store.getStorageProviderName()).thenReturn("default");
149+
144150

145151
when(_dataStoreProviderMgr.getDataStoreProvider(anyString())).thenReturn(dataStoreProvider);
146152
when(dataStoreProvider.getName()).thenReturn("default");
147-
((StorageManagerImpl)storageMgr).registerHostListener("default", hostListener);
153+
154+
when(hostListener.hostConnect(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
155+
storageMgr.registerHostListener("default", hostListener);
156+
148157

149158
when(_resourceMgr.listAllUpHosts(eq(Host.Type.Routing), anyLong(), anyLong(), anyLong())).thenReturn(hostList);
150159
when(agentMgr.easySend(anyLong(), Mockito.any(ModifyStoragePoolCommand.class))).thenReturn(answer);
151160
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);
157161

158-
when(storagePoolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(null);
159162
when(primaryStoreDao.findById(anyLong())).thenReturn(storagePool);
160-
when(primaryStoreDao.update(anyLong(), Mockito.any(StoragePoolVO.class))).thenReturn(true);
161163
when(primaryDataStoreHelper.attachCluster(Mockito.any(DataStore.class))).thenReturn(null);
162164
}
163165

166+
@After
167+
public void tearDown() throws Exception {
168+
closeable.close();
169+
}
170+
164171
@Test
165172
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-
173+
Assert.assertTrue(_cloudStackPrimaryDataStoreLifeCycle.attachCluster(store, new ClusterScope(1L, 1L, 1L)));
169174
}
170175
}

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)