:p
atchew
Login
Allow disk bus to be specified on creation based on commits: Allow disks to update cache and io flags Add tests to verify if cache and io of a disk can be changed Ramon Medeiros (2): Bug fix #1091: Allow to set disk performance options per guest and template Add tests for disk creation with specified bus driver model/vmstorages.py | 4 +++- tests/test_model.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Allow vmstorage creation passing disk bus Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- model/vmstorages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/vmstorages.py b/model/vmstorages.py index XXXXXXX..XXXXXXX 100644 --- a/model/vmstorages.py +++ b/model/vmstorages.py @@ -XXX,XX +XXX,XX @@ class VMStoragesModel(object): raise InvalidParameter("KCHVMSTOR0019E") dom = VMModel.get_vm(vm_name, self.conn) - params['bus'] = _get_device_bus(params['type'], dom) + + if params.get('bus') == None: + params['bus'] = _get_device_bus(params['type'], dom) if is_s390x() and params['type'] == 'disk' and 'dir_path' in params: if 'format' not in params: -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_model.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_model.py b/tests/test_model.py index XXXXXXX..XXXXXXX 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -XXX,XX +XXX,XX @@ class ModelTests(unittest.TestCase): self.assertRaises(InvalidParameter, inst.vmstorages_create, vm_name, cdrom_args) + # try add disk with specified bus + disk_args = {"type": "disk", + "pool": pool, + "vol": vol, + "bus": "scsi"} + disk = inst.vmstorages_create(vm_name, disk_args) + disk_info = inst.vmstorage_lookup(vm_name, disk) + self.assertEquals("scsi", disk_info['bus']) + self.assertTrue(disk_info["dev"].startswith("sd")) + inst.vmstorage_delete(vm_name, disk) + # Cold plug and unplug a disk disk = _attach_disk() inst.vmstorage_delete(vm_name, disk) -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Changes: v2: Use REST API for tests General fixes Ramon Medeiros (3): Allow disks to update cache and io flags Bug fix #1091: Allow to set disk performance options per guest and template Add tests to verify if cache and io of a disk can be changed API.json | 11 ++++++++++- docs/API.md | 3 +++ i18n.py | 1 - model/vmstorages.py | 55 +++++++++++++++++++++++++++++++++++------------------ tests/test_rest.py | 28 +++++++++++++++++++++++++++ xmlutils/disk.py | 12 +++++++++++- 6 files changed, 88 insertions(+), 22 deletions(-) -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
This is a part of Bug fix #1092 solution Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- API.json | 11 ++++++++++- docs/API.md | 3 +++ i18n.py | 1 - model/vmstorages.py | 51 +++++++++++++++++++++++++++++++++------------------ xmlutils/disk.py | 12 +++++++++++- 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/API.json b/API.json index XXXXXXX..XXXXXXX 100644 --- a/API.json +++ b/API.json @@ -XXX,XX +XXX,XX @@ "description": "Path of iso image file or disk mount point", "type": "string", "pattern": "^(|(/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$", - "required": true, "error": "KCHVMSTOR0003E" + }, + "cache": { + "description": "Cache options", + "type": "string", + "pattern": "^(none|writethrough|writeback|directsync|unsafe|default)$" + }, + "io": { + "description": "I/O options", + "type": "string", + "pattern": "^(native|threads|default)$" } }, "additionalProperties": false diff --git a/docs/API.md b/docs/API.md index XXXXXXX..XXXXXXX 100644 --- a/docs/API.md +++ b/docs/API.md @@ -XXX,XX +XXX,XX @@ Represents a snapshot of the Virtual Machine's primary monitor. * bus: Bus type of disk attached. * **PUT**: Update storage information * path: Path of cdrom iso. Can not be blank. Now just support cdrom type. + * io: IO settings for disks. Values accepted: native, threads and default. + * cache: Cache settings for disks. Values accepted: none, writethrough, + writeback, directsync, unsafe and default. * **DELETE**: Remove the storage. **Actions (POST):** diff --git a/i18n.py b/i18n.py index XXXXXXX..XXXXXXX 100644 --- a/i18n.py +++ b/i18n.py @@ -XXX,XX +XXX,XX @@ messages = { "KCHVMSTOR0002E": _("Invalid storage type. Types supported: 'cdrom', 'disk'"), "KCHVMSTOR0003E": _("The path '%(value)s' is not a valid local/remote path for the device"), - "KCHVMSTOR0006E": _("Only CDROM path can be update."), "KCHVMSTOR0007E": _("The storage device %(dev_name)s does not exist in the virtual machine %(vm_name)s"), "KCHVMSTOR0008E": _("Error while creating new storage device: %(error)s"), "KCHVMSTOR0009E": _("Error while updating storage device: %(error)s"), diff --git a/model/vmstorages.py b/model/vmstorages.py index XXXXXXX..XXXXXXX 100644 --- a/model/vmstorages.py +++ b/model/vmstorages.py @@ -XXX,XX +XXX,XX @@ # # Project Kimchi # -# Copyright IBM Corp, 2015-2016 +# Copyright IBM Corp, 2015-2017 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -XXX,XX +XXX,XX @@ from wok.plugins.kimchi.utils import create_disk_image, is_s390x from wok.plugins.kimchi.xmlutils.disk import get_device_node, get_disk_xml from wok.plugins.kimchi.xmlutils.disk import get_vm_disk_info, get_vm_disks - HOTPLUG_TYPE = ['scsi', 'virtio'] @@ -XXX,XX +XXX,XX @@ class VMStorageModel(object): dom = VMModel.get_vm(vm_name, self.conn) dev_info = self.lookup(vm_name, dev_name) + + # only change path to cdrom devices if dev_info['type'] != 'cdrom': - raise InvalidOperation("KCHVMSTOR0006E") + old_dev, old_xml = get_disk_xml(dev_info) + dev_info.update(params) + dev, xml = get_disk_xml(dev_info) - params['path'] = params.get('path', '') - old_disk_path = dev_info['path'] - new_disk_path = params['path'] - if new_disk_path != old_disk_path: - # An empty path means a CD-ROM was empty or ejected: - if old_disk_path is not '': - old_disk_used_by = get_disk_used_by(self.conn, old_disk_path) - if new_disk_path is not '': - new_disk_used_by = get_disk_used_by(self.conn, new_disk_path) + # remove + self.delete(vm_name, dev_name) - dev_info.update(params) - dev, xml = get_disk_xml(dev_info) + try: + dom.attachDeviceFlags(xml) + except Exception as e: + dom.attachDeviceFlags(old_xml) + raise OperationFailed("KCHVMSTOR0009E", {'error': e.message}) - try: - dom.updateDeviceFlags(xml, get_vm_config_flag(dom, 'all')) - except Exception as e: - raise OperationFailed("KCHVMSTOR0009E", {'error': e.message}) + else: + dev_info.update(params) + dev, xml = get_disk_xml(dev_info) + + params['path'] = params.get('path', '') + old_disk_path = dev_info['path'] + new_disk_path = params['path'] + if new_disk_path != old_disk_path: + # An empty path means a CD-ROM was empty or ejected: + if old_disk_path is not '': + old_disk_used_by = get_disk_used_by(self.conn, + old_disk_path) + if new_disk_path is not '': + new_disk_used_by = get_disk_used_by(self.conn, + new_disk_path) + + try: + dom.updateDeviceFlags(xml, get_vm_config_flag(dom, 'all')) + except Exception as e: + raise OperationFailed("KCHVMSTOR0009E", {'error': e.message}) try: if old_disk_used_by is not None and \ diff --git a/xmlutils/disk.py b/xmlutils/disk.py index XXXXXXX..XXXXXXX 100644 --- a/xmlutils/disk.py +++ b/xmlutils/disk.py @@ -XXX,XX +XXX,XX @@ # # Project Kimchi # -# Copyright IBM Corp, 2015-2016 +# Copyright IBM Corp, 2015-2017 # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -XXX,XX +XXX,XX @@ def get_disk_xml(params): if disk_type is None: disk_type = _get_disk_type(path) if len(path) > 0 else 'file' disk = E.disk(type=disk_type, device=params['type']) + + # <driver /> driver = E.driver(name='qemu', type=params['format']) if params['type'] != 'cdrom': driver.set('cache', 'none') @@ -XXX,XX +XXX,XX @@ def get_disk_xml(params): if params.get('pool_type') == "netfs": driver.set("io", "native") + # set io + if params.get("io") is not None: + driver.set("io", params.get("io")) + + # set cache + if params.get("cache") is not None: + driver.set("cache", params.get("cache")) + disk.append(driver) # Get device name according to bus and index values -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Allow vmstorage creation passing disk bus Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- model/vmstorages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/vmstorages.py b/model/vmstorages.py index XXXXXXX..XXXXXXX 100644 --- a/model/vmstorages.py +++ b/model/vmstorages.py @@ -XXX,XX +XXX,XX @@ class VMStoragesModel(object): raise InvalidParameter("KCHVMSTOR0019E") dom = VMModel.get_vm(vm_name, self.conn) - params['bus'] = _get_device_bus(params['type'], dom) + + if params.get('bus') is None: + params['bus'] = _get_device_bus(params['type'], dom) if is_s390x() and params['type'] == 'disk' and 'dir_path' in params: if 'format' not in params: -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_rest.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_rest.py b/tests/test_rest.py index XXXXXXX..XXXXXXX 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -XXX,XX +XXX,XX @@ class RestTests(unittest.TestCase): resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT') self.assertEquals(400, resp.status) + # add volume as scsi + mock_base = '/tmp/mock.img' + os.system("qemu-img create -f qcow2 %s 100M" % mock_base) + req = json.dumps({'type': 'disk', + 'path': mock_base, + 'bus': 'scsi'}) + resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages', + req, 'POST') + self.assertEquals(201, resp.status) + resp = json.loads(resp.read()) + self.assertEquals("scsi", resp["bus"]) + dev = resp["dev"] + + # change io/cache + req = json.dumps({"io": "threads", "cache": "unsafe"}) + resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages/' + + str(dev), req, 'PUT') + self.assertEquals(200, resp.status) + resp = json.loads(resp.read()) + self.assertEquals('threads', resp['io']) + self.assertEquals('unsafe', resp['cache']) + + # remove disk + resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd/storages/' + + str(dev), req, 'DELETE') + os.system("rm -rf " + mock_base) + self.assertEquals(204, resp.status) + def test_vm_lifecycle(self): # Create a Template req = json.dumps({'name': 'test', -- 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel