From 6447da75af83eb4bff704b4f2ad427d7d1b90cc4 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Sun, 10 Feb 2013 07:08:24 +0900 Subject: [PATCH] Sync latest cfg from oslo-incubator Main cfg change is: e3e5e0e Fixes "is not", "not in" syntax usage d156150 Implements import_group Change-Id: Ie6c0fe0d9d35ef6178a121e4f566207576c8d1e6 --- quantum/openstack/common/cfg.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/quantum/openstack/common/cfg.py b/quantum/openstack/common/cfg.py index c26191c339..56d169e1ab 100644 --- a/quantum/openstack/common/cfg.py +++ b/quantum/openstack/common/cfg.py @@ -863,7 +863,7 @@ class SubCommandOpt(Opt): description=self.description, help=self.help) - if not self.handler is None: + if self.handler is not None: self.handler(subparsers) @@ -1297,6 +1297,24 @@ class ConfigOpts(collections.Mapping): __import__(module_str) self._get_opt_info(name, group) + def import_group(self, group, module_str): + """Import an option group from a module. + + Import a module and check that a given option group is registered. + + This is intended for use with global configuration objects + like cfg.CONF where modules commonly register options with + CONF at module load time. If one module requires an option group + defined by another module it can use this method to explicitly + declare the dependency. + + :param group: an option OptGroup object or group name + :param module_str: the name of a module to import + :raises: ImportError, NoSuchGroupError + """ + __import__(module_str) + self._get_group(group) + @__clear_cache def set_override(self, name, override, group=None): """Override an opt value. @@ -1547,8 +1565,8 @@ class ConfigOpts(collections.Mapping): group = group_or_name if isinstance(group_or_name, OptGroup) else None group_name = group.name if group else group_or_name - if not group_name in self._groups: - if not group is None or not autocreate: + if group_name not in self._groups: + if group is not None or not autocreate: raise NoSuchGroupError(group_name) self.register_group(OptGroup(name=group_name)) @@ -1568,7 +1586,7 @@ class ConfigOpts(collections.Mapping): group = self._get_group(group) opts = group._opts - if not opt_name in opts: + if opt_name not in opts: raise NoSuchOptError(opt_name, group) return opts[opt_name] @@ -1606,7 +1624,7 @@ class ConfigOpts(collections.Mapping): opt = info['opt'] if opt.required: - if ('default' in info or 'override' in info): + if 'default' in info or 'override' in info: continue if self._get(opt.dest, group) is None: