add test case for create storage pool

This commit is contained in:
Edison Su 2013-01-18 19:44:07 -08:00 committed by Edison Su
parent b4988e86ab
commit 3251cd665b
6 changed files with 38 additions and 119 deletions

View File

@ -22,7 +22,7 @@ import java.util.Map;
public interface DataStoreLifeCycle {
public boolean initialize(DataStore store, Map<String, String> dsInfos);
public DataStore initialize(Map<String, String> dsInfos);
public boolean attachCluster(DataStore store, ClusterScope scope);

View File

@ -34,9 +34,9 @@ public class DefaultImageDataStoreLifeCycle implements ImageDataStoreLifeCycle {
@Override
public boolean initialize(DataStore store, Map<String, String> dsInfos) {
public DataStore initialize(Map<String, String> dsInfos) {
// TODO Auto-generated method stub
return false;
return null;
}

View File

@ -21,6 +21,7 @@ package org.apache.cloudstack.storage.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.inject.Inject;
@ -28,10 +29,15 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.datastore.provider.DataStoreProvider;
import org.apache.cloudstack.storage.datastore.provider.DataStoreProviderManager;
import org.apache.cloudstack.storage.image.ImageService;
import org.apache.cloudstack.storage.image.db.ImageDataDao;
@ -215,9 +221,23 @@ public class volumeServiceTest extends CloudStackTestNGBase {
createTemplate();
}
private PrimaryDataStoreInfo createPrimaryDataStore() {
@Test
public PrimaryDataStoreInfo createPrimaryDataStore() {
try {
DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
Map<String, String> params = new HashMap<String, String>();
params.put("url", this.getPrimaryStorageUrl());
params.put("dcId", dcId.toString());
params.put("clusterId", clusterId.toString());
params.put("name", this.primaryName);
params.put("roles", DataStoreRole.Primary.toString());
params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
params.put("providerId", String.valueOf(provider.getId()));
DataStoreLifeCycle lifeCycle = provider.getLifeCycle();
DataStore store = lifeCycle.initialize(params);
ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
lifeCycle.attachCluster(store, scope);
/*
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
@ -255,7 +275,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
return volume;
}
@Test(priority=2)
//@Test(priority=2)
public void createVolumeFromTemplate() {
primaryStore = createPrimaryDataStore();
TemplateEntity te = createTemplate();
@ -265,7 +285,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
ve.destroy();
}
@Test(priority=3)
//@Test(priority=3)
public void createDataDisk() {
primaryStore = createPrimaryDataStore();
VolumeVO volume = createVolume(null, primaryStore.getId());

View File

@ -35,6 +35,7 @@ public class DataStoreManagerImpl implements DataStoreManager {
PrimaryDataStoreProviderManager primaryStorMgr;
@Inject
ImageDataStoreManager imageDataStoreMgr;
@Override
public DataStore getDataStore(long storeId, DataStoreRole role) {
if (role == DataStoreRole.Primary) {
@ -47,7 +48,6 @@ public class DataStoreManagerImpl implements DataStoreManager {
@Override
public DataStore registerDataStore(Map<String, String> params,
String providerUuid) {
// TODO Auto-generated method stub
return null;
}

View File

@ -1,109 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.storage.datastore;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper;
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
import org.springframework.stereotype.Component;
import edu.emory.mathcs.backport.java.util.Arrays;
public class DefaultDatastoreLifeCyle implements DataStoreLifeCycle {
@Inject
PrimaryDataStoreHelper primaryStoreHelper;
@Inject
ImageDataStoreHelper imageStoreHelper;
@Override
public boolean initialize(DataStore store, Map<String, String> dsInfos) {
String roles = dsInfos.get("roles");
List<String> roleArry = Arrays.asList(roles.split(";"));
List<DataStoreRole> storeRoles = new ArrayList<DataStoreRole>();
for (String role : roleArry) {
storeRoles.add(DataStoreRole.getRole(role));
}
if (storeRoles.contains(DataStoreRole.Primary)) {
primaryStoreHelper.createPrimaryDataStore(dsInfos);
}
if (storeRoles.contains(DataStoreRole.Image)) {
imageStoreHelper.createImageDataStore(dsInfos);
}
//TODO: add more roles
return true;
}
@Override
public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
if (dataStore.getRole() == DataStoreRole.Primary) {
primaryStoreHelper.attachCluster(dataStore);
}
// TODO Auto-generated method stub
return true;
}
@Override
public boolean attachZone(DataStore dataStore, ZoneScope scope) {
return false;
}
@Override
public boolean dettach() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean unmanaged() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean maintain() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean cancelMaintain() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deleteDataStore() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -32,9 +32,12 @@ import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd;
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper;
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
@ -48,13 +51,18 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
PrimaryDataStoreDao dataStoreDao;
@Inject
HostDao hostDao;
@Inject
PrimaryDataStoreHelper primaryStoreHelper;
@Inject
PrimaryDataStoreProviderManager providerMgr;
public DefaultPrimaryDataStoreLifeCycleImpl() {
}
@Override
public boolean initialize(DataStore store, Map<String, String> dsInfos) {
//TODO: add extension point for each data store
return true;
public DataStore initialize(Map<String, String> dsInfos) {
PrimaryDataStoreVO storeVO = primaryStoreHelper.createPrimaryDataStore(dsInfos);
return providerMgr.getPrimaryDataStore(storeVO.getId());
}
protected void attachCluster(DataStore store) {