mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix(instances): memory, boot order and QoS edits check what they change first
Three edits went wrong on input or a state made outside the panel:
- A running VM's memory was set live, then for its next start. When the
next start had a lower maximum (virsh --config), the live change was
made and the second one failed. The maximum of the next start is now
checked first.
- A boot order entry without its device type ("disk") raised an error
page. It is now refused with a message.
- A QoS form of a NIC whose MAC changed since redefined the VM unchanged
and said the QoS was set or deleted. It now says the NIC is not in the
definition.
Turkish and Chinese texts included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
63fb7defee
commit
015972dc38
8 changed files with 307 additions and 243 deletions
|
|
@ -1701,6 +1701,12 @@ class wvmInstance(wvmConnect):
|
|||
# an active VM (running, paused, ...) changes only its current memory;
|
||||
# a paused guest's balloon driver applies it once it is resumed
|
||||
if self.instance.isActive():
|
||||
# the next start's maximum may differ (set with virsh --config):
|
||||
# checked before the running VM changes
|
||||
pending = int(etree.fromstring(self._XMLDesc(PERSISTENT_XML)).findtext("memory"))
|
||||
if cur_memory > pending:
|
||||
raise util.OperationError(gettext_noop("The VM's next start has a maximum memory of %(max)s MiB"),
|
||||
max=pending // 1024)
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
return
|
||||
|
|
@ -3085,6 +3091,13 @@ class wvmInstance(wvmConnect):
|
|||
def set_memory(self, size, flags=0):
|
||||
self.instance.setMemoryFlags(size, flags)
|
||||
|
||||
@staticmethod
|
||||
def _persistent_nic(tree, mac):
|
||||
"""Refuses a MAC no NIC of the persistent definition has: a form
|
||||
loaded before the NIC changed."""
|
||||
if not tree.xpath("/domain/devices/interface[mac/@address=$mac]", mac=mac):
|
||||
raise util.OperationError(gettext_noop("Network interface %(mac)s is not in the definition"), mac=mac)
|
||||
|
||||
def set_qos(self, mac, direction, average, peak, burst):
|
||||
if direction not in ("inbound", "outbound"):
|
||||
raise ValueError("Direction must be inbound or outbound")
|
||||
|
|
@ -3096,6 +3109,7 @@ class wvmInstance(wvmConnect):
|
|||
xml = f"<{direction} average='{average}' peak='{peak}' burst='{burst}'/>"
|
||||
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
|
||||
self._persistent_nic(tree, mac)
|
||||
|
||||
macs = tree.xpath("/domain/devices/interface/mac")
|
||||
for cur_mac in macs:
|
||||
|
|
@ -3118,6 +3132,7 @@ class wvmInstance(wvmConnect):
|
|||
|
||||
def unset_qos(self, mac, direction):
|
||||
tree = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
|
||||
self._persistent_nic(tree, mac)
|
||||
for direct in tree.xpath(
|
||||
"/domain/devices/interface/bandwidth/{}".format(direction)
|
||||
):
|
||||
|
|
|
|||
|
|
@ -132,6 +132,17 @@ class DeviceEditsTestCase(unittest.TestCase):
|
|||
p._defineXML.assert_called_once()
|
||||
p.wvm.defineXML.assert_not_called()
|
||||
|
||||
def test_a_qos_edit_of_a_nic_not_in_the_definition_changes_nothing(self):
|
||||
# a form loaded before the NIC's MAC changed
|
||||
for change in (
|
||||
lambda p: p.set_qos("52:54:10:00:00:09", "outbound", 1, 2, 3),
|
||||
lambda p: p.unset_qos("52:54:10:00:00:09", "inbound"),
|
||||
):
|
||||
p = proxy()
|
||||
with self.assertRaisesRegex(util.OperationError, "52:54:10:00:00:09 is not in the definition"):
|
||||
change(p)
|
||||
p._defineXML.assert_not_called()
|
||||
|
||||
def test_a_qos_edit_keeps_the_floor(self):
|
||||
p = proxy()
|
||||
p.set_qos("52:54:10:00:00:01", "inbound", 10, 20, 30)
|
||||
|
|
@ -279,6 +290,7 @@ class ResizeMemTestCase(unittest.TestCase):
|
|||
def test_an_active_vm_changes_only_its_current_memory(self):
|
||||
# a paused VM is active too: its guest applies the balloon once resumed
|
||||
p = proxy(active=True)
|
||||
p._XMLDesc = lambda flags: "<domain><memory>163840</memory></domain>"
|
||||
p.resize_mem(96, 160)
|
||||
self.assertEqual(
|
||||
[c.args for c in p.instance.setMemoryFlags.call_args_list],
|
||||
|
|
@ -286,6 +298,14 @@ class ResizeMemTestCase(unittest.TestCase):
|
|||
)
|
||||
p._defineXML.assert_not_called()
|
||||
|
||||
def test_an_active_vm_whose_next_start_has_a_lower_maximum_changes_nothing(self):
|
||||
# set with virsh --config: the running VM's maximum is higher
|
||||
p = proxy(active=True)
|
||||
p._XMLDesc = lambda flags: "<domain><memory>65536</memory></domain>"
|
||||
with self.assertRaisesRegex(util.OperationError, "next start has a maximum memory"):
|
||||
p.resize_mem(96, 160)
|
||||
p.instance.setMemoryFlags.assert_not_called()
|
||||
|
||||
def test_a_stopped_vm_gets_both_values_in_its_definition(self):
|
||||
p = proxy(active=False)
|
||||
p._XMLDesc = lambda flags: "<domain><memory>131072</memory><currentMemory>131072</currentMemory></domain>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue