From 7e2f53200eb97a8b7d7d090e5bf947cbbd416dcb Mon Sep 17 00:00:00 2001 From: Darrin Husselmann Date: Thu, 5 Nov 2020 10:02:35 +0200 Subject: [PATCH 1/3] Added global var before scaling VM --- test/integration/smoke/test_scale_vm.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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): From a479256dc58b59387f76add7d63474d0dc0611f2 Mon Sep 17 00:00:00 2001 From: Darrin Husselmann Date: Wed, 11 Nov 2020 11:30:12 +0200 Subject: [PATCH 2/3] Preventing failed instance due to specifying more vCPUs than pCPUs on host --- .../java/com/cloud/hypervisor/XenServerGuru.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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..3d502699c470 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 @@ -98,7 +98,18 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) { if (userVmVO != null) { HostVO host = hostDao.findById(userVmVO.getHostId()); if (host != null) { - to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId())); + 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())); + } } } From fc75399fd08601f87f111e74a8b11d1230c9539f Mon Sep 17 00:00:00 2001 From: Darrin Husselmann Date: Wed, 11 Nov 2020 16:34:55 +0200 Subject: [PATCH 3/3] Moved logic to method --- .../com/cloud/hypervisor/XenServerGuru.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) 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 3d502699c470..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,20 +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) { - 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())); - } - } + setMaxVCPUs(host, vm, to); } to.setBootloader(bt); @@ -137,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;