Skip to content

Commit dffb430

Browse files
nvazquezyadvr
authored andcommitted
kvm: Fix migrating VM from ISO failures (#2928)
Prevents errors while migrating VM from ISO: Test 1: Deploy VM from ISO -> Live migrate VM to another host -> ERROR Test 2: Register ISO using Direct Download on KVM -> Deploy VM from ISO -> Live migrate VM to another host -> ERROR - Prevent NullPointerException migrating VM from ISO - Prevent mount secondary storage on ISO direct downloads on KVM
1 parent f0491d5 commit dffb430

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class TemplateObjectTO implements DataTO {
4646
private Hypervisor.HypervisorType hypervisorType;
4747
private boolean bootable;
4848
private String uniqueName;
49+
private boolean directDownload;
4950

5051
public TemplateObjectTO() {
5152

@@ -235,6 +236,14 @@ public void setUniqueName(String uniqueName) {
235236
this.uniqueName = uniqueName;
236237
}
237238

239+
public boolean isDirectDownload() {
240+
return directDownload;
241+
}
242+
243+
public void setDirectDownload(boolean directDownload) {
244+
this.directDownload = directDownload;
245+
}
246+
238247
@Override
239248
public String toString() {
240249
return new StringBuilder("TemplateTO[id=").append(id).append("|origUrl=").append(origUrl).append("|name").append(name).append("]").toString();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
import com.cloud.resource.RequestWrapper;
5151
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
52+
import org.apache.cloudstack.storage.to.TemplateObjectTO;
5253
import org.apache.cloudstack.storage.to.VolumeObjectTO;
5354
import org.apache.cloudstack.utils.hypervisor.HypervisorUtils;
5455
import org.apache.cloudstack.utils.linux.CPUStat;
@@ -2209,7 +2210,8 @@ public String getVolumePath(final Connect conn, final DiskTO volume) throws Libv
22092210
final DataTO data = volume.getData();
22102211
final DataStoreTO store = data.getDataStore();
22112212

2212-
if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO || store instanceof PrimaryDataStoreTO)) {
2213+
if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO ||
2214+
store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) {
22132215
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
22142216
final int index = isoPath.lastIndexOf("/");
22152217
final String path = isoPath.substring(0, index);

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
5151
import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
5252
import org.apache.commons.collections.CollectionUtils;
53+
import org.apache.commons.collections.MapUtils;
5354
import org.apache.log4j.Logger;
5455
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
5556
import org.apache.cloudstack.api.ApiConstants;
@@ -557,11 +558,13 @@ public void prepareIsoForVmProfile(VirtualMachineProfile profile, DeployDestinat
557558
if (vm.getIsoId() != null) {
558559
Map<Volume, StoragePool> storageForDisks = dest.getStorageForDisks();
559560
Long poolId = null;
560-
for (StoragePool storagePool : storageForDisks.values()) {
561-
if (poolId != null && storagePool.getId() != poolId) {
562-
throw new CloudRuntimeException("Cannot determine where to download iso");
561+
if (MapUtils.isNotEmpty(storageForDisks)) {
562+
for (StoragePool storagePool : storageForDisks.values()) {
563+
if (poolId != null && storagePool.getId() != poolId) {
564+
throw new CloudRuntimeException("Cannot determine where to download iso");
565+
}
566+
poolId = storagePool.getId();
563567
}
564-
poolId = storagePool.getId();
565568
}
566569
TemplateInfo template = prepareIso(vm.getIsoId(), vm.getDataCenterId(), dest.getHost().getId(), poolId);
567570
if (template == null){
@@ -579,6 +582,7 @@ public void prepareIsoForVmProfile(VirtualMachineProfile profile, DeployDestinat
579582
}
580583

581584
TemplateObjectTO iso = (TemplateObjectTO)template.getTO();
585+
iso.setDirectDownload(template.isDirectDownload());
582586
iso.setGuestOsType(displayName);
583587
DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
584588
profile.addDisk(disk);

0 commit comments

Comments
 (0)