LGTM, thanks

On Wed, Aug 27, 2014 at 10:17 PM, Yuto KAWAMURA(kawamuray) <
[email protected]> wrote:

> Currently both of these functions check if the value satisfies
> bool(value) == False.
> Using this approach, numerical 0 would not be allowed as a value of a
> hvparam.
> We know that unspecified hvparams have a value of either None or the
> zero-length string, so these 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..f72aeff 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 that needs to be checked
> +    @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