On Tue, Sep 22, 2009 at 2:55 PM, Iustin Pop <[email protected]> wrote:
>
> Currently the config upgrade is done at each object instantiation, that
> means that ganeti-noded will run UpgradeConfig on all objects received
> remotely (instances, disks, nics). This is not so good, so this patch
> changes it so that only the ConfigWriter runs this method at
> configuration load time.
LGTM
Thanks,
Guido
> ---
> lib/config.py | 4 ++++
> lib/objects.py | 33 ++++++++++++++++++++++++++++++---
> 2 files changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/lib/config.py b/lib/config.py
> index 91621b9..22f10ea 100644
> --- a/lib/config.py
> +++ b/lib/config.py
> @@ -1055,6 +1055,10 @@ class ConfigWriter:
> not hasattr(data.cluster, 'rsahostkeypub')):
> raise errors.ConfigurationError("Incomplete configuration"
> " (missing cluster.rsahostkeypub)")
> +
> + # Upgrade configuration if needed
> + data.UpgradeConfig()
> +
> self._config_data = data
> # reset the last serial as -1 so that the next write will cause
> # ssconf update
> diff --git a/lib/objects.py b/lib/objects.py
> index e2154db..fbaae08 100644
> --- a/lib/objects.py
> +++ b/lib/objects.py
> @@ -92,7 +92,6 @@ class ConfigObject(object):
> def __init__(self, **kwargs):
> for k, v in kwargs.iteritems():
> setattr(self, k, v)
> - self.UpgradeConfig()
>
> def __getattr__(self, name):
> if name not in self.__slots__:
> @@ -198,8 +197,8 @@ class ConfigObject(object):
> def UpgradeConfig(self):
> """Fill defaults for missing configuration values.
>
> - This method will be called at object init time, and its implementation
> will
> - be object dependent.
> + This method will be called at configuration load time, and its
> + implementation will be object dependent.
>
> """
> pass
> @@ -313,6 +312,16 @@ class ConfigData(ConfigObject):
> obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
> return obj
>
> + def UpgradeConfig(self):
> + """Fill defaults for missing configuration values.
> +
> + """
> + self.cluster.UpgradeConfig()
> + for node in self.nodes.values():
> + node.UpgradeConfig()
> + for instance in self.instances.values():
> + instance.UpgradeConfig()
> +
>
> class NIC(ConfigObject):
> """Config object representing a network card."""
> @@ -598,6 +607,15 @@ class Disk(ConfigObject):
> all_errors.append("Disk access mode '%s' is invalid" % (self.mode, ))
> return all_errors
>
> + def UpgradeConfig(self):
> + """Fill defaults for missing configuration values.
> +
> + """
> + if self.children:
> + for child in self.children:
> + child.UpgradeConfig()
> + # add here config upgrade for this disk
> +
>
> class Instance(TaggableObject):
> """Config object representing an instance."""
> @@ -747,6 +765,15 @@ class Instance(TaggableObject):
> obj.disks = cls._ContainerFromDicts(obj.disks, list, Disk)
> return obj
>
> + def UpgradeConfig(self):
> + """Fill defaults for missing configuration values.
> +
> + """
> + for nic in self.nics:
> + nic.UpgradeConfig()
> + for disk in self.disks:
> + disk.UpgradeConfig()
> +
>
> class OS(ConfigObject):
> """Config object representing an operating system."""
> --
> 1.6.3.3
>
>
--
Guido Trotter
Google - Sysops Team
Google Ireland Ltd. : Registered in Ireland with company number 368047.
Gordon House, Barrow Street, Dublin 4, Ireland.