[PATCH] [Kimchi 0/2] Fix issues while attaching new disk to VM

Aline Manera (2): Bug fix: Display error when creating new disk to attach to guest Bug fix: Do not allow user selects invalid volume format to create a new volume API.json | 6 +++--- docs/API.md | 6 +++--- i18n.py | 4 ++-- model/storagevolumes.py | 2 +- model/vmstorages.py | 2 +- tests/test_template.py | 3 +-- ui/js/src/kimchi.guest_storage_add.main.js | 11 +++++++---- ui/pages/i18n.json.tmpl | 1 + ui/pages/template-edit.html.tmpl | 4 ---- 9 files changed, 19 insertions(+), 20 deletions(-) -- 2.5.5

Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- model/storagevolumes.py | 2 +- ui/js/src/kimchi.guest_storage_add.main.js | 7 +++++-- ui/pages/i18n.json.tmpl | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/model/storagevolumes.py b/model/storagevolumes.py index 83f38e2..e037e35 100644 --- a/model/storagevolumes.py +++ b/model/storagevolumes.py @@ -154,7 +154,7 @@ class StorageVolumesModel(object): pool.createXML(xml, 0) except libvirt.libvirtError as e: raise OperationFailed("KCHVOL0007E", - {'name': name, 'pool': pool, + {'name': name, 'pool': pool_name, 'err': e.get_error_message()}) vol_info = StorageVolumeModel(conn=self.conn, diff --git a/ui/js/src/kimchi.guest_storage_add.main.js b/ui/js/src/kimchi.guest_storage_add.main.js index fb7fed3..4b5c154 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -341,9 +341,12 @@ kimchi.guest_storage_add_main = function() { setTimeout(monitorTask, 2000); $(submitButton).prop('disabled', true); } else if (status === "failed") { - var errText = result['reason'] || + var errText = result['message'] || result['responseJSON']['reason']; - $(submitButton).prop('disabled', true); + $(submitButton).text(i18n['KCHVMCD6002M']); + $(submitButton).prop('disabled', false); + $(capacityTextbox).prop('disabled', false); + $(formatTextbox).prop('disabled', false); wok.message.error(errText, '#alert-modal-container2'); } }); diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index 95c5600..e152989 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -71,6 +71,7 @@ "KCHVM0003E": "$_("Current CPUs value cannot be higher than Max CPU value")", "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", + "KCHVMCD6002M": "$_("Attach")", "KCHVMCD6003M": "$_("Attaching...")", "KCHVMCD6009M": "$_("This disk will be detached permanently and you can re-attach it. Continue to detach it?")", -- 2.5.5

When trying to create a volume with one of the formats: bochs, cloop, cow, dmg - an error is raised by libvirt as listed below: [alinefm@alinefm-TP440 kimchi]$ sudo virsh vol-create default bochs.xml error: internal error: Child process (/usr/bin/qemu-img create -f bochs /var/lib/libvirt/images/fedora231462484883854.img 1K) unexpected exit status 1: qemu-img: /var/lib/libvirt/images/fedora231462484883854.img: Format driver 'bochs' does not support image creation [alinefm@alinefm-TP440 kimchi]$ sudo virsh vol-create default cloop.xml error: internal error: Child process (/usr/bin/qemu-img create -f cloop /var/lib/libvirt/images/fedora231462484883854.img 1K) unexpected exit status 1: qemu-img: /var/lib/libvirt/images/fedora231462484883854.img: Format driver 'cloop' does not support image creation [alinefm@alinefm-TP440 kimchi]$ sudo virsh vol-create default cow.xml error: internal error: Child process (/usr/bin/qemu-img create -f cow /var/lib/libvirt/images/fedora231462484883854.img 1K) unexpected exit status 1: qemu-img: /var/lib/libvirt/images/fedora231462484883854.img: Unknown file format 'cow' [alinefm@alinefm-TP440 kimchi]$ sudo virsh vol-create default dmg.xml error: internal error: Child process (/usr/bin/qemu-img create -f dmg /var/lib/libvirt/images/fedora231462484883854.img 1K) unexpected exit status 1: qemu-img: /var/lib/libvirt/images/fedora231462484883854.img: Format driver 'dmg' does not support image creation To prevent this error, do not allow user to selects one of those invalid formats. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- API.json | 6 +++--- docs/API.md | 6 +++--- i18n.py | 4 ++-- model/vmstorages.py | 2 +- tests/test_template.py | 3 +-- ui/js/src/kimchi.guest_storage_add.main.js | 4 ++-- ui/pages/template-edit.html.tmpl | 4 ---- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/API.json b/API.json index d452270..40278bb 100644 --- a/API.json +++ b/API.json @@ -230,7 +230,7 @@ "format": { "description": "The format of the volume", "type": "string", - "pattern": "^(|bochs|cloop|cow|dmg|qcow|qcow2|qed|raw|vmdk|vpc)$", + "pattern": "^(|qcow|qcow2|qed|raw|vmdk|vpc)$", "error": "KCHVOL0015E" }, "url": { @@ -536,7 +536,7 @@ "format": { "description": "Type of the image of the disk", "type": "string", - "pattern": "^(bochs|cloop|cow|dmg|qcow|qcow2|qed|raw|vmdk|vpc)$", + "pattern": "^(qcow|qcow2|qed|raw|vmdk|vpc)$", "error": "KCHTMPL0027E" }, "size": { @@ -708,7 +708,7 @@ "format": { "description": "Type of the image of the disk", "type": "string", - "pattern": "^(bochs|cloop|cow|dmg|qcow|qcow2|qed|raw|vmdk|vpc)$", + "pattern": "^(qcow|qcow2|qed|raw|vmdk|vpc)$", "error": "KCHTMPL0027E" }, "pool": { diff --git a/docs/API.md b/docs/API.md index a94f0f9..9d42c53 100644 --- a/docs/API.md +++ b/docs/API.md @@ -309,7 +309,7 @@ Represents a snapshot of the Virtual Machine's primary monitor. (either *size* or *volume* must be specified): * index: The device index * size: The device size in GB - * format: Format of the image. Valid formats: bochs, cloop, cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc + * format: Format of the image. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc * pool: Storage pool information * name: URI of the storagepool where disk will be created * base: Base image of this disk @@ -417,7 +417,7 @@ A interface represents available network interface on VM. * index: The device index * size: The device size in GB * volume: A volume name that contains the initial disk contents - * format: Format of the image. Valid formats: bochs, cloop, cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc. + * format: Format of the image. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc. * pool: Information about the pool where disk or volume will be created * name: URI of the storagepool * type: Type of the storagepool (dir, nfs, scsci, iscsi, etc) @@ -462,7 +462,7 @@ A interface represents available network interface on VM. * index: The device index * size: The device size in GB * volume: A volume name that contains the initial disk contents - * format: Format of the image. Valid formats: bochs, cloop, cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc. + * format: Format of the image. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc. * pool: Storage pool information * name: URI of the storagepool where template allocates vm disk. * graphics *(optional)*: A dict of graphics paramenters of this template diff --git a/i18n.py b/i18n.py index 39f5e57..db245c0 100644 --- a/i18n.py +++ b/i18n.py @@ -177,7 +177,7 @@ messages = { "KCHTMPL0022E": _("Disk size must be an integer greater than 1GB."), "KCHTMPL0024E": _("Cannot identify base image %(path)s format"), "KCHTMPL0026E": _("When specifying CPU topology, each element must be an integer greater than zero."), - "KCHTMPL0027E": _("Invalid disk image format. Valid formats: bochs, cloop, cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc."), + "KCHTMPL0027E": _("Invalid disk image format. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc."), "KCHTMPL0028E": _("When setting template disks, following parameters are required: 'index', 'pool name', 'format', 'size' or 'volume' (for scsi/iscsi pools)"), "KCHTMPL0029E": _("Disk format must be 'raw', for logical, iscsi, and scsi pools."), "KCHTMPL0030E": _("Memory expects an object with one or both parameters: 'current' and 'maxmemory'"), @@ -234,7 +234,7 @@ messages = { "KCHVOL0012E": _("Storage type %(type)s does not support volume create and delete"), "KCHVOL0013E": _("Storage volume name must be a string"), "KCHVOL0014E": _("Storage volume allocation must be an integer number"), - "KCHVOL0015E": _("Storage volume format not supported. Valid formats: bochs, cloop, cow, dmg, qcow, qcow2, qed, raw, vmdk, vpc."), + "KCHVOL0015E": _("Storage volume format not supported. Valid formats: qcow, qcow2, qed, raw, vmdk, vpc."), "KCHVOL0016E": _("Storage volume requires a volume name"), "KCHVOL0017E": _("Unable to update database with storage volume information due error: %(err)s"), "KCHVOL0018E": _("Only one of parameter %(param)s can be specified"), diff --git a/model/vmstorages.py b/model/vmstorages.py index 31a7d95..b55b156 100644 --- a/model/vmstorages.py +++ b/model/vmstorages.py @@ -116,7 +116,7 @@ class VMStoragesModel(object): raise InvalidParameter("KCHVMSTOR0016E") valid_format = { - "disk": ["raw", "bochs", "qcow", "qcow2", "qed", "vmdk"], + "disk": ["raw", "qcow", "qcow2", "qed", "vmdk", "vpc"], "cdrom": "iso"} if vol_info['type'] == 'file': diff --git a/tests/test_template.py b/tests/test_template.py index 5de8393..c0ca14f 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -309,8 +309,7 @@ class TemplateTests(unittest.TestCase): # For all supported types, edit the template and check if # the change was made. - disk_types = ['bochs', 'cloop', 'cow', 'dmg', 'qcow', 'qcow2', - 'qed', 'raw', 'vmdk', 'vpc'] + disk_types = ['qcow', 'qcow2', 'qed', 'raw', 'vmdk', 'vpc'] for disk_type in disk_types: disk_data = {'disks': [{'index': 0, 'format': disk_type, 'size': 10, 'pool': {'name': DEFAULT_POOL}}]} diff --git a/ui/js/src/kimchi.guest_storage_add.main.js b/ui/js/src/kimchi.guest_storage_add.main.js index 4b5c154..29fccab 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -75,7 +75,7 @@ kimchi.guest_storage_add_main = function() { var rbExisting = 'false'; var getFormatList = function() { - var format = ["bochs", "cloop", "cow", "dmg", "qcow", "qcow2", "qed", "raw", "vmdk", "vpc"]; + var format = ["qcow", "qcow2", "qed", "raw", "vmdk", "vpc"]; var selectFormatHTML = ''; var i; for (i = 0; i < format.length; i++) { @@ -182,7 +182,7 @@ kimchi.guest_storage_add_main = function() { selectStorageVolHTML = ''; volTextbox.empty(); kimchi.listStorageVolumes($(this).val(), function(result) { - var validVolType = { cdrom: /iso/, disk: /^(raw|qcow|qcow2|bochs|qed|vmdk)$/}; + var validVolType = { cdrom: /iso/, disk: /^(raw|qcow|qcow2|qed|vmdk|vpc)$/}; if (result.length) { $.each(result, function(index, value) { // Only unused volume can be attached diff --git a/ui/pages/template-edit.html.tmpl b/ui/pages/template-edit.html.tmpl index 8fb4a56..c880ef4 100644 --- a/ui/pages/template-edit.html.tmpl +++ b/ui/pages/template-edit.html.tmpl @@ -189,10 +189,6 @@ <select id="diskFormat"> <option value="qcow2">qcow2</option> <option value="raw">raw</option> - <option value="bochs">bochs</option> - <option value="cloop">cloop</option> - <option value="cow">cow</option> - <option value="dmg">dmg</option> <option value="qcow">qcow</option> <option value="qed">qed</option> <option value="vmdk">vmdk</option> -- 2.5.5

Reviewed-By: Lucio Correia <luciojhc@linux.vnet.ibm.com> On 05-05-2016 20:14, Aline Manera wrote:
Aline Manera (2): Bug fix: Display error when creating new disk to attach to guest Bug fix: Do not allow user selects invalid volume format to create a new volume
API.json | 6 +++--- docs/API.md | 6 +++--- i18n.py | 4 ++-- model/storagevolumes.py | 2 +- model/vmstorages.py | 2 +- tests/test_template.py | 3 +-- ui/js/src/kimchi.guest_storage_add.main.js | 11 +++++++---- ui/pages/i18n.json.tmpl | 1 + ui/pages/template-edit.html.tmpl | 4 ---- 9 files changed, 19 insertions(+), 20 deletions(-)
-- Lucio Correia Software Engineer IBM LTC Brazil
participants (2)
-
Aline Manera
-
Lucio Correia