Martin Sivák has uploaded a new change for review.
Change subject: Fix ballooning behaviour of freshly received VM
......................................................................
Fix ballooning behaviour of freshly received VM
There is an issue with freshly received VMs. MOM might ask for
the current balloon status before the stats threads collect all
data. The target will be reported as 0 in that case and the VM
will be requested to return all its free memory.
The balloon info method won't return any data before it
has everything ready after this fix is applied.
This also fixes the unittest that was using balloon for checking
whether the stats system works.
Change-Id: If44c8e9d65b7221b2dec5fdd1f2d7d4343f7aeaa
Signed-off-by: Martin Sivak <msivak(a)redhat.com>
---
M tests/vmTests.py
M vdsm/rpc/vdsmapi-schema.json
M vdsm/virt/vm.py
3 files changed, 25 insertions(+), 20 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/34887/1
diff --git a/tests/vmTests.py b/tests/vmTests.py
index 07dc6be..effc8a6 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1495,10 +1495,9 @@
with fake.VM(self.VM_PARAMS, self.DEV_BALLOON) as testvm:
self.assertEqual(testvm._dom, None)
mock_stats_thread = vm.VmStatsThread(testvm)
- res = {}
- mock_stats_thread._getBalloonStats(res)
+ res = mock_stats_thread.get()
self.assertIn('balloonInfo', res)
- self.assertIn('balloon_cur', res['balloonInfo'])
+ self.assertNotIn('balloon_cur', res['balloonInfo'])
def testGetStatsDomInfoFail(self):
# bz1073478 - extra case
@@ -1506,10 +1505,8 @@
testvm._dom = fake.Domain(
virtError=libvirt.VIR_ERR_NO_DOMAIN)
mock_stats_thread = vm.VmStatsThread(testvm)
- res = {}
- mock_stats_thread._getBalloonStats(res)
+ res = mock_stats_thread.get()
self.assertIn('balloonInfo', res)
- self.assertIn('balloon_cur', res['balloonInfo'])
def testMultipleGraphicDeviceStats(self):
devices = [{'type': 'graphics', 'device':
'spice', 'port': '-1'},
diff --git a/vdsm/rpc/vdsmapi-schema.json b/vdsm/rpc/vdsmapi-schema.json
index 624b686..0074223 100644
--- a/vdsm/rpc/vdsmapi-schema.json
+++ b/vdsm/rpc/vdsmapi-schema.json
@@ -6320,21 +6320,22 @@
##
# @BalloonInfo:
#
-# Guest memory balloon information.
+# Guest memory balloon information. Values are present only when the
+# balloon is enabled and ready.
#
-# @balloon_max: The maximum amount of memory available to the guest (in KiB)
+# @balloon_max: #optional The maximum amount of memory available to the guest (in KiB)
#
-# @balloon_cur: The current amount of memory available to the guest (in KiB)
+# @balloon_cur: #optional The current amount of memory available to the guest (in KiB)
#
-# @balloon_min: The minimum amount of memory guaranteed to the guest (in KiB)
+# @balloon_min: #optional The minimum amount of memory guaranteed to the guest (in KiB)
#
-# @balloon_target: The amount of memory requested (in KiB)
+# @balloon_target: #optional The amount of memory requested (in KiB)
#
# Since: 4.10.0
##
{'type': 'BalloonInfo',
- 'data': {'balloon_max': 'str', 'balloon_cur':
'str', 'balloon_min': 'str',
- 'balloon_target': 'str'}}
+ 'data': {'*balloon_max': 'str', '*balloon_cur':
'str', '*balloon_min': 'str',
+ '*balloon_target': 'str'}}
##
# @VmDisplayInfo:
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 9740ab3..3c51089 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -410,14 +410,21 @@
balloon_target = dev.get('target', max_mem)
break
else:
- balloon_target = 0
+ balloon_target = None
- stats['balloonInfo'] = {
- 'balloon_max': str(max_mem),
- 'balloon_min': str(
- int(self._vm.conf.get('memGuaranteedSize', '0')) *
1024),
- 'balloon_cur': str(sample) if sample is not None else '0',
- 'balloon_target': str(balloon_target)}
+ stats['balloonInfo'] = {}
+
+ # Do not return any balloon status info before we get all data
+ # MOM will ignore VMs with missing balloon information instead
+ # using incomplete data and computing wrong balloon targets
+ if balloon_target is not None and sample is not None:
+ stats['balloonInfo'].update({
+ 'balloon_max': str(max_mem),
+ 'balloon_min': str(
+ int(self._vm.conf.get('memGuaranteedSize', '0')) *
1024),
+ 'balloon_cur': str(sample),
+ 'balloon_target': str(balloon_target)
+ })
def _getCpuTuneInfo(self, stats):
--
To view, visit
http://gerrit.ovirt.org/34887
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If44c8e9d65b7221b2dec5fdd1f2d7d4343f7aeaa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Sivák <msivak(a)redhat.com>