LGTM, thanks!

On Mon, Mar 31, 2014 at 2:47 PM, Klaus Aehlig <[email protected]> wrote:

> As the attempt to convert the dict used as json representation
> of the configuration into a configuration object already makes
> assumptions about the internal representation, verify the version
> before such an attempt. Fixes issue 783.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  lib/config.py | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/lib/config.py b/lib/config.py
> index e6c4000..15707da 100644
> --- a/lib/config.py
> +++ b/lib/config.py
> @@ -62,7 +62,7 @@ _UPGRADE_CONFIG_JID = "jid-cfg-upgrade"
>
>
>  def _ValidateConfig(data):
> -  """Verifies that a configuration objects looks valid.
> +  """Verifies that a configuration dict looks valid.
>
>    This only verifies the version of the configuration.
>
> @@ -70,8 +70,9 @@ def _ValidateConfig(data):
>        we expect
>
>    """
> -  if data.version != constants.CONFIG_VERSION:
> -    raise errors.ConfigVersionMismatch(constants.CONFIG_VERSION,
> data.version)
> +  if data['version'] != constants.CONFIG_VERSION:
> +    raise errors.ConfigVersionMismatch(constants.CONFIG_VERSION,
> +                                       data['version'])
>
>
>  class TemporaryReservationManager:
> @@ -2275,13 +2276,15 @@ class ConfigWriter(object):
>      raw_data = utils.ReadFile(self._cfg_file)
>
>      try:
> -      data = objects.ConfigData.FromDict(serializer.Load(raw_data))
> +      data_dict = serializer.Load(raw_data)
> +      # Make sure the configuration has the right version
> +      _ValidateConfig(data_dict)
> +      data = objects.ConfigData.FromDict(data_dict)
> +    except errors.ConfigVersionMismatch:
> +      raise
>      except Exception, err:
>        raise errors.ConfigurationError(err)
>
> -    # Make sure the configuration has the right version
> -    _ValidateConfig(data)
> -
>      if (not hasattr(data, "cluster") or
>          not hasattr(data.cluster, "rsahostkeypub")):
>        raise errors.ConfigurationError("Incomplete configuration"
> --
> 1.9.1.423.g4596e3a
>
>

Reply via email to