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.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1104774
Change-Id: I46c22acc77867abc79cd54ef6113ab2da005fd94
Signed-off-by: Martin Betak <[email protected]>
---
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
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
7 files changed, 62 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/28656/1

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 d600044..2c1f448 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
@@ -40,9 +40,11 @@
 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;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import 
org.ovirt.engine.core.common.vdscommands.IsVmDuringInitiatingVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
@@ -61,6 +63,7 @@
     private VM vm;
     private RunVmParams runVmParam;
     private boolean isInternalExecution;
+    private OsRepository osRepository;
 
     private List<Disk> cachedVmDisks;
     private List<DiskImage> cachedVmImageDisks;
@@ -72,6 +75,7 @@
         this.vm = vm;
         this.runVmParam = rumVmParam;
         this.isInternalExecution = isInternalExecution;
+        this.osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
     }
 
     /**
@@ -116,8 +120,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;
     }
 
     /**
@@ -548,4 +565,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 87b4c5a..ef7621d 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;
@@ -32,6 +33,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.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dao.network.VmNicDao;
@@ -42,11 +44,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
@@ -231,6 +239,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 e2750e1..ce1be2a 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
@@ -333,6 +333,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 cb50312..5f56291 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_IS_BROKEN=Cannot ${action} ${type}. The 
snapshot is broken, and no further work can be done on it. Please remove this 
snapshot from the VM.
 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.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index d433d81..bfe9321 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -3110,4 +3110,7 @@
 
     @DefaultStringValue("Cannot ${action} ${type}. A VirtIO-SCSI LUN disk 
can't be read-only.")
     String 
ACTION_TYPE_FAILED_VIRT_IO_SCSI_INTERFACE_FOR_LUN_DISKS_DOES_NOT_SUPPORT_READ_ONLY_ATTR();
+
+    @DefaultStringValue("Cannot ${action} ${type}. Memory size exceeds 
supported limit for given cluster version.")
+    String ACTION_TYPE_FAILED_MEMORY_EXCEEDS_SUPPORTED_LIMIT();
 }
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 5d86fc2..c167c12 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -21,6 +21,7 @@
 ACTION_TYPE_FAILED_VM_SNAPSHOT_IS_BROKEN=Cannot ${action} ${type}. The 
snapshot is broken, and no further work can be done on it. Please remove this 
snapshot from the VM.
 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.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index bf3e468..7bdeb76 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -21,6 +21,7 @@
 ACTION_TYPE_FAILED_VM_SNAPSHOT_IS_BROKEN=Cannot ${action} ${type}. The 
snapshot is broken, and no further work can be done on it. Please remove this 
snapshot from the VM.
 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/28656
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I46c22acc77867abc79cd54ef6113ab2da005fd94
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Martin Betak <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to