[PATCHv3 0/2] issue#382: Fix adding disk submitted with wrong default value

From: Royce Lv <lvroyce@linux.vnet.ibm.com> v1>v3, Fix path validation, fix default value set logic Royce Lv (2): issue#382 :Change false default value issue#382: Validate form for adding guest cdrom ui/js/src/kimchi.guest_storage_add.main.js | 40 ++++++++++++++++++++++++++++-- ui/pages/i18n.json.tmpl | 7 ++++-- 2 files changed, 43 insertions(+), 4 deletions(-) -- 1.8.3.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Default value for pool and volume were passed when path parameter is set. Fix this wrong behavior by delete the default values. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 12 ++++++++++-- 1 file changed, 10 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 6af00cc..80045d3 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -50,6 +50,16 @@ kimchi.guest_storage_add_main = function() { } }); + if ($(".path-section").hasClass('hidden')) { + $(poolTextbox).val('default'); + $(poolTextbox).change(); + $(pathTextbox).val(""); + } + else { + $(poolTextbox).val(""); + $(volTextbox).val(""); + } + $.each(types, function(index, elem){ if (selectType == elem.value) { var buses = new Array(); @@ -74,8 +84,6 @@ kimchi.guest_storage_add_main = function() { }); } }); - $(poolTextbox).val('default'); - $(poolTextbox).change(); kimchi.select('guest-add-storage-pool-list', options); } }); -- 1.8.3.2

