Skip to content

Commit 4fbecf1

Browse files
author
Edison Su
committed
add unit test back, primary storage life cycle is tested
1 parent 3251cd6 commit 4fbecf1

181 files changed

Lines changed: 557 additions & 363 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/com/cloud/storage/StoragePoolVO.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class StoragePoolVO implements StoragePool {
4949

5050
@Column(name="pool_type", updatable=false, nullable=false, length=32)
5151
@Enumerated(value=EnumType.STRING)
52-
private StoragePoolType protocol;
52+
private StoragePoolType poolType;
5353

5454
@Column(name=GenericDao.CREATED_COLUMN)
5555
Date created;
@@ -112,7 +112,7 @@ public String getUuid() {
112112

113113
@Override
114114
public StoragePoolType getPoolType() {
115-
return protocol;
115+
return poolType;
116116
}
117117

118118
@Override
@@ -215,7 +215,7 @@ public StoragePoolVO(long poolId, String name, String uuid, StoragePoolType type
215215
this.name = name;
216216
this.id = poolId;
217217
this.uuid = uuid;
218-
this.protocol = type;
218+
this.poolType = type;
219219
this.dataCenterId = dataCenterId;
220220
this.availableBytes = availableBytes;
221221
this.capacityBytes = capacityBytes;
@@ -227,11 +227,11 @@ public StoragePoolVO(long poolId, String name, String uuid, StoragePoolType type
227227
}
228228

229229
public StoragePoolVO(StoragePoolVO that) {
230-
this(that.id, that.name, that.uuid, that.protocol, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
230+
this(that.id, that.name, that.uuid, that.poolType, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
231231
}
232232

233233
public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path) {
234-
this.protocol = type;
234+
this.poolType = type;
235235
this.hostAddress = hostAddress;
236236
this.port = port;
237237
this.path = path;
@@ -240,7 +240,7 @@ public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String
240240
}
241241

242242
public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path, String userInfo) {
243-
this.protocol = type;
243+
this.poolType = type;
244244
this.hostAddress = hostAddress;
245245
this.port = port;
246246
this.path = path;
@@ -285,12 +285,12 @@ public int getPort() {
285285

286286
@Override
287287
public boolean isShared() {
288-
return protocol.isShared();
288+
return poolType.isShared();
289289
}
290290

291291
@Override
292292
public boolean isLocal() {
293-
return !protocol.isShared();
293+
return !poolType.isShared();
294294
}
295295

296296
@Transient
@@ -341,6 +341,6 @@ public int hashCode() {
341341

342342
@Override
343343
public String toString() {
344-
return new StringBuilder("Pool[").append(id).append("|").append(protocol).append("]").toString();
344+
return new StringBuilder("Pool[").append(id).append("|").append(poolType).append("]").toString();
345345
}
346346
}

engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implement
3737
protected final SearchBuilder<DetailVO> HostSearch;
3838
protected final SearchBuilder<DetailVO> DetailSearch;
3939

40-
protected HostDetailsDaoImpl() {
40+
public HostDetailsDaoImpl() {
4141
HostSearch = createSearchBuilder();
4242
HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
4343
HostSearch.done();

engine/storage/integration-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
<version>${project.version}</version>
3333
<scope>test</scope>
3434
</dependency>
35+
<dependency>
36+
<groupId>org.apache.cloudstack</groupId>
37+
<artifactId>cloud-engine-storage-snapshot</artifactId>
38+
<version>${project.version}</version>
39+
<scope>test</scope>
40+
</dependency>
3541
<dependency>
3642
<groupId>org.apache.cloudstack</groupId>
3743
<artifactId>cloud-engine-storage-image</artifactId>

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,38 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.test;
1818

19+
import org.apache.cloudstack.acl.APIChecker;
20+
import org.apache.cloudstack.engine.service.api.OrchestrationService;
1921
import org.apache.cloudstack.storage.HostEndpointRpcServer;
22+
import org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector;
23+
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
2024
import org.mockito.Mockito;
2125
import org.springframework.context.annotation.Bean;
2226

2327
import com.cloud.agent.AgentManager;
28+
import com.cloud.cluster.ClusteredAgentRebalanceService;
29+
import com.cloud.cluster.agentlb.dao.HostTransferMapDao;
30+
import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
31+
import com.cloud.dc.dao.ClusterDao;
32+
import com.cloud.dc.dao.ClusterDaoImpl;
33+
import com.cloud.dc.dao.DataCenterDao;
34+
import com.cloud.dc.dao.DataCenterDaoImpl;
35+
import com.cloud.dc.dao.DataCenterIpAddressDaoImpl;
36+
import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
37+
import com.cloud.dc.dao.DataCenterVnetDaoImpl;
38+
import com.cloud.dc.dao.DcDetailsDaoImpl;
39+
import com.cloud.dc.dao.HostPodDao;
40+
import com.cloud.dc.dao.HostPodDaoImpl;
41+
import com.cloud.dc.dao.PodVlanDaoImpl;
2442
import com.cloud.host.dao.HostDao;
43+
import com.cloud.host.dao.HostDetailsDao;
44+
import com.cloud.host.dao.HostDetailsDaoImpl;
45+
import com.cloud.host.dao.HostTagsDao;
46+
import com.cloud.host.dao.HostTagsDaoImpl;
47+
import com.cloud.server.auth.UserAuthenticator;
48+
import com.cloud.storage.dao.StoragePoolHostDao;
49+
import com.cloud.storage.dao.StoragePoolHostDaoImpl;
50+
import com.cloud.utils.component.ComponentContext;
2551

2652
public class ChildTestConfiguration extends TestConfiguration {
2753

@@ -33,6 +59,53 @@ public HostDao hostDao() {
3359
return nDao;
3460
}
3561

62+
@Bean
63+
public EndPointSelector selector() {
64+
return Mockito.mock(EndPointSelector.class);
65+
}
66+
@Bean
67+
public DataCenterDao dcDao() {
68+
return new DataCenterDaoImpl();
69+
}
70+
@Bean
71+
public HostDetailsDao hostDetailsDao() {
72+
return new HostDetailsDaoImpl();
73+
}
74+
75+
@Bean
76+
public HostTagsDao hostTagsDao() {
77+
return new HostTagsDaoImpl();
78+
}
79+
80+
@Bean ClusterDao clusterDao() {
81+
return new ClusterDaoImpl();
82+
}
83+
84+
@Bean HostTransferMapDao hostTransferDao() {
85+
return new HostTransferMapDaoImpl();
86+
}
87+
@Bean DataCenterIpAddressDaoImpl dataCenterIpAddressDaoImpl() {
88+
return new DataCenterIpAddressDaoImpl();
89+
}
90+
@Bean DataCenterLinkLocalIpAddressDaoImpl dataCenterLinkLocalIpAddressDaoImpl() {
91+
return new DataCenterLinkLocalIpAddressDaoImpl();
92+
}
93+
@Bean DataCenterVnetDaoImpl dataCenterVnetDaoImpl() {
94+
return new DataCenterVnetDaoImpl();
95+
}
96+
@Bean PodVlanDaoImpl podVlanDaoImpl() {
97+
return new PodVlanDaoImpl();
98+
}
99+
@Bean DcDetailsDaoImpl dcDetailsDaoImpl() {
100+
return new DcDetailsDaoImpl();
101+
}
102+
@Bean HostPodDao hostPodDao() {
103+
return new HostPodDaoImpl();
104+
}
105+
@Bean StoragePoolHostDao storagePoolHostDao() {
106+
return new StoragePoolHostDaoImpl();
107+
}
108+
36109
@Bean
37110
public AgentManager agentMgr() {
38111
return new DirectAgentManagerSimpleImpl();
@@ -42,6 +115,22 @@ public AgentManager agentMgr() {
42115
public HostEndpointRpcServer rpcServer() {
43116
return new MockHostEndpointRpcServerDirectCallResource();
44117
}
118+
@Bean
119+
public ClusteredAgentRebalanceService _rebalanceService() {
120+
return Mockito.mock(ClusteredAgentRebalanceService.class);
121+
}
122+
@Bean
123+
public UserAuthenticator authenticator() {
124+
return Mockito.mock(UserAuthenticator.class);
125+
}
126+
@Bean
127+
public OrchestrationService orchSrvc() {
128+
return Mockito.mock(OrchestrationService.class);
129+
}
130+
@Bean
131+
public APIChecker apiChecker() {
132+
return Mockito.mock(APIChecker.class);
133+
}
45134
/* @Override
46135
@Bean
47136
public PrimaryDataStoreDao primaryDataStoreDao() {

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.storage.test;
2020

21+
import java.net.URI;
22+
import java.net.URISyntaxException;
2123
import java.util.ArrayList;
2224
import java.util.HashMap;
2325
import java.util.List;
@@ -33,12 +35,15 @@
3335
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3436
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
3537
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
38+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3639
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
3740
import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
41+
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
3842
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
3943
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
4044
import org.apache.cloudstack.storage.datastore.provider.DataStoreProvider;
4145
import org.apache.cloudstack.storage.datastore.provider.DataStoreProviderManager;
46+
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
4247
import org.apache.cloudstack.storage.image.ImageService;
4348
import org.apache.cloudstack.storage.image.db.ImageDataDao;
4449
import org.apache.cloudstack.storage.image.db.ImageDataVO;
@@ -66,7 +71,7 @@
6671
import com.cloud.resource.ResourceState;
6772
import com.cloud.storage.Storage.TemplateType;
6873

69-
@ContextConfiguration(locations="classpath:/storageContext.xml")
74+
@ContextConfiguration(locations={"classpath:/storageContext.xml"})
7075
public class volumeServiceTest extends CloudStackTestNGBase {
7176
//@Inject
7277
//ImageDataStoreProviderManager imageProviderMgr;
@@ -92,6 +97,8 @@ public class volumeServiceTest extends CloudStackTestNGBase {
9297
DataStoreProviderManager dataStoreProviderMgr;
9398
@Inject
9499
AgentManager agentMgr;
100+
@Inject
101+
EndPointSelector selector;
95102
Long dcId;
96103
Long clusterId;
97104
Long podId;
@@ -101,7 +108,12 @@ public class volumeServiceTest extends CloudStackTestNGBase {
101108

102109
@Test(priority = -1)
103110
public void setUp() {
104-
111+
try {
112+
dataStoreProviderMgr.configure(null, new HashMap<String, Object>());
113+
} catch (ConfigurationException e) {
114+
// TODO Auto-generated catch block
115+
e.printStackTrace();
116+
}
105117
host = hostDao.findByGuid(this.getHostGuid());
106118
if (host != null) {
107119
dcId = host.getDataCenterId();
@@ -143,13 +155,8 @@ public void setUp() {
143155
host.setClusterId(cluster.getId());
144156

145157
host = hostDao.persist(host);
146-
try {
147-
dataStoreProviderMgr.configure(null, new HashMap<String, Object>());
148-
} catch (ConfigurationException e) {
149-
// TODO Auto-generated catch block
150-
e.printStackTrace();
151-
}
152-
primaryStore = createPrimaryDataStore();
158+
159+
//primaryStore = createPrimaryDataStore();
153160

154161
//CreateVolumeAnswer createVolumeFromImageAnswer = new CreateVolumeAnswer(UUID.randomUUID().toString());
155162

@@ -175,7 +182,12 @@ protected void injectMockito() {
175182
List<HostVO> results = new ArrayList<HostVO>();
176183
results.add(host);
177184
Mockito.when(hostDao.listAll()).thenReturn(results);
185+
Mockito.when(hostDao.findById(Mockito.anyLong())).thenReturn(host);
178186
Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
187+
List<EndPoint> eps = new ArrayList<EndPoint>();
188+
eps.add(HypervisorHostEndPoint.getHypervisorHostEndPoint(host.getId(),
189+
host.getPrivateIpAddress()));
190+
Mockito.when(selector.selectAll(Mockito.any(DataStore.class))).thenReturn(eps);
179191
}
180192

181193
private ImageDataVO createImageData() {
@@ -220,16 +232,50 @@ private TemplateEntity createTemplate() {
220232
public void createTemplateTest() {
221233
createTemplate();
222234
}
235+
236+
@Test
237+
public void testCreatePrimaryStorage() {
238+
DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
239+
Map<String, String> params = new HashMap<String, String>();
240+
URI uri = null;
241+
try {
242+
uri = new URI(this.getPrimaryStorageUrl());
243+
} catch (URISyntaxException e) {
244+
// TODO Auto-generated catch block
245+
e.printStackTrace();
246+
}
247+
params.put("url", this.getPrimaryStorageUrl());
248+
params.put("server", uri.getHost());
249+
params.put("path", uri.getPath());
250+
params.put("protocol", uri.getScheme());
251+
params.put("dcId", dcId.toString());
252+
params.put("clusterId", clusterId.toString());
253+
params.put("name", this.primaryName);
254+
params.put("port", "1");
255+
params.put("roles", DataStoreRole.Primary.toString());
256+
params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
257+
params.put("providerId", String.valueOf(provider.getId()));
258+
259+
DataStoreLifeCycle lifeCycle = provider.getLifeCycle();
260+
DataStore store = lifeCycle.initialize(params);
261+
ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
262+
lifeCycle.attachCluster(store, scope);
263+
}
223264

224265
@Test
225266
public PrimaryDataStoreInfo createPrimaryDataStore() {
226-
try {
267+
try {/*
227268
DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
228269
Map<String, String> params = new HashMap<String, String>();
229-
params.put("url", this.getPrimaryStorageUrl());
270+
URI uri = new URI(this.getPrimaryStorageUrl());
271+
params.put("url", this.getPrimaryStorageUrl());
272+
params.put("server", uri.getHost());
273+
params.put("path", uri.getPath());
274+
params.put("protocol", uri.getScheme());
230275
params.put("dcId", dcId.toString());
231276
params.put("clusterId", clusterId.toString());
232277
params.put("name", this.primaryName);
278+
params.put("port", "1");
233279
params.put("roles", DataStoreRole.Primary.toString());
234280
params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
235281
params.put("providerId", String.valueOf(provider.getId()));
@@ -238,6 +284,7 @@ public PrimaryDataStoreInfo createPrimaryDataStore() {
238284
DataStore store = lifeCycle.initialize(params);
239285
ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
240286
lifeCycle.attachCluster(store, scope);
287+
*/
241288
/*
242289
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
243290
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
@@ -306,7 +353,7 @@ public void tearDown() {
306353
}
307354

308355
//@Test
309-
@Test
356+
//@Test
310357
public void test1() {
311358
/*System.out.println(VolumeTypeHelper.getType("Root"));
312359
System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk"));

0 commit comments

Comments
 (0)