[Kimchi-devel] [PATCH] [Kimchi 2/2] Bug fix: Do not allow user selects invalid volume format to create a new volume

Aline Manera alinefm at linux.vnet.ibm.com
Thu May 5 23:14:50 UTC 2016


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




More information about the Kimchi-devel mailing list