Reviewed-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> On 06/26/2014 02:47 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Default value for pool and volume were passed when path parameter is set. Fix this wrong behavior by delete the default values.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 12 ++++++++++-- 1 file changed, 10 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 6af00cc..80045d3 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -50,6 +50,16 @@ kimchi.guest_storage_add_main = function() { } });
+ if ($(".path-section").hasClass('hidden')) { + $(poolTextbox).val('default'); + $(poolTextbox).change(); + $(pathTextbox).val(""); + } + else { + $(poolTextbox).val(""); + $(volTextbox).val(""); + } + $.each(types, function(index, elem){ if (selectType == elem.value) { var buses = new Array(); @@ -74,8 +84,6 @@ kimchi.guest_storage_add_main = function() { }); } }); - $(poolTextbox).val('default'); - $(poolTextbox).change(); kimchi.select('guest-add-storage-pool-list', options); } });
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add function for cdrom and disk form validation, so that cdrom will not be created when no path given. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 28 ++++++++++++++++++++++++++++ ui/pages/i18n.json.tmpl | 7 +++++-- 2 files changed, 33 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 80045d3..a7e4c4c 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() { }); }); + var validateCDROM = function(settings) { + if (/(^\/.*)$/.test(settings['path'])) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0001E'); + return false; + } + } + + var validateDisk = function(settings) { + if (settings['pool'] && settings['vol']) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0002E'); + return false; + } + } + + validator = {cdrom: validateCDROM, disk: validateDisk}; var submitForm = function(event) { if (submitButton.prop('disabled')) { return false; @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() { settings[$(c).attr('name')] = $(c).val(); } }); + // Validate form for cdrom and disk + validateSpecifiedForm = validator[settings['type']]; + if (!validateSpecifiedForm(settings)) { + $(submitButton).prop('disabled', false); + $.each([submitButton, nameTextbox, pathTextbox, poolTextbox, volTextbox], function(i, c) { + $(c).prop('disabled', false); + }); + return false; + } $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']); kimchi.addVMStorage(settings, function(result) { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index ce23bc4..d765cf2 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -162,5 +162,8 @@ "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", "KCHPOOL6010M": "$_("Looking for available partitions ...")", "KCHPOOL6011M": "$_("No available partitions found.")", - "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -} \ No newline at end of file + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")", + + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local path and cannot be blank.")", + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")" +} -- 1.8.3.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add function for cdrom and disk form validation, so that cdrom will not be created when no path given.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 28 ++++++++++++++++++++++++++++ ui/pages/i18n.json.tmpl | 7 +++++-- 2 files changed, 33 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 80045d3..a7e4c4c 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() { }); });
+ var validateCDROM = function(settings) { + if (/(^\/.*)$/.test(settings['path']))
On 06/26/2014 02:47 PM, lvroyce@linux.vnet.ibm.com wrote: the RE looks like strangely. But It can works well. seem you you can check the path is starts with "/" /^(\/.*)+$/.test(settings['path'] ) or /^(\/.*)$/.test(settings['path'] ) or /^\//.test ?
+ return true; + else { + kimchi.message.error.code('KCHVMSTOR0001E'); + return false; + } + } + + var validateDisk = function(settings) { + if (settings['pool'] && settings['vol']) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0002E'); + return false; + } + } + + validator = {cdrom: validateCDROM, disk: validateDisk}; var submitForm = function(event) { if (submitButton.prop('disabled')) { return false; @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() { settings[$(c).attr('name')] = $(c).val(); } }); + // Validate form for cdrom and disk + validateSpecifiedForm = validator[settings['type']]; + if (!validateSpecifiedForm(settings)) { + $(submitButton).prop('disabled', false); + $.each([submitButton, nameTextbox, pathTextbox, poolTextbox, volTextbox], function(i, c) { + $(c).prop('disabled', false); + }); + return false; + } $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']);
kimchi.addVMStorage(settings, function(result) { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index ce23bc4..d765cf2 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -162,5 +162,8 @@ "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", "KCHPOOL6010M": "$_("Looking for available partitions ...")", "KCHPOOL6011M": "$_("No available partitions found.")", - "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -} \ No newline at end of file + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")", + + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local path and cannot be blank.")", + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")" +} just a question about the difference among "cannot", "can not" and "can't"? :-) I check the dictionary, seems they are same.
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 2014年06月26日 21:46, Sheldon wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add function for cdrom and disk form validation, so that cdrom will not be created when no path given.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 28 ++++++++++++++++++++++++++++ ui/pages/i18n.json.tmpl | 7 +++++-- 2 files changed, 33 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 80045d3..a7e4c4c 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() { }); });
+ var validateCDROM = function(settings) { + if (/(^\/.*)$/.test(settings['path']))
On 06/26/2014 02:47 PM, lvroyce@linux.vnet.ibm.com wrote: the RE looks like strangely. But It can works well. seem you you can check the path is starts with "/" /^(\/.*)+$/.test(settings['path'] ) My fault, I put bracket in the wrong place. or /^(\/.*)$/.test(settings['path'] ) or /^\//.test ?
+ return true; + else { + kimchi.message.error.code('KCHVMSTOR0001E'); + return false; + } + } + + var validateDisk = function(settings) { + if (settings['pool'] && settings['vol']) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0002E'); + return false; + } + } + + validator = {cdrom: validateCDROM, disk: validateDisk}; var submitForm = function(event) { if (submitButton.prop('disabled')) { return false; @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() { settings[$(c).attr('name')] = $(c).val(); } }); + // Validate form for cdrom and disk + validateSpecifiedForm = validator[settings['type']]; + if (!validateSpecifiedForm(settings)) { + $(submitButton).prop('disabled', false); + $.each([submitButton, nameTextbox, pathTextbox, poolTextbox, volTextbox], function(i, c) { + $(c).prop('disabled', false); + }); + return false; + } $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']);
kimchi.addVMStorage(settings, function(result) { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index ce23bc4..d765cf2 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -162,5 +162,8 @@ "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", "KCHPOOL6010M": "$_("Looking for available partitions ...")", "KCHPOOL6011M": "$_("No available partitions found.")", - "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -} \ No newline at end of file + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")", + + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local path and cannot be blank.")", + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")" +} just a question about the difference among "cannot", "can not" and "can't"? :-) I check the dictionary, seems they are same.

