diff options
| author | Mark McLoughlin <markmc@redhat.com> | 2012-05-12 11:52:53 +0100 |
|---|---|---|
| committer | Mark McLoughlin <markmc@redhat.com> | 2012-05-12 11:52:53 +0100 |
| commit | 05bc19d4e96052463062b6b8ca83852b4b169d48 (patch) | |
| tree | 73d36631d83d4d8626311936d2820f7db45a9cc3 /openstack/common | |
| parent | b74081884696f943a23aa8b31b4275e7819a1c21 (diff) | |
| download | oslo-05bc19d4e96052463062b6b8ca83852b4b169d48.tar.gz oslo-05bc19d4e96052463062b6b8ca83852b4b169d48.tar.xz oslo-05bc19d4e96052463062b6b8ca83852b4b169d48.zip | |
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
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/cfg.py | 24 |
1 files changed, 20 insertions, 4 deletions
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. |
