[PATCHv2 1/2] Fix: filter unsupported source type from volume list

From: Royce Lv <lvroyce@linux.vnet.ibm.com> For disk attachment, isos should not be listed, and cdrom should just accept isos. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/js/src/kimchi.guest_storage_add.main.js b/ui/js/src/kimchi.guest_storage_add.main.js index a8c5acb..ca7f7cf 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -33,11 +33,12 @@ kimchi.guest_storage_add_main = function() { var pathTextbox = $('input[name="path"]', storageAddForm); var poolTextbox = $('input[name="pool"]', storageAddForm); var volTextbox = $('input[name="vol"]', storageAddForm); + var selectType = $(typeTextbox).val(); typeTextbox.change(function() { $('#guest-storage-bus').selectMenu(); var pathObject = {'cdrom': ".path-section", 'disk': '.volume-section'} - var selectType = $(this).val(); + selectType = $(this).val(); $.each(pathObject, function(type, value) { if(selectType == type){ $(value).removeClass('hidden'); @@ -75,11 +76,12 @@ kimchi.guest_storage_add_main = function() { poolTextbox.change(function() { var options = []; kimchi.listStorageVolumes($(this).val(), function(result) { + var validVolType = { cdrom: /iso/, disk: /^(raw|qcow|qcow2|bochs|qed|vmdk)$/}; $('#guest-disk').selectMenu(); if (result.length) { $.each(result, function(index, value) { // Only unused volume can be attached - if (value.ref_cnt == 0) { + if ((value.ref_cnt == 0) && (validVolType[selectType].test(value.format))) { options.push({ label: value.name, value: value.name -- 1.8.3.2

From: Royce Lv <lvroyce@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@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
participants (2)
-
Aline Manera
-
lvroyce0210@gmail.com