On 06/26/2014 03:47 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add function for cdrom and disk form validation, so that cdrom will not be created when no path given.
Royce, the backend should be able to handle those cases. It is the error I got when I tried to add a cdrom without passing a "path" using curl alinefm@alinefm:~/mail-patches$ curl -u banana:linux99 -H "Content-Type: application/json" -H "Accept: application/json" https://localhost:8001/vms/Ubuntu13-10/storages -d'{"type": "cdrom"}' -X POST -k { "reason":"The server encountered an unexpected condition which prevented it from fulfilling the request.", "code":"500 Internal Server Error", "call_stack":"Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py\", line 656, in respond\n response.body = self.handler()\n File \"/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py\", line 188, in __call__\n self.body = self.oldhandler(*args, **kwargs)\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py\", line 34, in __call__\n return self.callable(*self.args, **self.kwargs)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 270, in index\n return self.create(parse_request(), *args)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 209, in create\n name = create(*args)\n File \"/home/alinefm/kimchi/src/kimchi/model/vmstorages.py\", line 171, in create\n params['src_type'] = _check_path(params['path'])\nKeyError: 'path'\n" And in console: 127.0.0.1 - - [26/Jun/2014:17:19:12] "POST /vms/Ubuntu13-10/storages HTTP/1.0" 500 1009 "" "curl/7.27.0" [26/Jun/2014:17:19:14] HTTP Request Headers: AUTHORIZATION: Basic YmFuYW5hOmxpbnV4OTk= Content-Length: 17 HOST: localhost CONNECTION: close Remote-Addr: 127.0.0.1 X-REAL-IP: 127.0.0.1 ACCEPT: application/json USER-AGENT: curl/7.27.0 X-FORWARDED-FOR: 127.0.0.1 Content-Type: application/json [26/Jun/2014:17:19:14] HTTP Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__ self.body = self.oldhandler(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__ return self.callable(*self.args, **self.kwargs) File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 270, in index return self.create(parse_request(), *args) File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 209, in create name = create(*args) File "/home/alinefm/kimchi/src/kimchi/model/vmstorages.py", line 171, in create params['src_type'] = _check_path(params['path']) KeyError: 'path' The same error occurs when I used type == 'disk' alinefm@alinefm:~/mail-patches$ curl -u banana:linux99 -H "Content-Type: application/json" -H "Accept: application/json" https://localhost:8001/vms/Ubuntu13-10/storages -d'{"type": "disk"}' -X POST -k { "reason":"The server encountered an unexpected condition which prevented it from fulfilling the request.", "code":"500 Internal Server Error", "call_stack":"Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py\", line 656, in respond\n response.body = self.handler()\n File \"/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py\", line 188, in __call__\n self.body = self.oldhandler(*args, **kwargs)\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py\", line 34, in __call__\n return self.callable(*self.args, **self.kwargs)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 270, in index\n return self.create(parse_request(), *args)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 209, in create\n name = create(*args)\n File \"/home/alinefm/kimchi/src/kimchi/model/vmstorages.py\", line 171, in create\n params['src_type'] = _check_path(params['path'])\nKeyError: 'path'\n"
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 28 ++++++++++++++++++++++++++++ ui/pages/i18n.json.tmpl | 7 +++++-- 2 files changed, 33 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 80045d3..a7e4c4c 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() { }); });
+ var validateCDROM = function(settings) { + if (/(^\/.*)$/.test(settings['path'])) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0001E'); + return false; + } + } + + var validateDisk = function(settings) { + if (settings['pool'] && settings['vol']) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0002E'); + return false; + } + } + + validator = {cdrom: validateCDROM, disk: validateDisk}; var submitForm = function(event) { if (submitButton.prop('disabled')) { return false; @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() { settings[$(c).attr('name')] = $(c).val(); } }); + // Validate form for cdrom and disk + validateSpecifiedForm = validator[settings['type']]; + if (!validateSpecifiedForm(settings)) { + $(submitButton).prop('disabled', false); + $.each([submitButton, nameTextbox, pathTextbox, poolTextbox, volTextbox], function(i, c) { + $(c).prop('disabled', false); + }); + return false; + } $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']);
kimchi.addVMStorage(settings, function(result) { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index ce23bc4..d765cf2 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -162,5 +162,8 @@ "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", "KCHPOOL6010M": "$_("Looking for available partitions ...")", "KCHPOOL6011M": "$_("No available partitions found.")", - "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -} \ No newline at end of file + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")", + + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local path and cannot be blank.")", + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")" +}

