mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(vrtManager): a vCPU maximum the CPU topology does not make is refused first
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
This commit is contained in:
parent
e206862856
commit
1ddc941b2d
6 changed files with 58 additions and 3 deletions
Binary file not shown.
|
|
@ -9997,3 +9997,7 @@ msgstr "Yerel sunucu"
|
|||
#: webvirtcloud/settings.py:320
|
||||
msgid "All interfaces"
|
||||
msgstr "Tüm arabirimler"
|
||||
|
||||
#, python-format
|
||||
msgid "The VM's CPU topology has %(count)s vCPUs: change it in the XML editor to set another maximum"
|
||||
msgstr "VM'nin CPU topolojisi %(count)s vCPU içeriyor: başka bir en fazla değer için onu XML düzenleyicide değiştirin"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -9416,3 +9416,7 @@ msgstr "本机"
|
|||
#: webvirtcloud/settings.py:320
|
||||
msgid "All interfaces"
|
||||
msgstr "所有接口"
|
||||
|
||||
#, python-format
|
||||
msgid "The VM's CPU topology has %(count)s vCPUs: change it in the XML editor to set another maximum"
|
||||
msgstr "该虚拟机的 CPU 拓扑为 %(count)s 个 vCPU:要设置其他最大值,请在 XML 编辑器中修改拓扑"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import contextlib
|
|||
import ipaddress
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
import os.path
|
||||
import re
|
||||
import string
|
||||
|
|
@ -1681,9 +1682,15 @@ class wvmInstance(wvmConnect):
|
|||
raise util.OperationError(gettext_noop("The VM has no video card"))
|
||||
|
||||
def resize_cpu(self, cur_vcpu, vcpu):
|
||||
"""
|
||||
Function change ram and cpu on instance.
|
||||
"""
|
||||
"""The current and maximum vCPUs of a shut-off VM. A CPU topology
|
||||
fixes the maximum: libvirt refuses another one."""
|
||||
topology = etree.fromstring(self._XMLDesc(PERSISTENT_XML)).find("cpu/topology")
|
||||
if topology is not None:
|
||||
count = math.prod(int(value) for key, value in topology.attrib.items()
|
||||
if key in ("sockets", "dies", "clusters", "cores", "threads"))
|
||||
if count != int(vcpu):
|
||||
raise util.OperationError(gettext_noop("The VM's CPU topology has %(count)s vCPUs: change it in the "
|
||||
"XML editor to set another maximum"), count=count)
|
||||
is_vcpus_enabled = self.get_vcpus()
|
||||
if is_vcpus_enabled:
|
||||
self.set_vcpu_hotplug(False)
|
||||
|
|
|
|||
40
vrtManager/tests/test_resize_cpu.py
Normal file
40
vrtManager/tests/test_resize_cpu.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""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"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue