[Kimchi-devel] [PATCHv2 2/2] Reject improper format for storage types
lvroyce0210 at gmail.com
lvroyce0210 at gmail.com
Wed Sep 24 13:44:09 UTC 2014
From: Royce Lv <lvroyce at linux.vnet.ibm.com>
Reject non-iso storage volume for cdrom attachment,
and non supported foramt types for disk attachment
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 1 +
src/kimchi/model/vmstorages.py | 13 ++++++++++---
tests/test_model.py | 7 +++++++
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index e83843c..877d7f7 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -259,6 +259,7 @@ messages = {
"KCHVMSTOR0015E": _("Cannot retrieve disk path information for given pool/volume: %(error)s"),
"KCHVMSTOR0016E": _("Volume already in use by other virtual machine."),
"KCHVMSTOR0017E": _("Only one of path or pool/volume can be specified to add a new virtual machine disk"),
+ "KCHVMSTOR0018E": _("Volume chosen with format %(format)s does not fit storage type %(type)s"),
"KCHREPOS0001E": _("YUM Repository ID must be one word only string."),
"KCHREPOS0002E": _("Repository URL must be an http://, ftp:// or file:// URL."),
diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
index 54e2685..a4faa6b 100644
--- a/src/kimchi/model/vmstorages.py
+++ b/src/kimchi/model/vmstorages.py
@@ -153,9 +153,16 @@ class VMStoragesModel(object):
if vol_info['ref_cnt'] != 0:
raise InvalidParameter("KCHVMSTOR0016E")
- supported_format = ["raw", "bochs", "qcow", "qcow2", "qed", "vmdk"]
- if vol_info['format'] in supported_format:
- params['format'] = vol_info['format']
+ supported_format = {
+ "disk": ["raw", "bochs", "qcow", "qcow2", "qed", "vmdk"],
+ "cdrom": "iso"}
+ if vol_info['format'] in supported_format[params['type']]:
+ if params['type'] == 'disk':
+ params['format'] = vol_info['format']
+ else:
+ raise InvalidParameter("KCHVMSTOR0018E",
+ {"format": vol_info['format'],
+ "type": params['type']})
params['path'] = vol_info['path']
params['src_type'] = _check_path(params['path'])
if (params['bus'] not in HOTPLUG_TYPE
diff --git a/tests/test_model.py b/tests/test_model.py
index 4e517c1..6d70a96 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -276,6 +276,13 @@ class ModelTests(unittest.TestCase):
prev_count = len(inst.vmstorages_get_list(vm_name))
self.assertEquals(1, prev_count)
+ # Volume format with mismatched type raise error
+ cdrom_args = {"type": "cdrom",
+ "pool": pool,
+ "vol": vol}
+ self.assertRaises(InvalidParameter,
+ inst.vmstorages_create, vm_name, cdrom_args)
+
# Cold plug and unplug a disk
disk = _attach_disk()
inst.vmstorage_delete(vm_name, disk)
--
1.8.3.2
More information about the Kimchi-devel
mailing list