On 2014年06月27日 04:23, Aline Manera wrote:
On 06/26/2014 03:47 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add function for cdrom and disk form validation, so that cdrom will not be created when no path given.
Royce, the backend should be able to handle those cases.
It is the error I got when I tried to add a cdrom without passing a "path" using curl Yes, backend needs to handle this. 500Error needs to be fixed. Also front end will alert user to when the wrong input is coming for early error discovery.
alinefm@alinefm:~/mail-patches$ curl -u banana:linux99 -H "Content-Type: application/json" -H "Accept: application/json" https://localhost:8001/vms/Ubuntu13-10/storages -d'{"type": "cdrom"}' -X POST -k { "reason":"The server encountered an unexpected condition which prevented it from fulfilling the request.", "code":"500 Internal Server Error", "call_stack":"Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py\", line 656, in respond\n response.body = self.handler()\n File \"/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py\", line 188, in __call__\n self.body = self.oldhandler(*args, **kwargs)\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py\", line 34, in __call__\n return self.callable(*self.args, **self.kwargs)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 270, in index\n return self.create(parse_request(), *args)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 209, in create\n name = create(*args)\n File \"/home/alinefm/kimchi/src/kimchi/model/vmstorages.py\", line 171, in create\n params['src_type'] = _check_path(params['path'])\nKeyError: 'path'\n"
And in console:
127.0.0.1 - - [26/Jun/2014:17:19:12] "POST /vms/Ubuntu13-10/storages HTTP/1.0" 500 1009 "" "curl/7.27.0" [26/Jun/2014:17:19:14] HTTP Request Headers: AUTHORIZATION: Basic YmFuYW5hOmxpbnV4OTk= Content-Length: 17 HOST: localhost CONNECTION: close Remote-Addr: 127.0.0.1 X-REAL-IP: 127.0.0.1 ACCEPT: application/json USER-AGENT: curl/7.27.0 X-FORWARDED-FOR: 127.0.0.1 Content-Type: application/json [26/Jun/2014:17:19:14] HTTP Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__ self.body = self.oldhandler(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__ return self.callable(*self.args, **self.kwargs) File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 270, in index return self.create(parse_request(), *args) File "/home/alinefm/kimchi/src/kimchi/control/base.py", line 209, in create name = create(*args) File "/home/alinefm/kimchi/src/kimchi/model/vmstorages.py", line 171, in create params['src_type'] = _check_path(params['path']) KeyError: 'path'
The same error occurs when I used type == 'disk'
alinefm@alinefm:~/mail-patches$ curl -u banana:linux99 -H "Content-Type: application/json" -H "Accept: application/json" https://localhost:8001/vms/Ubuntu13-10/storages -d'{"type": "disk"}' -X POST -k { "reason":"The server encountered an unexpected condition which prevented it from fulfilling the request.", "code":"500 Internal Server Error", "call_stack":"Traceback (most recent call last):\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py\", line 656, in respond\n response.body = self.handler()\n File \"/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py\", line 188, in __call__\n self.body = self.oldhandler(*args, **kwargs)\n File \"/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py\", line 34, in __call__\n return self.callable(*self.args, **self.kwargs)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 270, in index\n return self.create(parse_request(), *args)\n File \"/home/alinefm/kimchi/src/kimchi/control/base.py\", line 209, in create\n name = create(*args)\n File \"/home/alinefm/kimchi/src/kimchi/model/vmstorages.py\", line 171, in create\n params['src_type'] = _check_path(params['path'])\nKeyError: 'path'\n"
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_storage_add.main.js | 28 ++++++++++++++++++++++++++++ ui/pages/i18n.json.tmpl | 7 +++++-- 2 files changed, 33 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 80045d3..a7e4c4c 100644 --- a/ui/js/src/kimchi.guest_storage_add.main.js +++ b/ui/js/src/kimchi.guest_storage_add.main.js @@ -135,6 +135,25 @@ kimchi.guest_storage_add_main = function() { }); });
+ var validateCDROM = function(settings) { + if (/(^\/.*)$/.test(settings['path'])) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0001E'); + return false; + } + } + + var validateDisk = function(settings) { + if (settings['pool'] && settings['vol']) + return true; + else { + kimchi.message.error.code('KCHVMSTOR0002E'); + return false; + } + } + + validator = {cdrom: validateCDROM, disk: validateDisk}; var submitForm = function(event) { if (submitButton.prop('disabled')) { return false; @@ -155,6 +174,15 @@ kimchi.guest_storage_add_main = function() { settings[$(c).attr('name')] = $(c).val(); } }); + // Validate form for cdrom and disk + validateSpecifiedForm = validator[settings['type']]; + if (!validateSpecifiedForm(settings)) { + $(submitButton).prop('disabled', false); + $.each([submitButton, nameTextbox, pathTextbox, poolTextbox, volTextbox], function(i, c) { + $(c).prop('disabled', false); + }); + return false; + } $(submitButton).addClass('loading').text(i18n['KCHVMCD6003M']);
kimchi.addVMStorage(settings, function(result) { diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index ce23bc4..d765cf2 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -162,5 +162,8 @@ "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", "KCHPOOL6010M": "$_("Looking for available partitions ...")", "KCHPOOL6011M": "$_("No available partitions found.")", - "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -} \ No newline at end of file + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")", + + "KCHVMSTOR0001E": "$_("CDROM path need to be a valid local path and cannot be blank.")", + "KCHVMSTOR0002E": "$_("Disk pool or volume cannot be blank.")" +}
participants (4)
-
Aline Manera
-
lvroyce@linux.vnet.ibm.com
-
Royce Lv
-
Sheldon