cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ro...@apache.org
Subject [cloudstack] branch 4.11 updated: kvm: Fix migrating VM from ISO failures (#2928)
Date Mon, 29 Oct 2018 10:44:26 GMT
This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.11
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.11 by this push:
     new dffb430  kvm: Fix migrating VM from ISO failures (#2928)
dffb430 is described below

commit dffb4309750517ced063008ccee7907cb85f86ba
Author: Nicolas Vazquez <nicovazquez90@gmail.com>
AuthorDate: Mon Oct 29 07:44:20 2018 -0300

    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
---
 .../org/apache/cloudstack/storage/to/TemplateObjectTO.java   |  9 +++++++++
 .../hypervisor/kvm/resource/LibvirtComputingResource.java    |  4 +++-
 server/src/com/cloud/template/TemplateManagerImpl.java       | 12 ++++++++----
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java b/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
index 4a3d058..cc2eaad 100644
--- a/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
+++ b/core/src/org/apache/cloudstack/storage/to/TemplateObjectTO.java
@@ -46,6 +46,7 @@ public class TemplateObjectTO implements DataTO {
     private Hypervisor.HypervisorType hypervisorType;
     private boolean bootable;
     private String uniqueName;
+    private boolean directDownload;
 
     public TemplateObjectTO() {
 
@@ -235,6 +236,14 @@ public class TemplateObjectTO implements DataTO {
         this.uniqueName = uniqueName;
     }
 
+    public boolean isDirectDownload() {
+        return directDownload;
+    }
+
+    public void setDirectDownload(boolean directDownload) {
+        this.directDownload = directDownload;
+    }
+
     @Override
     public String toString() {
         return new StringBuilder("TemplateTO[id=").append(id).append("|origUrl=").append(origUrl).append("|name").append(name).append("]").toString();
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 8a94b05..652f643 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -49,6 +49,7 @@ import javax.xml.parsers.ParserConfigurationException;
 
 import com.cloud.resource.RequestWrapper;
 import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.cloudstack.utils.hypervisor.HypervisorUtils;
 import org.apache.cloudstack.utils.linux.CPUStat;
@@ -2209,7 +2210,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         final DataTO data = volume.getData();
         final DataStoreTO store = data.getDataStore();
 
-        if (volume.getType() == Volume.Type.ISO && data.getPath() != null &&
(store instanceof NfsTO || store instanceof PrimaryDataStoreTO)) {
+        if (volume.getType() == Volume.Type.ISO && data.getPath() != null &&
(store instanceof NfsTO ||
+                store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO
&& !((TemplateObjectTO) data).isDirectDownload())) {
             final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
             final int index = isoPath.lastIndexOf("/");
             final String path = isoPath.substring(0, index);
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 42bdd72..48cc6f4 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -50,6 +50,7 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
 import org.apache.log4j.Logger;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.api.ApiConstants;
@@ -557,11 +558,13 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         if (vm.getIsoId() != null) {
             Map<Volume, StoragePool> storageForDisks = dest.getStorageForDisks();
             Long poolId = null;
-            for (StoragePool storagePool : storageForDisks.values()) {
-                if (poolId != null && storagePool.getId() != poolId) {
-                    throw new CloudRuntimeException("Cannot determine where to download iso");
+            if (MapUtils.isNotEmpty(storageForDisks)) {
+                for (StoragePool storagePool : storageForDisks.values()) {
+                    if (poolId != null && storagePool.getId() != poolId) {
+                        throw new CloudRuntimeException("Cannot determine where to download
iso");
+                    }
+                    poolId = storagePool.getId();
                 }
-                poolId = storagePool.getId();
             }
             TemplateInfo template = prepareIso(vm.getIsoId(), vm.getDataCenterId(), dest.getHost().getId(),
poolId);
             if (template == null){
@@ -579,6 +582,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             }
 
             TemplateObjectTO iso = (TemplateObjectTO)template.getTO();
+            iso.setDirectDownload(template.isDirectDownload());
             iso.setGuestOsType(displayName);
             DiskTO disk = new DiskTO(iso, 3L, null, Volume.Type.ISO);
             profile.addDisk(disk);


Mime
View raw message