diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java index 2ef942cd53a3..eb2aca03434b 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java @@ -97,9 +97,7 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) { UserVmVO userVmVO = userVmDao.findById(vm.getId()); if (userVmVO != null) { HostVO host = hostDao.findById(userVmVO.getHostId()); - if (host != null) { - to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId())); - } + setMaxVCPUs(host, vm, to); } to.setBootloader(bt); @@ -126,6 +124,23 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) { return to; } + private void setMaxVCPUs(HostVO host, VirtualMachineProfile vm, VirtualMachineTO to) { + if (host != null) { + if (host.getCpus() < MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId())) { + String message = String.valueOf(new StringBuilder() + .append("Ignoring global max vCPUs limit (from global setting xen.vm.vcpu.max) on vm ") + .append(vm.getUuid()).append(" and setting VM max vCPU to host pCPU max: ") + .append(host.getCpus()) + .append(". Requested number of virtual CPUs exceeds number of host physical CPUs")); + logger.info(message); + to.setVcpuMaxLimit(host.getCpus()); + } else { + logger.info("Setting vm: " + vm.getUuid() + " max vCPU limit (from global setting xen.vm.vcpu.max) to: " + MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId())); + to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId())); + } + } + } + @Override public boolean trackVmHostChange() { return true; diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index ddd6bcfbc71e..04052d2ec886 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -23,7 +23,8 @@ from marvin.lib.utils import cleanup_resources from marvin.lib.base import (Account, VirtualMachine, - ServiceOffering) + ServiceOffering, + Configurations) from marvin.lib.common import (get_zone, get_template, get_domain) @@ -81,6 +82,12 @@ def setUpClass(cls): cls.services["service_offerings"]["big"] ) + Configurations.update( + cls.apiclient, + name="enable.dynamic.scale.vm", + value="true" + ) + # create a virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -101,6 +108,13 @@ def tearDownClass(cls): TestScaleVm, cls).getClsTestClient().getApiClient() cleanup_resources(cls.apiclient, cls._cleanup) + + Configurations.update( + cls.apiclient, + name="enable.dynamic.scale.vm", + value="false" + ) + return def setUp(self):