This commit is contained in:
Edison Su 2013-05-12 18:27:25 -07:00
parent 0b9e0c0f3a
commit 492127c035
10 changed files with 63 additions and 34 deletions

View File

@ -67,6 +67,12 @@
<artifactId>cloud-plugin-hypervisor-vmware</artifactId> <artifactId>cloud-plugin-hypervisor-vmware</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-hypervisor-kvm</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.cloudstack</groupId> <groupId>org.apache.cloudstack</groupId>

View File

@ -24,6 +24,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
@ -38,6 +39,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
private String secondaryStorage; private String secondaryStorage;
private String imageInstallPath; private String imageInstallPath;
private String scriptPath; private String scriptPath;
private HypervisorType hypervisor;
private Transaction txn; private Transaction txn;
private String s3AccessKey; private String s3AccessKey;
@ -72,11 +74,14 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr", @Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr",
"devcloud-host-ip", "template-url", "devcloud-local-storage-uuid", "devcloud-host-ip", "template-url", "devcloud-local-storage-uuid",
"primary-storage-want-to-add", "devcloud-secondary-storage", "s3-accesskey", "s3-secretkey", "s3-endpoint", "s3-template-bucket", "s3-usehttps", "image-install-path", "primary-storage-uuid-want-to-add", "script-path"}) "primary-storage-want-to-add", "devcloud-secondary-storage", "s3-accesskey", "s3-secretkey", "s3-endpoint",
"s3-template-bucket", "s3-usehttps", "image-install-path", "primary-storage-uuid-want-to-add", "script-path",
"hypervisor"})
protected void setup(String hostuuid, String gateway, String cidr, protected void setup(String hostuuid, String gateway, String cidr,
String hostIp, String templateUrl, String localStorageUuid, String hostIp, String templateUrl, String localStorageUuid,
String primaryStorage, String secondaryStorage, String s3_accessKey, String s3_secretKey, String s3_endpoint, String s3_template_bucket, String primaryStorage, String secondaryStorage, String s3_accessKey, String s3_secretKey, String s3_endpoint, String s3_template_bucket,
String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath) { String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath,
String hypervisor) {
this.hostGuid = hostuuid; this.hostGuid = hostuuid;
this.hostGateway = gateway; this.hostGateway = gateway;
this.hostCidr = cidr; this.hostCidr = cidr;
@ -86,6 +91,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
this.primaryStorageUrl = primaryStorage; this.primaryStorageUrl = primaryStorage;
this.primaryStorageUuid = primaryStorageUuid; this.primaryStorageUuid = primaryStorageUuid;
this.imageInstallPath = imageInstallPath; this.imageInstallPath = imageInstallPath;
this.hypervisor = HypervisorType.getType(hypervisor);
this.setSecondaryStorage(secondaryStorage); this.setSecondaryStorage(secondaryStorage);
// set S3 parameters // set S3 parameters
this.s3AccessKey = s3_accessKey; this.s3AccessKey = s3_accessKey;
@ -180,5 +186,13 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
this.scriptPath = scriptPath; this.scriptPath = scriptPath;
} }
public HypervisorType getHypervisor() {
return hypervisor;
}
public void setHypervisor(HypervisorType hypervisor) {
this.hypervisor = hypervisor;
}
} }

View File

@ -50,6 +50,7 @@ import com.cloud.host.HostVO;
import com.cloud.host.Status.Event; import com.cloud.host.Status.Event;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.hypervisor.vmware.VmwareServerDiscoverer; import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
import com.cloud.hypervisor.xen.resource.XcpOssResource; import com.cloud.hypervisor.xen.resource.XcpOssResource;
import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResource;
@ -122,6 +123,16 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
logger.debug("Failed to load resource:" + e.toString()); logger.debug("Failed to load resource:" + e.toString());
} }
} else if (host.getHypervisorType() == HypervisorType.KVM) {
resource = new LibvirtComputingResource();
try {
params.put("public.network.device", "cloudbr0");
params.put("private.network.device", "cloudbr0");
resource.configure(host.getName(), params);
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (host.getHypervisorType() == HypervisorType.VMware) { } else if (host.getHypervisorType() == HypervisorType.VMware) {
ClusterVO cluster = clusterDao.findById(host.getClusterId()); ClusterVO cluster = clusterDao.findById(host.getClusterId());
String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue(); String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();

View File

@ -179,7 +179,7 @@ public class SnapshotTest extends CloudStackTestNGBase {
podId = pod.getId(); podId = pod.getId();
//create xen cluster //create xen cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster"); ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(HypervisorType.XenServer.toString()); cluster.setHypervisorType(this.getHypervisor().toString());
cluster.setClusterType(ClusterType.CloudManaged); cluster.setClusterType(ClusterType.CloudManaged);
cluster.setManagedState(ManagedState.Managed); cluster.setManagedState(ManagedState.Managed);
cluster = clusterDao.persist(cluster); cluster = clusterDao.persist(cluster);
@ -197,7 +197,7 @@ public class SnapshotTest extends CloudStackTestNGBase {
host.setPodId(podId); host.setPodId(podId);
host.setLastPinged(0); host.setLastPinged(0);
host.setResourceState(ResourceState.Enabled); host.setResourceState(ResourceState.Enabled);
host.setHypervisorType(HypervisorType.XenServer); host.setHypervisorType(this.getHypervisor());
host.setClusterId(cluster.getId()); host.setClusterId(cluster.getId());
host = hostDao.persist(host); host = hostDao.persist(host);

View File

@ -171,7 +171,7 @@ public class VolumeTest extends CloudStackTestNGBase {
podId = pod.getId(); podId = pod.getId();
//create xen cluster //create xen cluster
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster"); ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
cluster.setHypervisorType(HypervisorType.XenServer.toString()); cluster.setHypervisorType(this.getHypervisor().toString());
cluster.setClusterType(ClusterType.CloudManaged); cluster.setClusterType(ClusterType.CloudManaged);
cluster.setManagedState(ManagedState.Managed); cluster.setManagedState(ManagedState.Managed);
cluster = clusterDao.persist(cluster); cluster = clusterDao.persist(cluster);
@ -189,7 +189,7 @@ public class VolumeTest extends CloudStackTestNGBase {
host.setPodId(podId); host.setPodId(podId);
host.setLastPinged(0); host.setLastPinged(0);
host.setResourceState(ResourceState.Enabled); host.setResourceState(ResourceState.Enabled);
host.setHypervisorType(HypervisorType.XenServer); host.setHypervisorType(this.getHypervisor());
host.setClusterId(cluster.getId()); host.setClusterId(cluster.getId());
host = hostDao.persist(host); host = hostDao.persist(host);
@ -320,7 +320,7 @@ public class VolumeTest extends CloudStackTestNGBase {
return volume; return volume;
} }
//@Test @Test
public void testCopyBaseImage() { public void testCopyBaseImage() {
DataStore primaryStore = createPrimaryDataStore(); DataStore primaryStore = createPrimaryDataStore();
primaryStoreId = primaryStore.getId(); primaryStoreId = primaryStore.getId();

View File

@ -209,10 +209,6 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
@Override @Override
public boolean canHandle(Snapshot snapshot) { public boolean canHandle(Snapshot snapshot) {
if (snapshot.getHypervisorType() == HypervisorType.XenServer) { return true;
return true;
} else {
return false;
}
} }
} }

View File

@ -461,7 +461,7 @@ ServerResource {
} }
protected String getDefaultDomrScriptsDir() { protected String getDefaultDomrScriptsDir() {
return "scripts/network/domr/kvm"; return "scripts/network/domr";
} }
protected String getNetworkDirectSourceMode() { protected String getNetworkDirectSourceMode() {
@ -682,7 +682,7 @@ ServerResource {
_localStorageUUID = (String) params.get("local.storage.uuid"); _localStorageUUID = (String) params.get("local.storage.uuid");
if (_localStorageUUID == null) { if (_localStorageUUID == null) {
throw new ConfigurationException("local.storage.uuid is not set! Please set this to a valid UUID"); _localStorageUUID = UUID.nameUUIDFromBytes(_localStoragePath.getBytes()).toString();
} }
value = (String) params.get("scripts.timeout"); value = (String) params.get("scripts.timeout");

View File

@ -142,7 +142,7 @@ public class KVMStorageProcessor implements StorageProcessor {
DataTO destData = cmd.getDestTO(); DataTO destData = cmd.getDestTO();
TemplateObjectTO template = (TemplateObjectTO)srcData; TemplateObjectTO template = (TemplateObjectTO)srcData;
DataStoreTO imageStore = template.getDataStore(); DataStoreTO imageStore = template.getDataStore();
VolumeObjectTO volume = (VolumeObjectTO)destData; TemplateObjectTO volume = (TemplateObjectTO)destData;
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
if (!(imageStore instanceof NfsTO)) { if (!(imageStore instanceof NfsTO)) {
@ -195,10 +195,10 @@ public class KVMStorageProcessor implements StorageProcessor {
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk( KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(
tmplVol, UUID.randomUUID().toString(), primaryPool); tmplVol, UUID.randomUUID().toString(), primaryPool);
VolumeObjectTO newVol = new VolumeObjectTO(); TemplateObjectTO newTemplate = new TemplateObjectTO();
newVol.setPath(primaryVol.getName()); newTemplate.setPath(primaryVol.getName());
newVol.setSize(primaryVol.getSize()); newTemplate.setFormat(ImageFormat.QCOW2);
return new CopyCmdAnswer(newVol); return new CopyCmdAnswer(newTemplate);
} catch (CloudRuntimeException e) { } catch (CloudRuntimeException e) {
return new CopyCmdAnswer(e.toString()); return new CopyCmdAnswer(e.toString());
} finally { } finally {
@ -273,14 +273,7 @@ public class KVMStorageProcessor implements StorageProcessor {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
primaryStore.getUuid()); primaryStore.getUuid());
String templatePath = null; String templatePath = template.getPath();
if (imageStore instanceof NfsTO) {
NfsTO nfsImageStore = (NfsTO)imageStore;
templatePath = nfsImageStore.getUrl();
} else {
s_logger.debug("Failed to create volume: ");
return new CopyCmdAnswer("Unsupported protocol");
}
if(primaryPool.getType() == StoragePoolType.CLVM) { if(primaryPool.getType() == StoragePoolType.CLVM) {
vol = templateToPrimaryDownload(templatePath, primaryPool); vol = templateToPrimaryDownload(templatePath, primaryPool);
@ -321,9 +314,9 @@ public class KVMStorageProcessor implements StorageProcessor {
DataTO srcData = cmd.getSrcTO(); DataTO srcData = cmd.getSrcTO();
DataTO destData = cmd.getDestTO(); DataTO destData = cmd.getDestTO();
int wait = cmd.getWait(); int wait = cmd.getWait();
TemplateObjectTO template = (TemplateObjectTO)srcData; TemplateObjectTO template = (TemplateObjectTO)destData;
DataStoreTO imageStore = template.getDataStore(); DataStoreTO imageStore = template.getDataStore();
VolumeObjectTO volume = (VolumeObjectTO)destData; VolumeObjectTO volume = (VolumeObjectTO)srcData;
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
if (!(imageStore instanceof NfsTO)) { if (!(imageStore instanceof NfsTO)) {
@ -425,7 +418,7 @@ public class KVMStorageProcessor implements StorageProcessor {
loc.save(); loc.save();
TemplateObjectTO newTemplate = new TemplateObjectTO(); TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(templateFolder + templateName + ".qcow2"); newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2");
return new CopyCmdAnswer(newTemplate); return new CopyCmdAnswer(newTemplate);
} catch (Exception e) { } catch (Exception e) {
s_logger.debug("Failed to create template from volume: " + e.toString()); s_logger.debug("Failed to create template from volume: " + e.toString());
@ -783,8 +776,9 @@ public class KVMStorageProcessor implements StorageProcessor {
@Override @Override
public Answer createSnapshot(CreateObjectCommand cmd) { public Answer createSnapshot(CreateObjectCommand cmd) {
VolumeObjectTO volume = (VolumeObjectTO)cmd.getData(); SnapshotObjectTO snapshotTO = (SnapshotObjectTO)cmd.getData();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)snapshotTO.getDataStore();
VolumeObjectTO volume = snapshotTO.getVolume();
String snapshotName = UUID.randomUUID().toString(); String snapshotName = UUID.randomUUID().toString();
String vmName = volume.getVmName(); String vmName = volume.getVmName();
try { try {

View File

@ -48,7 +48,7 @@ is_lv() {
# And a logical volume # And a logical volume
lvm lvs "${1}" > /dev/null 2>&1 && return 0 lvm lvs "${1}" > /dev/null 2>&1 && return 0
fi fi
return 1 return 0
} }
get_vg() { get_vg() {

View File

@ -450,7 +450,15 @@ public class Script implements Callable<String> {
} }
file = new File(System.getProperty("paths.script") + File.separator + path + File.separator + script); search = System.getProperty("paths.script");
search += File.separatorChar + path + File.separator;
do {
search = search.substring(0, search.lastIndexOf(File.separator));
file = new File(search + File.separator + script);
s_logger.debug("Looking for " + script + " in " + file.getAbsolutePath());
} while (!file.exists() && search.lastIndexOf(File.separator) != -1);
if (file.exists()) { if (file.exists()) {
return file.getAbsolutePath(); return file.getAbsolutePath();
} }