Martin Betak has uploaded a new change for review.

Change subject: core: Add validation for Vm memory hard limits
......................................................................

core: Add validation for Vm memory hard limits

The vdc options VM64BitMaxMemorySizeInMB and VM64BitMaxMemorySizeInMB
were not checked at all, only the os-info were used to issue a warning.

Now we check those against the appropriate cluster version at the VM
run.

Change-Id: I46c22acc77867abc79cd54ef6113ab2da005fd94
Signed-off-by: Martin Betak <mbe...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
6 files changed, 61 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/28516/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index 0b7c922..f199f36 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -853,7 +853,7 @@
 
     protected RunVmValidator getRunVmValidator() {
         return new RunVmValidator(getVm(), getParameters(),
-                isInternalExecution(), getActiveIsoDomainId());
+                isInternalExecution(), getActiveIsoDomainId(), osRepository);
     }
 
     protected Guid getActiveIsoDomainId() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
index a584305..751c712 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
@@ -224,7 +224,7 @@
         RunVmParams runVmParams = new RunVmParams(vmId);
         runVmParams.setUseVnc(osRepository.isLinux(vm.getVmOsId()) || 
vm.getVmType() == VmType.Server);
 
-        return new RunVmValidator(vm, runVmParams, false, 
findActiveISODomain(vm.getStoragePoolId()))
+        return new RunVmValidator(vm, runVmParams, false, 
findActiveISODomain(vm.getStoragePoolId()), osRepository)
                 .canRunVm(
                         messages,
                         fetchStoragePool(vm.getStoragePoolId()),
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
index f1b327b..3359184 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
@@ -39,6 +39,7 @@
 import org.ovirt.engine.core.common.config.Config;
 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.queries.GetImagesListParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
@@ -61,6 +62,7 @@
     private RunVmParams runVmParam;
     private boolean isInternalExecution;
     private Guid activeIsoDomainId;
+    private OsRepository osRepository;
 
     private List<Disk> cachedVmDisks;
     private List<DiskImage> cachedVmImageDisks;
@@ -69,11 +71,12 @@
     private Set<String> cachedClusterNetworksNames;
 
     public RunVmValidator(VM vm, RunVmParams rumVmParam, boolean 
isInternalExecution,
-            Guid activeIsoDomainId) {
+            Guid activeIsoDomainId, OsRepository osRepository) {
         this.vm = vm;
         this.runVmParam = rumVmParam;
         this.isInternalExecution = isInternalExecution;
         this.activeIsoDomainId = activeIsoDomainId;
+        this.osRepository = osRepository;
     }
 
     /**
@@ -118,8 +121,21 @@
                 validate(validateStatelessVm(vm, getVmDisks(), 
runVmParam.getRunAsStateless()), messages) &&
                 validate(validateStorageDomains(vm, isInternalExecution, 
getVmImageDisks()), messages) &&
                 validate(validateImagesForRunVm(vm, getVmImageDisks()), 
messages) &&
+                validate(validateMemorySize(vm), messages) &&
                 SchedulingManager.getInstance().canSchedule(
                         vdsGroup, vm, vdsBlackList, vdsWhiteList, destVds, 
messages);
+    }
+
+    protected ValidationResult validateMemorySize(VM vm) {
+        final ConfigValues configKey = 
getOsRepository().get64bitOss().contains(vm.getOs())
+                ? ConfigValues.VM64BitMaxMemorySizeInMB
+                : ConfigValues.VM32BitMaxMemorySizeInMB;
+        final int maxSize = Config.getValue(configKey, 
vm.getVdsGroupCompatibilityVersion().getValue());
+        if (vm.getMemSizeMb() > maxSize) {
+            return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT);
+        }
+
+        return ValidationResult.VALID;
     }
 
     /**
@@ -551,4 +567,8 @@
 
         return cachedClusterNetworksNames;
     }
+
+    public OsRepository getOsRepository() {
+        return osRepository;
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
index e881a8f..37587d1 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
@@ -7,6 +7,7 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
 import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
 
 import java.util.ArrayList;
@@ -31,6 +32,7 @@
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 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.customprop.VmPropertiesUtils;
 import org.ovirt.engine.core.common.utils.exceptions.InitializationException;
 import org.ovirt.engine.core.compat.Guid;
@@ -41,11 +43,17 @@
 @RunWith(MockitoJUnitRunner.class)
 public class RunVmValidatorTest {
 
+    private static final int _64_BIT_OS = 13;
+
+    public static final int MEMORY_LIMIT_32_BIT = 32000;
+    public static final int MEMORY_LIMIT_64_BIT = 640000;
     @ClassRule
     public static MockConfigRule mcr = new MockConfigRule(
             mockConfig(ConfigValues.VdsSelectionAlgorithm, "General", "0"),
             mockConfig(ConfigValues.PredefinedVMProperties, "3.0", "0"),
-            mockConfig(ConfigValues.UserDefinedVMProperties, "3.0", "0")
+            mockConfig(ConfigValues.UserDefinedVMProperties, "3.0", "0"),
+            mockConfig(ConfigValues.VM32BitMaxMemorySizeInMB, "3.3", 
MEMORY_LIMIT_32_BIT),
+            mockConfig(ConfigValues.VM64BitMaxMemorySizeInMB, "3.3", 
MEMORY_LIMIT_64_BIT)
             );
 
     @Spy
@@ -95,8 +103,8 @@
     @Test
     public void testVmFailNoDisks() {
         validateResult(runVmValidator.validateBootSequence(new VM(), null, new 
ArrayList<Disk>(), null),
-                false,
-                VdcBllMessages.VM_CANNOT_RUN_FROM_DISK_WITHOUT_DISK);
+                       false,
+                       VdcBllMessages.VM_CANNOT_RUN_FROM_DISK_WITHOUT_DISK);
     }
 
     @Test
@@ -223,6 +231,31 @@
                 VdcBllMessages.VM_CANNOT_RUN_STATELESS_HA);
     }
 
+    private void mockOsRepository() {
+        OsRepository osRepository = mock(OsRepository.class);
+        when(osRepository.get64bitOss()).thenReturn(new ArrayList<Integer>() 
{{ add(_64_BIT_OS); }});
+        when(runVmValidator.getOsRepository()).thenReturn(osRepository);
+    }
+
+    @Test
+    public void test32BitMemoryExceedsLimit() {
+        VM vm = new VM();
+        vm.setVdsGroupCompatibilityVersion(Version.v3_3);
+        vm.setVmMemSizeMb(MEMORY_LIMIT_32_BIT + 1);
+        mockOsRepository();
+        validateResult(runVmValidator.validateMemorySize(vm), false, 
VdcBllMessages.ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT);
+    }
+
+    @Test
+    public void test64BitMemoryExceedsLimit() {
+        VM vm = new VM();
+        vm.setVdsGroupCompatibilityVersion(Version.v3_3);
+        vm.setVmMemSizeMb(MEMORY_LIMIT_64_BIT + 1);
+        vm.setVmOs(_64_BIT_OS);
+        mockOsRepository();
+        validateResult(runVmValidator.validateMemorySize(vm), false, 
VdcBllMessages.ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT);
+    }
+
     private void canRunVmAsStateless(boolean autoStartUp,
             final boolean vmInPreview,
             boolean isVmStateless,
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index a38c559..c9a054a 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -344,6 +344,7 @@
     
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_WITH_NOT_SUPPORTED_ARCHITECTURE(ErrorType.NOT_SUPPORTED),
     
ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_TEMPLATE_WITH_NOT_SUPPORTED_ARCHITECTURE(ErrorType.NOT_SUPPORTED),
     
ACTION_TYPE_FAILED_MIN_MEMORY_CANNOT_EXCEED_MEMORY_SIZE(ErrorType.BAD_PARAMETERS),
+    ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT(ErrorType.NOT_SUPPORTED),
     VDS_CANNOT_CHECK_VERSION_HOST_NON_RESPONSIVE(ErrorType.CONFLICT),
     STORAGE_DOMAIN_DOES_NOT_EXIST(ErrorType.BAD_PARAMETERS),
     // VDS_CANNOT_RUN_VM_FAILED_TO_RUN, // EINAV: not in use
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index a30d480..542f695 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -21,6 +21,7 @@
 ACTION_TYPE_FAILED_VM_SNAPSHOT_HAS_NO_CONFIGURATION=Cannot ${action} ${type}. 
The snapshot ${SnapshotName} of VM ${VmName} has no configuration available. 
Please choose a snapshot with configuration available.
 ACTION_TYPE_FAILED_CANNOT_RUN_ACTION_ON_NON_MANAGED_VM=Cannot ${action} 
${type}. This VM is not managed by the engine.
 ACTION_TYPE_FAILED_MIN_MEMORY_CANNOT_EXCEED_MEMORY_SIZE=Cannot ${action} 
${type}. Physical Memory Guaranteed cannot exceed Memory Size.
+ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT=Cannot ${action} ${type}. 
Memory size exceeds supported limit for given cluster version.
 IMAGE_REPOSITORY_NOT_FOUND=Storage Domain cannot be accessed.\n\
 Possible reasons:\n\
        No operational Host in Data Center or Data Center state is not Up.


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

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

Reply via email to