Vered Volansky has uploaded a new change for review.

Change subject: restapi: Fix NPE when live migrating a disk
......................................................................

restapi: Fix NPE when live migrating a disk

Empty Guid was passed as source domain id to the MoveDisksCommand when
live migrating a disk. This is fixed and the actual source domain is
extracted from the disk entity and passed to the command.
This was mocked out in BackendVmDiskResourceTest.

Change-Id: I570a4c81605b63a860c012e9071e46c34c793635
Bug-Url: https://bugzilla.redhat.com/1103499
Signed-off-by: Vered Volansky <vvola...@redhat.com>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendActionableResource.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDisksResourceTest.java
3 files changed, 16 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/30975/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendActionableResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendActionableResource.java
index a322dc7..ea1c538 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendActionableResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendActionableResource.java
@@ -208,6 +208,10 @@
         }
     }
 
+    protected VDSGroup lookupClusterByName(String name) {
+        return getEntity(VDSGroup.class, VdcQueryType.GetVdsGroupByName, new 
NameQueryParameters(name), "Cluster: name=" + name);
+    }
+
     protected Guid getClusterId(Action action) {
         if (action.getCluster().isSetId()) {
             return asGuid(action.getCluster().getId());
@@ -215,10 +219,6 @@
             VDSGroup cluster = 
lookupClusterByName(action.getCluster().getName());
             return cluster != null ? cluster.getId() : null;
         }
-    }
-
-    protected VDSGroup lookupClusterByName(String name) {
-        return getEntity(VDSGroup.class, VdcQueryType.GetVdsGroupByName, new 
NameQueryParameters(name), "Cluster: name=" + name);
     }
 
     protected Guid lookupStorageDomainIdByName(String name) {
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java
index 2f3da7a..41671e4 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmDiskResource.java
@@ -90,11 +90,13 @@
     public Response move(Action action) {
         validateParameters(action, "storageDomain.id|name");
         Guid storageDomainId = getStorageDomainId(action);
-        Guid imageId = asGuid(getDisk().getImageId());
+        Disk disk = getDisk();
+        Guid sourceStorageDomainId = getSourceStorageDomainId(disk);
+        Guid imageId = asGuid(disk.getImageId());
         MoveDisksParameters params =
                 new MoveDisksParameters(Collections.singletonList(new 
MoveDiskParameters(
                         imageId,
-                        Guid.Empty,
+                        sourceStorageDomainId,
                         storageDomainId)));
         return doAction(VdcActionType.MoveDisks, params, action);
     }
@@ -103,6 +105,10 @@
         return performGet(VdcQueryType.GetDiskByDiskId, new 
IdQueryParameters(guid));
     }
 
+    protected Guid getSourceStorageDomainId(Disk disk) {
+        return 
asGuid(disk.getStorageDomains().getStorageDomains().get(0).getId());
+    }
+
     @Override
     public Disk get() {
         return super.get();//explicit call solves REST-Easy confusion
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDisksResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDisksResourceTest.java
index 60d2681..68b8967 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDisksResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/AbstractBackendDisksResourceTest.java
@@ -107,6 +107,10 @@
         
expect(entity.getDiskStorageType()).andReturn(DiskStorageType.IMAGE).anyTimes();
         expect(entity.getImageId()).andReturn(GUIDS[1]).anyTimes();
         expect(entity.getReadOnly()).andReturn(true).anyTimes();
+        ArrayList<Guid> sdIds = new ArrayList<>();
+        sdIds.add(Guid.Empty);
+        expect(entity.getStorageIds()).andReturn(sdIds).anyTimes();
+
         return setUpStatisticalEntityExpectations(entity);
     }
 


-- 
To view, visit http://gerrit.ovirt.org/30975
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I570a4c81605b63a860c012e9071e46c34c793635
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Vered Volansky <vvola...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to