mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
fix(instances): a paused VM's memory is resized as a running VM's
Only a running VM counted as active, so a paused one (or one blocked, PM-suspended or shutting down) had its maximum and current memory written for the next boot and nothing applied live. Every active VM now has its current memory changed live and in its definition and keeps its maximum; a paused guest takes the new size once resumed. The quota check follows the same rule. Checked on a real guest: paused, shrunk, resumed, then grown back.
This commit is contained in:
parent
7b5c2cd057
commit
251ddbbec1
7 changed files with 55 additions and 9 deletions
|
|
@ -15,7 +15,6 @@ try:
|
|||
VIR_DOMAIN_AFFECT_LIVE,
|
||||
VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT,
|
||||
VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP,
|
||||
VIR_DOMAIN_RUNNING,
|
||||
VIR_DOMAIN_XML_SECURE,
|
||||
VIR_DOMAIN_XML_INACTIVE,
|
||||
VIR_DOMAIN_XML_MIGRATABLE,
|
||||
|
|
@ -1431,8 +1430,9 @@ class wvmInstance(wvmConnect):
|
|||
"""
|
||||
memory = int(memory) * 1024
|
||||
cur_memory = int(cur_memory) * 1024
|
||||
# if dom is running change only ram
|
||||
if self.get_status() == VIR_DOMAIN_RUNNING:
|
||||
# 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():
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.set_memory(cur_memory, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""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."""
|
||||
definition changes go through _defineXML. An active VM's memory is resized
|
||||
by balloon, a stopped one's in its definition."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
|
@ -106,5 +107,25 @@ class DeviceEditsTestCase(unittest.TestCase):
|
|||
self.assertIsNone(etree.fromstring(xml).find("model"))
|
||||
|
||||
|
||||
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.resize_mem(96, 160)
|
||||
self.assertEqual(
|
||||
[c.args for c in p.instance.setMemoryFlags.call_args_list],
|
||||
[(96 * 1024, VIR_DOMAIN_AFFECT_LIVE), (96 * 1024, VIR_DOMAIN_AFFECT_CONFIG)],
|
||||
)
|
||||
p._defineXML.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>"
|
||||
p.resize_mem(96, 160)
|
||||
tree = defined(p)
|
||||
self.assertEqual((tree.findtext("memory"), tree.findtext("currentMemory")), (str(160 * 1024), str(96 * 1024)))
|
||||
p.instance.setMemoryFlags.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue