Updated Branches: refs/heads/object_store 0b9e0c0f3 -> 492127c03
fix kvm Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/492127c0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/492127c0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/492127c0 Branch: refs/heads/object_store Commit: 492127c035ceddf9f71c70ba4a9c6f2894cc8319 Parents: 0b9e0c0 Author: Edison Su <edison...@citrix.com> Authored: Sun May 12 18:27:25 2013 -0700 Committer: Edison Su <edison...@citrix.com> Committed: Sun May 12 18:27:37 2013 -0700 ---------------------------------------------------------------------- engine/storage/integration-test/pom.xml | 6 +++ .../storage/test/CloudStackTestNGBase.java | 18 ++++++++- .../storage/test/DirectAgentManagerSimpleImpl.java | 11 +++++ .../cloudstack/storage/test/SnapshotTest.java | 4 +- .../apache/cloudstack/storage/test/VolumeTest.java | 6 +- .../snapshot/XenserverSnapshotStrategy.java | 6 +-- .../kvm/resource/LibvirtComputingResource.java | 4 +- .../kvm/storage/KVMStorageProcessor.java | 30 ++++++--------- scripts/storage/qcow2/managesnapshot.sh | 2 +- utils/src/com/cloud/utils/script/Script.java | 10 ++++- 10 files changed, 63 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/integration-test/pom.xml ---------------------------------------------------------------------- diff --git a/engine/storage/integration-test/pom.xml b/engine/storage/integration-test/pom.xml index 56d36ad..8a9dc15 100644 --- a/engine/storage/integration-test/pom.xml +++ b/engine/storage/integration-test/pom.xml @@ -68,6 +68,12 @@ <version>${project.version}</version> <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> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-plugin-storage-volume-default</artifactId> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java ---------------------------------------------------------------------- diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java index 77b6ec3..726ea01 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java @@ -24,6 +24,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Parameters; import org.testng.annotations.Test; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; @@ -38,6 +39,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests { private String secondaryStorage; private String imageInstallPath; private String scriptPath; + private HypervisorType hypervisor; private Transaction txn; private String s3AccessKey; @@ -72,11 +74,14 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests { @Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr", "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, String hostIp, String templateUrl, String localStorageUuid, 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.hostGateway = gateway; this.hostCidr = cidr; @@ -86,6 +91,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests { this.primaryStorageUrl = primaryStorage; this.primaryStorageUuid = primaryStorageUuid; this.imageInstallPath = imageInstallPath; + this.hypervisor = HypervisorType.getType(hypervisor); this.setSecondaryStorage(secondaryStorage); // set S3 parameters this.s3AccessKey = s3_accessKey; @@ -180,5 +186,13 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests { this.scriptPath = scriptPath; } + public HypervisorType getHypervisor() { + return hypervisor; + } + + public void setHypervisor(HypervisorType hypervisor) { + this.hypervisor = hypervisor; + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java index ac5a69d..c11da3d 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java @@ -50,6 +50,7 @@ import com.cloud.host.HostVO; import com.cloud.host.Status.Event; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; import com.cloud.hypervisor.vmware.VmwareServerDiscoverer; import com.cloud.hypervisor.xen.resource.XcpOssResource; import com.cloud.resource.ServerResource; @@ -122,6 +123,16 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa } catch (ConfigurationException e) { 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) { ClusterVO cluster = clusterDao.findById(host.getClusterId()); String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java ---------------------------------------------------------------------- diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java index e772c82..d667a78 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java @@ -179,7 +179,7 @@ public class SnapshotTest extends CloudStackTestNGBase { podId = pod.getId(); //create xen 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.setManagedState(ManagedState.Managed); cluster = clusterDao.persist(cluster); @@ -197,7 +197,7 @@ public class SnapshotTest extends CloudStackTestNGBase { host.setPodId(podId); host.setLastPinged(0); host.setResourceState(ResourceState.Enabled); - host.setHypervisorType(HypervisorType.XenServer); + host.setHypervisorType(this.getHypervisor()); host.setClusterId(cluster.getId()); host = hostDao.persist(host); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java ---------------------------------------------------------------------- diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java index c610e50..76ce404 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java @@ -171,7 +171,7 @@ public class VolumeTest extends CloudStackTestNGBase { podId = pod.getId(); //create xen 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.setManagedState(ManagedState.Managed); cluster = clusterDao.persist(cluster); @@ -189,7 +189,7 @@ public class VolumeTest extends CloudStackTestNGBase { host.setPodId(podId); host.setLastPinged(0); host.setResourceState(ResourceState.Enabled); - host.setHypervisorType(HypervisorType.XenServer); + host.setHypervisorType(this.getHypervisor()); host.setClusterId(cluster.getId()); host = hostDao.persist(host); @@ -320,7 +320,7 @@ public class VolumeTest extends CloudStackTestNGBase { return volume; } - //@Test + @Test public void testCopyBaseImage() { DataStore primaryStore = createPrimaryDataStore(); primaryStoreId = primaryStore.getId(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java index 171de4c..072d14b 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java @@ -209,10 +209,6 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase { @Override public boolean canHandle(Snapshot snapshot) { - if (snapshot.getHypervisorType() == HypervisorType.XenServer) { - return true; - } else { - return false; - } + return true; } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index a32d0cc..747f337 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -461,7 +461,7 @@ ServerResource { } protected String getDefaultDomrScriptsDir() { - return "scripts/network/domr/kvm"; + return "scripts/network/domr"; } protected String getNetworkDirectSourceMode() { @@ -682,7 +682,7 @@ ServerResource { _localStorageUUID = (String) params.get("local.storage.uuid"); 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"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index c3fc0ec..3bdf428 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -142,7 +142,7 @@ public class KVMStorageProcessor implements StorageProcessor { DataTO destData = cmd.getDestTO(); TemplateObjectTO template = (TemplateObjectTO)srcData; DataStoreTO imageStore = template.getDataStore(); - VolumeObjectTO volume = (VolumeObjectTO)destData; + TemplateObjectTO volume = (TemplateObjectTO)destData; PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); if (!(imageStore instanceof NfsTO)) { @@ -195,10 +195,10 @@ public class KVMStorageProcessor implements StorageProcessor { KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk( tmplVol, UUID.randomUUID().toString(), primaryPool); - VolumeObjectTO newVol = new VolumeObjectTO(); - newVol.setPath(primaryVol.getName()); - newVol.setSize(primaryVol.getSize()); - return new CopyCmdAnswer(newVol); + TemplateObjectTO newTemplate = new TemplateObjectTO(); + newTemplate.setPath(primaryVol.getName()); + newTemplate.setFormat(ImageFormat.QCOW2); + return new CopyCmdAnswer(newTemplate); } catch (CloudRuntimeException e) { return new CopyCmdAnswer(e.toString()); } finally { @@ -273,14 +273,7 @@ public class KVMStorageProcessor implements StorageProcessor { primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); - String templatePath = null; - if (imageStore instanceof NfsTO) { - NfsTO nfsImageStore = (NfsTO)imageStore; - templatePath = nfsImageStore.getUrl(); - } else { - s_logger.debug("Failed to create volume: "); - return new CopyCmdAnswer("Unsupported protocol"); - } + String templatePath = template.getPath(); if(primaryPool.getType() == StoragePoolType.CLVM) { vol = templateToPrimaryDownload(templatePath, primaryPool); @@ -321,9 +314,9 @@ public class KVMStorageProcessor implements StorageProcessor { DataTO srcData = cmd.getSrcTO(); DataTO destData = cmd.getDestTO(); int wait = cmd.getWait(); - TemplateObjectTO template = (TemplateObjectTO)srcData; + TemplateObjectTO template = (TemplateObjectTO)destData; DataStoreTO imageStore = template.getDataStore(); - VolumeObjectTO volume = (VolumeObjectTO)destData; + VolumeObjectTO volume = (VolumeObjectTO)srcData; PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); if (!(imageStore instanceof NfsTO)) { @@ -425,7 +418,7 @@ public class KVMStorageProcessor implements StorageProcessor { loc.save(); TemplateObjectTO newTemplate = new TemplateObjectTO(); - newTemplate.setPath(templateFolder + templateName + ".qcow2"); + newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2"); return new CopyCmdAnswer(newTemplate); } catch (Exception e) { s_logger.debug("Failed to create template from volume: " + e.toString()); @@ -783,8 +776,9 @@ public class KVMStorageProcessor implements StorageProcessor { @Override public Answer createSnapshot(CreateObjectCommand cmd) { - VolumeObjectTO volume = (VolumeObjectTO)cmd.getData(); - PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); + SnapshotObjectTO snapshotTO = (SnapshotObjectTO)cmd.getData(); + PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)snapshotTO.getDataStore(); + VolumeObjectTO volume = snapshotTO.getVolume(); String snapshotName = UUID.randomUUID().toString(); String vmName = volume.getVmName(); try { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/scripts/storage/qcow2/managesnapshot.sh ---------------------------------------------------------------------- diff --git a/scripts/storage/qcow2/managesnapshot.sh b/scripts/storage/qcow2/managesnapshot.sh index 29b7081..30148de 100755 --- a/scripts/storage/qcow2/managesnapshot.sh +++ b/scripts/storage/qcow2/managesnapshot.sh @@ -48,7 +48,7 @@ is_lv() { # And a logical volume lvm lvs "${1}" > /dev/null 2>&1 && return 0 fi - return 1 + return 0 } get_vg() { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/492127c0/utils/src/com/cloud/utils/script/Script.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index 3632bf5..d3a3591 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -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()) { return file.getAbsolutePath(); }