[PATCH v2][Kimchi 1/2] Issue #838: Extend memory hotplug feature test

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@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

This patch block UI memory and max memory inputs to avoid problems with max memory tag and memory hotplug in distros that do not support this feature. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_edit_main.js | 11 ++++++++++- ui/pages/guest-edit.html.tmpl | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js index 9054eec..19d9e7d 100644 --- a/ui/js/src/kimchi.guest_edit_main.js +++ b/ui/js/src/kimchi.guest_edit_main.js @@ -679,8 +679,17 @@ kimchi.guest_edit_main = function() { wok.window.open('plugins/kimchi/guest-storage-add.html', 'extendCreateStorage'); }); if ((kimchi.thisVMState === "running") || (kimchi.thisVMState === "paused")) { - $("#form-guest-edit-general input").not("#guest-edit-memory-textbox").prop("disabled", true); + if (kimchi.capabilities.mem_hotplug_support) { + $("#form-guest-edit-general input").not("#guest-edit-memory-textbox").prop("disabled", true); + } else { + $("#form-guest-edit-general input").prop("disabled", true); + } } + if (! kimchi.capabilities.mem_hotplug_support) { + $("#guest-edit-max-memory-textbox").prop("disabled", true); + $("#guest-edit-memory-hotplug-unsupported").removeClass('hidden'); + } + $('#guest-show-max-memory').on('click', function(e) { e.preventDefault; $('#guest-max-memory-panel').slideToggle(); diff --git a/ui/pages/guest-edit.html.tmpl b/ui/pages/guest-edit.html.tmpl index 2a8cfbe..05d0b14 100644 --- a/ui/pages/guest-edit.html.tmpl +++ b/ui/pages/guest-edit.html.tmpl @@ -65,6 +65,7 @@ <div id="guest-max-memory-panel" class="form-group"> <label for="guest-edit-max-memory-textbox">$_("Max Memory (MB)")</label> <input id="guest-edit-max-memory-textbox" class="form-control" name="max-memory" type="number" min="1024" step="1024" /> + <p id="guest-edit-memory-hotplug-unsupported" class="help-block hidden"><i class="fa fa-info-circle"></i> $_("Host does not support memory hotplug")</p> </div> <div class="form-group"> <label for="guest-edit-icon-textbox">$_("Icon")</label> -- 2.1.0
participants (2)
-
Aline Manera
-
Rodrigo Trujillo