LGTM barring nitpicks

On Mon, Aug 18, 2014 at 3:38 AM, Yuto KAWAMURA(kawamuray) <
[email protected]> wrote:

> Currently both of these functions are checking if the value is
>

s/are checking/check/
s/is/satisfies/


> bool(value) == False.
> By this approach, numerical 0 would not be allowed as a value of a
>

s/By/Using/


> hvparam.
> We know values that means unspecified hvparam are either one of the
>

We know that unspecified hvparams have a value of either None or ...


> None or the zero-length string, so these functions are required to
>

functions need to


> check if the value is the one of these unspecified values.
>
> Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]>
> ---
>  lib/hypervisor/hv_base.py | 23 ++++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
> index cd74ce7..3bed945 100644
> --- a/lib/hypervisor/hv_base.py
> +++ b/lib/hypervisor/hv_base.py
> @@ -532,6 +532,23 @@ class BaseHypervisor(object):
>      return start_mem
>
>    @classmethod
> +  def _IsParamValueUnspecified(cls, param_value):
> +    """Check if the parameter value is a kind of value meaning
> unspecified.
> +
> +    This function checks if the parameter value is a kind of value meaning
> +    unspecified.
> +
> +    @type param_value: any
> +    @param param_value: the parameter value need to be checked
>
s/need/that needs/

> +    @rtype: bool
> +    @return: True if the parameter value is a kind of value meaning
> unspecified,
> +      False otherwise
> +
> +    """
> +    return param_value is None \
> +      or isinstance(param_value, basestring) and param_value == ""
> +
> +  @classmethod
>    def CheckParameterSyntax(cls, hvparams):
>      """Check the given parameters for validity.
>
> @@ -552,9 +569,9 @@ class BaseHypervisor(object):
>        if name not in hvparams:
>          raise errors.HypervisorError("Parameter '%s' is missing" % name)
>        value = hvparams[name]
> -      if not required and not value:
> +      if not required and cls._IsParamValueUnspecified(value):
>          continue
> -      if not value:
> +      if cls._IsParamValueUnspecified(value):
>          raise errors.HypervisorError("Parameter '%s' is required but"
>                                       " is currently not defined" % (name,
> ))
>        if check_fn is not None and not check_fn(value):
> @@ -576,7 +593,7 @@ class BaseHypervisor(object):
>      """
>      for name, (required, _, _, check_fn, errstr) in
> cls.PARAMETERS.items():
>        value = hvparams[name]
> -      if not required and not value:
> +      if not required and cls._IsParamValueUnspecified(value):
>          continue
>        if check_fn is not None and not check_fn(value):
>          raise errors.HypervisorError("Parameter '%s' fails"
> --
> 2.0.4
>
>


Hrvoje Ribicic
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370

Reply via email to