Vitor de Lima has uploaded a new change for review.

Change subject: core, engine: Fix balloon detection during VM import
......................................................................

core, engine: Fix balloon detection during VM import

The canDoAction method of the ImportVmCommand was not properly checking
for the presence of ballooning devices and always blocked the importing
of ppc64 VMs. This patch fixes this issue.

Change-Id: If660e368d7ec31ff1f8251d483971ffbf0bd858a
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1152560
Signed-off-by: Vitor de Lima <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVMFromConfigurationCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
4 files changed, 42 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/83/34383/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 9a3c6c4..c83e241 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -60,6 +60,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.VmStatistics;
@@ -79,6 +80,7 @@
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
+import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.validation.group.ImportClonedEntity;
 import org.ovirt.engine.core.common.validation.group.ImportEntity;
 import 
org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters;
@@ -209,8 +211,17 @@
             }
         }
 
+        boolean hasBalloon = false;
+
+        for (VmDevice vmDevice : getVm().getManagedVmDeviceMap().values()) {
+            if (VmDeviceCommonUtils.isMemoryBalloon(vmDevice)) {
+                hasBalloon = true;
+                break;
+            }
+        }
+
         OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
-        if (getVm().isBalloonEnabled() && 
!osRepository.isBalloonEnabled(getVm().getStaticData().getOsId(),
+        if (hasBalloon && 
!osRepository.isBalloonEnabled(getVm().getStaticData().getOsId(),
                 getVdsGroup().getcompatibility_version())) {
             addCanDoActionMessageVariable("clusterArch", 
getVdsGroup().getArchitecture());
             return 
failCanDoAction(VdcBllMessages.BALLOON_REQUESTED_ON_NOT_SUPPORTED_ARCH);
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVMFromConfigurationCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVMFromConfigurationCommandTest.java
index 1eb7866..3fda088 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVMFromConfigurationCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVMFromConfigurationCommandTest.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.core.bll;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyMap;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -23,6 +25,7 @@
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.ovirt.engine.core.common.action.ImportVmParameters;
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.OvfEntityData;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
@@ -78,6 +81,7 @@
         displayTypeMap.put(osId, new HashMap<Version, List<DisplayType>>());
         displayTypeMap.get(osId).put(null, Arrays.asList(DisplayType.qxl));
         when(osRepository.getDisplayTypes()).thenReturn(displayTypeMap);
+        when(osRepository.isBalloonEnabled(anyInt(), 
any(Version.class))).thenReturn(true);
         mockVdsGroup();
         setXmlOvfData();
     }
@@ -189,6 +193,7 @@
         vdsGroup = new VDSGroup();
         vdsGroup.setId(clusterId);
         vdsGroup.setStoragePoolId(storagePoolId);
+        vdsGroup.setArchitecture(ArchitectureType.x86_64);
     }
 
     private void mockStoragePool() {
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java
index 0e34a19..fc19c7a 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java
@@ -51,17 +51,21 @@
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
+import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.ValidationUtils;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.utils.MockConfigRule;
 import org.ovirt.engine.core.utils.RandomUtils;
 import org.ovirt.engine.core.utils.RandomUtilsSeedingRule;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ImportVmCommandTest {
@@ -121,10 +125,23 @@
         verify(multipleSdValidator, 
never()).allDomainsHaveSpaceForNewDisks(anyList());
     }
 
+    void addBalloonToVm(VM vm) {
+        Guid deviceId = Guid.newGuid();
+        Map<String, Object> specParams = new HashMap<String, Object>();
+        specParams.put(VdsProperties.Model, VdsProperties.Virtio);
+        VmDevice balloon = new VmDevice(new VmDeviceId(deviceId, vm.getId()),
+                VmDeviceGeneralType.BALLOON, 
VmDeviceType.MEMBALLOON.toString(), null, 0, specParams,
+                true, true, true, null, null, null, null);
+
+        vm.getManagedVmDeviceMap().put(deviceId, balloon);
+    }
+
     @Test
     public void refuseBalloonOnPPC() {
         final ImportVmCommand<ImportVmParameters> c = 
setupDiskSpaceTest(createParameters());
-        c.getParameters().getVm().setBalloonEnabled(true);
+
+        addBalloonToVm(c.getParameters().getVm());
+
         c.getParameters().getVm().setClusterArch(ArchitectureType.ppc64);
         VDSGroup cluster = new VDSGroup();
         cluster.setArchitecture(ArchitectureType.ppc64);
@@ -140,7 +157,9 @@
     @Test
     public void acceptBalloon() {
         final ImportVmCommand<ImportVmParameters> c = 
setupDiskSpaceTest(createParameters());
-        c.getParameters().getVm().setBalloonEnabled(true);
+
+        addBalloonToVm(c.getParameters().getVm());
+
         c.getParameters().getVm().setClusterArch(ArchitectureType.x86_64);
         VDSGroup cluster = new VDSGroup();
         cluster.setArchitecture(ArchitectureType.x86_64);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
index c60f5ba..3326efc 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
@@ -57,6 +57,10 @@
         return device.getType() == VmDeviceGeneralType.SOUND;
     }
 
+    public static boolean isMemoryBalloon(VmDevice device) {
+        return device.getType() == VmDeviceGeneralType.BALLOON;
+    }
+
     public static boolean isBridge(VmDevice device) {
         return device.getType() == VmDeviceGeneralType.INTERFACE
                 && device.getDevice().equals(VmDeviceType.BRIDGE.getName());


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If660e368d7ec31ff1f8251d483971ffbf0bd858a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Vitor de Lima <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to