[Kimchi-devel] [PATCH 4/5] storagepool: Do not assume different 'else' values in pool type
Aline Manera
alinefm at linux.vnet.ibm.com
Tue Jan 21 01:02:05 UTC 2014
Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
On 01/20/2014 08:09 PM, Crístian Viana wrote:
> Currently, there are four different storage pool types. The JavaScript
> code that handles that logic assumes different values in the 'else'
> blocks of different functions. It is a good practice to be explicit on
> what we are checking for and not to depend on the possible last value
> out of a set. This can easily lead to bugs in the future if additional
> storage pool types are added. Also, the code is harder to follow because
> the 'else' assumptions on similar comparisons are sometimes one value
> and sometimes another value.
>
> Use explicit and consistent values when checking the different
> pool types in 'if/else' clauses.
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
> ui/js/src/kimchi.storagepool_add_main.js | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js
> index 24de979..2f54db9 100644
> --- a/ui/js/src/kimchi.storagepool_add_main.js
> +++ b/ui/js/src/kimchi.storagepool_add_main.js
> @@ -71,7 +71,7 @@ kimchi.initStorageAddPage = function() {
> $('.logical-section').addClass('tmpl-html');
> $('.nfs-section').addClass('tmpl-html');
> $('.iscsi-section').removeClass('tmpl-html');
> - } else {
> + } else if ($(this).val() === 'logical') {
> $('.path-section').addClass('tmpl-html');
> $('.logical-section').removeClass('tmpl-html');
> $('.nfs-section').addClass('tmpl-html');
> @@ -108,10 +108,11 @@ kimchi.validateForm = function() {
> return kimchi.validateNfsForm();
> } else if (poolType === "iscsi") {
> return kimchi.validateIscsiForm();
> - } else {
> + } else if (poolType === "logical") {
> return kimchi.validateLogicalForm();
> + } else {
> + return false;
> }
> -
> };
>
> kimchi.validateDirForm = function () {
> @@ -205,7 +206,7 @@ kimchi.addPool = function(event) {
> source.path = $('#nfspathId').val();
> source.host = $('#nfsserverId').val();
> formData.source = source;
> - } else {
> + } else if (poolType === 'iscsi') {
> var source = {};
> source.target = $('#iscsiTargetId').val();
> source.host = $('#iscsiserverId').val();
More information about the Kimchi-devel
mailing list