Wednesday, 23 March
2016
Wed, 23 Mar
'16
3:17 p.m.
If QEMU version is < 2.1, qemu is not going to start guest which have
maxmemory tag configured in the XML. Kimchi adds this tag by default in
order to allow memory hotplug.
In other words, in order to allow memory hotplug, versions must be
libvirt >= 1.2.14 and qemu >= 2.1. Libvirt was already being tested by
the feature test, but qemu did not. Distros as Red Hat 7 and CentOS
still are in qemu 1.5.
This patch extend the feature test and do not create maxmemory tag in
order to avoid problems in those distros.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
i18n.py | 2 +-
model/featuretests.py | 20 +++++++++++++-------
model/vms.py | 11 ++++++++++-
tests/test_model.py | 5 +++--
vmtemplate.py | 4 +++-
5 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/i18n.py b/i18n.py
index beefeb5..6214687 100644
--- a/i18n.py
+++ b/i18n.py
@@ -99,7 +99,7 @@ messages = {
"KCHVM0043E": _("Only increase memory is allowed in active
VMs"),
"KCHVM0044E": _("For live memory update, new memory value must be
equal old memory value plus multiples of 1024 Mib"),
"KCHVM0045E": _("There are not enough free slots of 1024 Mib in the
guest."),
- "KCHVM0046E": _("Host's libvirt version does not support memory
devices. Libvirt must be >= 1.2.14"),
+ "KCHVM0046E": _("Host's libvirt or qemu version does not support
memory devices and memory hotplug. Libvirt must be >= 1.2.14 and QEMU must be >=
2.1."),
"KCHVM0047E": _("Error attaching memory device. Details:
%(error)s"),
"KCHVM0048E": _("Cannot start %(name)s. Virtual machine is already
running."),
"KCHVM0049E": _("Cannot power off %(name)s. Virtual machine is shut
off."),
diff --git a/model/featuretests.py b/model/featuretests.py
index 378335a..ba728e1 100644
--- a/model/featuretests.py
+++ b/model/featuretests.py
@@ -72,6 +72,14 @@ MAXMEM_VM_XML = """
<type arch='%(arch)s'>hvm</type>
<boot dev='hd'/>
</os>
+ <cpu>
+ <numa>
+ <cell id='0' cpus='0' memory='10240'
unit='KiB'/>
+ </numa>
+ </cpu>
+ <features>
+ <acpi/>
+ </features>
</domain>"""
DEV_MEM_XML = """
@@ -209,13 +217,9 @@ class FeatureTests(object):
A memory device can be hot-plugged or hot-unplugged since libvirt
version 1.2.14.
'''
- # Libvirt < 1.2.14 does not support memory devices, so firstly, check
- # its version, then try to attach a device. These steps avoid errors
- # with Libvirt 'test' driver for KVM
- version = 1000000*1 + 1000*2 + 14
- if libvirt.getVersion() < version:
- return False
-
+ # Libvirt < 1.2.14 does not support memory devices, so try to attach a
+ # device. Then check if QEMU (>= 2.1) supports memory hotplug, starting
+ # the guest These steps avoid errors with Libvirt 'test' driver for KVM
with RollbackContext() as rollback:
FeatureTests.disable_libvirt_error_logging()
rollback.prependDefer(FeatureTests.enable_libvirt_error_logging)
@@ -230,6 +234,8 @@ class FeatureTests(object):
try:
dom.attachDeviceFlags(DEV_MEM_XML,
libvirt.VIR_DOMAIN_MEM_CONFIG)
+ dom.create()
+ rollback.prependDefer(dom.destroy)
return True
except libvirt.libvirtError:
return False
diff --git a/model/vms.py b/model/vms.py
index 03ffdae..e3bc266 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -170,7 +170,8 @@ class VMsModel(object):
stream_protocols = self.caps.libvirt_stream_protocols
xml = t.to_vm_xml(name, vm_uuid,
libvirt_stream_protocols=stream_protocols,
- graphics=graphics)
+ graphics=graphics,
+ mem_hotplug_support = self.caps.mem_hotplug_support)
cb('Defining new VM')
try:
@@ -809,6 +810,14 @@ class VMModel(object):
return (nonascii_name if nonascii_name is not None else vm_name, dom)
def _update_memory_config(self, xml, params):
+ # Cannot pass max memory if there is not support to memory hotplug
+ # Then set max memory as memory, just to continue with the update
+ if not self.caps.mem_hotplug_support:
+ if 'maxmemory' in params['memory']:
+ raise InvalidOperation("KCHVM0046E")
+ else:
+ params['memory']['maxmemory'] =
params['memory']['current']
+
root = ET.fromstring(xml)
# MiB to KiB
hasMem = 'current' in params['memory']
diff --git a/tests/test_model.py b/tests/test_model.py
index b461172..c91ba8f 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -912,13 +912,14 @@ class ModelTests(unittest.TestCase):
# rename and increase memory when vm is not running
params = {'name': u'пeω-∨м',
- 'memory': {'current': 2048,
- 'maxmemory': 2048}}
+ 'memory': {'current': 2048}}
inst.vm_update('kimchi-vm1', params)
rollback.prependDefer(utils.rollback_wrapper, inst.vm_delete,
u'пeω-∨м')
self.assertEquals(info['uuid'],
inst.vm_lookup(u'пeω-∨м')['uuid'])
info = inst.vm_lookup(u'пeω-∨м')
+ # Max memory is returned, add to test
+ params['memory']['maxmemory'] = 2048
for key in params.keys():
self.assertEquals(params[key], info[key])
diff --git a/vmtemplate.py b/vmtemplate.py
index 4bcf324..653ad02 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -376,7 +376,9 @@ class VMTemplate(object):
# Rearrange memory parameters
params['memory'] = self.info['memory'].get('current')
params['max_memory'] = ""
- if memory != maxmemory:
+ # if there is not support to memory hotplug in Libvirt or qemu, we
+ # cannot add the tag maxMemory
+ if memory != maxmemory and kwargs.get('mem_hotplug_support', True):
maxmem_xml = "<maxMemory slots='%s'
unit='MiB'>%s</maxMemory>"
params['max_memory'] = maxmem_xml % (slots, maxmemory)
--
2.1.0