mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
fix(instances): enabling vCPU hot plug keeps the current vCPU count
Enabling hot plug on a stopped VM wrote every vCPU up to the maximum as enabled, so a VM with 2 of 4 vCPUs booted with 4. The current vCPUs stay enabled now; libvirt adds the rest as disabled hotpluggable vCPUs.
This commit is contained in:
parent
251ddbbec1
commit
c1d2e9610d
4 changed files with 29 additions and 3 deletions
|
|
@ -1105,8 +1105,9 @@ class wvmInstance(wvmConnect):
|
|||
self.instance.setVcpu(str(cpu_id), enabled)
|
||||
|
||||
def set_vcpu_hotplug(self, status, vcpus_hotplug=0):
|
||||
"""vcpus_hotplug = 0 make all vpus hotpluggable"""
|
||||
vcpus_hotplug = int(self.get_vcpu()) if vcpus_hotplug == 0 else vcpus_hotplug
|
||||
"""vcpus_hotplug: the vCPUs enabled at boot, 0 keeps the current ones;
|
||||
libvirt adds the rest up to the maximum as disabled hotpluggable vCPUs"""
|
||||
vcpus_hotplug = self.get_cur_vcpu() if vcpus_hotplug == 0 else vcpus_hotplug
|
||||
if self.get_status() == 5: # shutoff
|
||||
if status:
|
||||
xml = """ <vcpus>"""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
"""Device edits of a VM: each definition is changed as it describes the
|
||||
device, every NIC type can be a boot device, posted values stay values, and
|
||||
definition changes go through _defineXML. An active VM's memory is resized
|
||||
by balloon, a stopped one's in its definition."""
|
||||
by balloon, a stopped one's in its definition. Enabling vCPU hot plug keeps
|
||||
the vCPUs enabled at boot."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
|
@ -65,6 +66,15 @@ class DetachDiskTestCase(unittest.TestCase):
|
|||
p.instance.detachDeviceFlags.assert_not_called()
|
||||
|
||||
|
||||
class VcpuHotplugTestCase(unittest.TestCase):
|
||||
def test_enabling_hotplug_keeps_the_current_vcpus_enabled(self):
|
||||
p = proxy(active=False)
|
||||
p.instance.info.return_value = [5]
|
||||
p._XMLDesc = lambda flags: "<domain><vcpu current='2'>4</vcpu></domain>"
|
||||
p.set_vcpu_hotplug(True)
|
||||
self.assertEqual(defined(p).xpath("vcpus/vcpu/@enabled"), ["yes", "yes"])
|
||||
|
||||
|
||||
class DeviceEditsTestCase(unittest.TestCase):
|
||||
def test_a_block_volume_is_attached_by_its_device_path(self):
|
||||
p = proxy(active=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue