Skip to content

Commit 492127c

Browse files
author
Edison Su
committed
fix kvm
1 parent 0b9e0c0 commit 492127c

10 files changed

Lines changed: 63 additions & 34 deletions

File tree

engine/storage/integration-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
<artifactId>cloud-plugin-hypervisor-vmware</artifactId>
6868
<version>${project.version}</version>
6969
<scope>test</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.apache.cloudstack</groupId>
73+
<artifactId>cloud-plugin-hypervisor-kvm</artifactId>
74+
<version>${project.version}</version>
75+
<scope>test</scope>
7076
</dependency>
7177
<dependency>
7278
<groupId>org.apache.cloudstack</groupId>

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.testng.annotations.Parameters;
2525
import org.testng.annotations.Test;
2626

27+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2728
import com.cloud.utils.db.DB;
2829
import com.cloud.utils.db.Transaction;
2930

@@ -38,6 +39,7 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
3839
private String secondaryStorage;
3940
private String imageInstallPath;
4041
private String scriptPath;
42+
private HypervisorType hypervisor;
4143
private Transaction txn;
4244

4345
private String s3AccessKey;
@@ -72,11 +74,14 @@ protected void closeDB(Method testMethod) throws Exception {
7274

7375
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr",
7476
"devcloud-host-ip", "template-url", "devcloud-local-storage-uuid",
75-
"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"})
77+
"primary-storage-want-to-add", "devcloud-secondary-storage", "s3-accesskey", "s3-secretkey", "s3-endpoint",
78+
"s3-template-bucket", "s3-usehttps", "image-install-path", "primary-storage-uuid-want-to-add", "script-path",
79+
"hypervisor"})
7680
protected void setup(String hostuuid, String gateway, String cidr,
7781
String hostIp, String templateUrl, String localStorageUuid,
7882
String primaryStorage, String secondaryStorage, String s3_accessKey, String s3_secretKey, String s3_endpoint, String s3_template_bucket,
79-
String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath) {
83+
String s3_usehttps, String imageInstallPath, String primaryStorageUuid, String scriptPath,
84+
String hypervisor) {
8085
this.hostGuid = hostuuid;
8186
this.hostGateway = gateway;
8287
this.hostCidr = cidr;
@@ -86,6 +91,7 @@ protected void setup(String hostuuid, String gateway, String cidr,
8691
this.primaryStorageUrl = primaryStorage;
8792
this.primaryStorageUuid = primaryStorageUuid;
8893
this.imageInstallPath = imageInstallPath;
94+
this.hypervisor = HypervisorType.getType(hypervisor);
8995
this.setSecondaryStorage(secondaryStorage);
9096
// set S3 parameters
9197
this.s3AccessKey = s3_accessKey;
@@ -180,5 +186,13 @@ public void setScriptPath(String scriptPath) {
180186
this.scriptPath = scriptPath;
181187
}
182188

189+
public HypervisorType getHypervisor() {
190+
return hypervisor;
191+
}
192+
193+
public void setHypervisor(HypervisorType hypervisor) {
194+
this.hypervisor = hypervisor;
195+
}
196+
183197

184198
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.host.Status.Event;
5151
import com.cloud.host.dao.HostDao;
5252
import com.cloud.hypervisor.Hypervisor.HypervisorType;
53+
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
5354
import com.cloud.hypervisor.vmware.VmwareServerDiscoverer;
5455
import com.cloud.hypervisor.xen.resource.XcpOssResource;
5556
import com.cloud.resource.ServerResource;
@@ -122,6 +123,16 @@ protected void loadResource(Long hostId) {
122123
} catch (ConfigurationException e) {
123124
logger.debug("Failed to load resource:" + e.toString());
124125
}
126+
} else if (host.getHypervisorType() == HypervisorType.KVM) {
127+
resource = new LibvirtComputingResource();
128+
try {
129+
params.put("public.network.device", "cloudbr0");
130+
params.put("private.network.device", "cloudbr0");
131+
resource.configure(host.getName(), params);
132+
} catch (ConfigurationException e) {
133+
// TODO Auto-generated catch block
134+
e.printStackTrace();
135+
}
125136
} else if (host.getHypervisorType() == HypervisorType.VMware) {
126137
ClusterVO cluster = clusterDao.findById(host.getClusterId());
127138
String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void setUp() {
179179
podId = pod.getId();
180180
//create xen cluster
181181
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
182-
cluster.setHypervisorType(HypervisorType.XenServer.toString());
182+
cluster.setHypervisorType(this.getHypervisor().toString());
183183
cluster.setClusterType(ClusterType.CloudManaged);
184184
cluster.setManagedState(ManagedState.Managed);
185185
cluster = clusterDao.persist(cluster);
@@ -197,7 +197,7 @@ public void setUp() {
197197
host.setPodId(podId);
198198
host.setLastPinged(0);
199199
host.setResourceState(ResourceState.Enabled);
200-
host.setHypervisorType(HypervisorType.XenServer);
200+
host.setHypervisorType(this.getHypervisor());
201201
host.setClusterId(cluster.getId());
202202

203203
host = hostDao.persist(host);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void setUp() {
171171
podId = pod.getId();
172172
//create xen cluster
173173
ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
174-
cluster.setHypervisorType(HypervisorType.XenServer.toString());
174+
cluster.setHypervisorType(this.getHypervisor().toString());
175175
cluster.setClusterType(ClusterType.CloudManaged);
176176
cluster.setManagedState(ManagedState.Managed);
177177
cluster = clusterDao.persist(cluster);
@@ -189,7 +189,7 @@ public void setUp() {
189189
host.setPodId(podId);
190190
host.setLastPinged(0);
191191
host.setResourceState(ResourceState.Enabled);
192-
host.setHypervisorType(HypervisorType.XenServer);
192+
host.setHypervisorType(this.getHypervisor());
193193
host.setClusterId(cluster.getId());
194194

195195
host = hostDao.persist(host);
@@ -320,7 +320,7 @@ private VolumeVO createVolume(Long templateId, long dataStoreId) {
320320
return volume;
321321
}
322322

323-
//@Test
323+
@Test
324324
public void testCopyBaseImage() {
325325
DataStore primaryStore = createPrimaryDataStore();
326326
primaryStoreId = primaryStore.getId();

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) {
209209

210210
@Override
211211
public boolean canHandle(Snapshot snapshot) {
212-
if (snapshot.getHypervisorType() == HypervisorType.XenServer) {
213-
return true;
214-
} else {
215-
return false;
216-
}
212+
return true;
217213
}
218214
}

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ protected String getDefaultKvmScriptsDir() {
461461
}
462462

463463
protected String getDefaultDomrScriptsDir() {
464-
return "scripts/network/domr/kvm";
464+
return "scripts/network/domr";
465465
}
466466

467467
protected String getNetworkDirectSourceMode() {
@@ -682,7 +682,7 @@ public boolean configure(String name, Map<String, Object> params)
682682

683683
_localStorageUUID = (String) params.get("local.storage.uuid");
684684
if (_localStorageUUID == null) {
685-
throw new ConfigurationException("local.storage.uuid is not set! Please set this to a valid UUID");
685+
_localStorageUUID = UUID.nameUUIDFromBytes(_localStoragePath.getBytes()).toString();
686686
}
687687

688688
value = (String) params.get("scripts.timeout");

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
142142
DataTO destData = cmd.getDestTO();
143143
TemplateObjectTO template = (TemplateObjectTO)srcData;
144144
DataStoreTO imageStore = template.getDataStore();
145-
VolumeObjectTO volume = (VolumeObjectTO)destData;
145+
TemplateObjectTO volume = (TemplateObjectTO)destData;
146146
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
147147

148148
if (!(imageStore instanceof NfsTO)) {
@@ -195,10 +195,10 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
195195
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(
196196
tmplVol, UUID.randomUUID().toString(), primaryPool);
197197

198-
VolumeObjectTO newVol = new VolumeObjectTO();
199-
newVol.setPath(primaryVol.getName());
200-
newVol.setSize(primaryVol.getSize());
201-
return new CopyCmdAnswer(newVol);
198+
TemplateObjectTO newTemplate = new TemplateObjectTO();
199+
newTemplate.setPath(primaryVol.getName());
200+
newTemplate.setFormat(ImageFormat.QCOW2);
201+
return new CopyCmdAnswer(newTemplate);
202202
} catch (CloudRuntimeException e) {
203203
return new CopyCmdAnswer(e.toString());
204204
} finally {
@@ -273,14 +273,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
273273
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(),
274274
primaryStore.getUuid());
275275

276-
String templatePath = null;
277-
if (imageStore instanceof NfsTO) {
278-
NfsTO nfsImageStore = (NfsTO)imageStore;
279-
templatePath = nfsImageStore.getUrl();
280-
} else {
281-
s_logger.debug("Failed to create volume: ");
282-
return new CopyCmdAnswer("Unsupported protocol");
283-
}
276+
String templatePath = template.getPath();
284277

285278
if(primaryPool.getType() == StoragePoolType.CLVM) {
286279
vol = templateToPrimaryDownload(templatePath, primaryPool);
@@ -321,9 +314,9 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
321314
DataTO srcData = cmd.getSrcTO();
322315
DataTO destData = cmd.getDestTO();
323316
int wait = cmd.getWait();
324-
TemplateObjectTO template = (TemplateObjectTO)srcData;
317+
TemplateObjectTO template = (TemplateObjectTO)destData;
325318
DataStoreTO imageStore = template.getDataStore();
326-
VolumeObjectTO volume = (VolumeObjectTO)destData;
319+
VolumeObjectTO volume = (VolumeObjectTO)srcData;
327320
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
328321

329322
if (!(imageStore instanceof NfsTO)) {
@@ -425,7 +418,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
425418
loc.save();
426419

427420
TemplateObjectTO newTemplate = new TemplateObjectTO();
428-
newTemplate.setPath(templateFolder + templateName + ".qcow2");
421+
newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2");
429422
return new CopyCmdAnswer(newTemplate);
430423
} catch (Exception e) {
431424
s_logger.debug("Failed to create template from volume: " + e.toString());
@@ -783,8 +776,9 @@ public Answer createVolume(CreateObjectCommand cmd) {
783776

784777
@Override
785778
public Answer createSnapshot(CreateObjectCommand cmd) {
786-
VolumeObjectTO volume = (VolumeObjectTO)cmd.getData();
787-
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore();
779+
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)cmd.getData();
780+
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)snapshotTO.getDataStore();
781+
VolumeObjectTO volume = snapshotTO.getVolume();
788782
String snapshotName = UUID.randomUUID().toString();
789783
String vmName = volume.getVmName();
790784
try {

scripts/storage/qcow2/managesnapshot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ is_lv() {
4848
# And a logical volume
4949
lvm lvs "${1}" > /dev/null 2>&1 && return 0
5050
fi
51-
return 1
51+
return 0
5252
}
5353

5454
get_vg() {

utils/src/com/cloud/utils/script/Script.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,15 @@ public static String findScript(String path, String script) {
450450

451451
}
452452

453-
file = new File(System.getProperty("paths.script") + File.separator + path + File.separator + script);
453+
search = System.getProperty("paths.script");
454+
455+
search += File.separatorChar + path + File.separator;
456+
do {
457+
search = search.substring(0, search.lastIndexOf(File.separator));
458+
file = new File(search + File.separator + script);
459+
s_logger.debug("Looking for " + script + " in " + file.getAbsolutePath());
460+
} while (!file.exists() && search.lastIndexOf(File.separator) != -1);
461+
454462
if (file.exists()) {
455463
return file.getAbsolutePath();
456464
}

0 commit comments

Comments
 (0)