mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
A VM with a CPU topology takes only the maximum it makes; libvirt refused another one after the vCPU hotplug list had been removed, so a failed resize left hotplug off. The maximum is now checked against the topology before anything changes, with tr and zh translations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
"""A CPU topology fixes a VM's maximum vCPUs: another maximum is refused
|
|
before anything changes."""
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock
|
|
|
|
from lxml import etree
|
|
from vrtManager import util
|
|
from vrtManager.instance import wvmInstance
|
|
|
|
DOMAIN_XML = """<domain><vcpu placement='static' current='2'>{count}</vcpu><cpu mode='host-model'>{topology}</cpu>
|
|
<vcpus><vcpu id='0' enabled='yes' hotpluggable='no' order='1'/><vcpu id='1' enabled='yes' hotpluggable='yes' order='2'/></vcpus>
|
|
</domain>"""
|
|
|
|
|
|
def shut_off_vm(xml):
|
|
inst = wvmInstance.__new__(wvmInstance)
|
|
inst.instance = MagicMock()
|
|
inst.wvm = MagicMock()
|
|
inst._XMLDesc = MagicMock(return_value=xml)
|
|
inst.get_status = MagicMock(return_value=5)
|
|
inst.get_cur_vcpu = MagicMock(return_value=2)
|
|
return inst
|
|
|
|
|
|
class ResizeCpuTests(unittest.TestCase):
|
|
def test_a_maximum_the_topology_does_not_make_is_refused(self):
|
|
inst = shut_off_vm(DOMAIN_XML.format(count=2, topology="<topology sockets='1' dies='1' cores='2' threads='1'/>"))
|
|
with self.assertRaises(util.OperationError) as raised:
|
|
inst.resize_cpu("2", "4")
|
|
self.assertEqual(raised.exception.values, {"count": 2})
|
|
inst.wvm.defineXML.assert_not_called() # hotplug is not switched off either
|
|
|
|
def test_the_maximum_of_the_topology_or_no_topology_is_set(self):
|
|
for topology, count in (("<topology sockets='2' cores='2' threads='1'/>", "4"), ("", "4")):
|
|
with self.subTest(topology):
|
|
inst = shut_off_vm(DOMAIN_XML.format(count=2, topology=topology))
|
|
inst.resize_cpu("2", count)
|
|
vcpu = etree.fromstring(inst.wvm.defineXML.call_args_list[1].args[0]).find("vcpu")
|
|
self.assertEqual((vcpu.text, vcpu.get("current")), ("4", "2"))
|