diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo
index 40657e2c..fa18f4ab 100644
Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ
diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po
index 18a6d081..000e60cc 100644
--- a/locale/tr/LC_MESSAGES/django.po
+++ b/locale/tr/LC_MESSAGES/django.po
@@ -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"
diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo
index 188f5596..6c785cd2 100644
Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ
diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po
index 31bdf030..b104851e 100644
--- a/locale/zh/LC_MESSAGES/django.po
+++ b/locale/zh/LC_MESSAGES/django.po
@@ -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 编辑器中修改拓扑"
diff --git a/vrtManager/instance.py b/vrtManager/instance.py
index cbcdefd2..771ec7e8 100644
--- a/vrtManager/instance.py
+++ b/vrtManager/instance.py
@@ -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)
diff --git a/vrtManager/tests/test_resize_cpu.py b/vrtManager/tests/test_resize_cpu.py
new file mode 100644
index 00000000..8b108664
--- /dev/null
+++ b/vrtManager/tests/test_resize_cpu.py
@@ -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 = """{count}{topology}
+
+"""
+
+
+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=""))
+ 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 (("", "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"))