From 05bc19d4e96052463062b6b8ca83852b4b169d48 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Sat, 12 May 2012 11:52:53 +0100 Subject: cfg: make reset() clear defaults and overrides Fixes bug #998396 Both Nova and Keystone need to clear the overrides on their config object between test runs. It's reasonable to expect the reset() method would do this, so let's make it so. Also add a clear() method with the old behaviour. Change-Id: I192c5bb07e81f0fb844fa2fd429dc2e7133800de --- openstack/common/cfg.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'openstack/common') diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py index 31d727b..c50aa6a 100644 --- a/openstack/common/cfg.py +++ b/openstack/common/cfg.py @@ -940,7 +940,7 @@ class ConfigOpts(collections.Mapping): :raises: SystemExit, ConfigFilesNotFoundError, ConfigFileParseError, RequiredOptError """ - self.reset() + self.clear() self._args = args @@ -987,11 +987,16 @@ class ConfigOpts(collections.Mapping): """Return the number of options and option groups.""" return len(self._opts) + len(self._groups) - @__clear_cache def reset(self): - """Reset the state of the object to before it was called.""" + """Clear the object state and unset overrides and defaults.""" + self._unset_defaults_and_overrides() + self.clear() + + @__clear_cache + def clear(self): + """Clear the state of the object to before it was called.""" self._args = None - self._cli_values = None + self._cli_values = {} self._cparser = None @__clear_cache @@ -1098,6 +1103,17 @@ class ConfigOpts(collections.Mapping): opt_info = self._get_opt_info(name, group) opt_info['default'] = default + def _unset_defaults_and_overrides(self): + """Unset any default or override on all options.""" + def unset(opts): + for info in opts.values(): + info['default'] = None + info['override'] = None + + unset(self._opts) + for group in self._groups.values(): + unset(group._opts) + def disable_interspersed_args(self): """Set parsing to stop on the first non-option. -- cgit