summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2015-06-22 10:16:34 +0000
committerJan Cholasta <jcholast@redhat.com>2015-07-01 13:05:30 +0000
commit2d1515323acb4125306817096bafab6623de0b47 (patch)
tree5f9c347978fe2c94eb0b0f3996ff7a79d3e848db /ipalib
parent481f8ddaa32795c64275438645e45d2c4bbbae26 (diff)
downloadfreeipa-2d1515323acb4125306817096bafab6623de0b47.tar.gz
freeipa-2d1515323acb4125306817096bafab6623de0b47.tar.xz
freeipa-2d1515323acb4125306817096bafab6623de0b47.zip
plugable: Load plugins only from modules imported by API
Previously all plugin modules imported from anywhere were added to the API. https://fedorahosted.org/freeipa/ticket/3090 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/__init__.py4
-rw-r--r--ipalib/cli.py3
-rw-r--r--ipalib/plugable.py24
3 files changed, 24 insertions, 7 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 74a812033..a6fad545c 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -936,7 +936,7 @@ api = create_api(mode=None)
if os.environ.get('IPA_UNIT_TEST_MODE', None) == 'cli_test':
from cli import cli_plugins
- for klass in cli_plugins:
- api.register(klass)
api.bootstrap(context='cli', in_server=False, in_tree=True)
+ for klass in cli_plugins:
+ api.add_plugin(klass)
api.finalize()
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 52529ea02..c0e8c9c93 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -1333,8 +1333,7 @@ def run(api):
try:
(options, argv) = api.bootstrap_with_global_options(context='cli')
for klass in cli_plugins:
- api.register(klass)
- api.load_plugins()
+ api.add_plugin(klass)
api.finalize()
if not 'config_loaded' in api.env and not 'help' in argv:
raise NotConfiguredError()
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index d98ab731e..d13e5ed88 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -612,8 +612,6 @@ class API(DictProxy):
return
for module in self.modules:
self.import_plugins(module)
- for klass, kwargs in self.register.iteritems():
- self.add_plugin(klass, **kwargs)
# FIXME: This method has no unit test
def import_plugins(self, module):
@@ -651,7 +649,7 @@ class API(DictProxy):
for name in modules:
self.log.debug("importing plugin module %s", name)
try:
- importlib.import_module(name)
+ module = importlib.import_module(name)
except errors.SkipPluginModule, e:
self.log.debug("skipping plugin module %s: %s", name, e.reason)
except StandardError, e:
@@ -660,6 +658,23 @@ class API(DictProxy):
self.log.error("could not load plugin module %s\n%s", name,
traceback.format_exc())
raise
+ else:
+ self.add_module(module)
+
+ def add_module(self, module):
+ """
+ Add plugins from the ``module``.
+
+ :param module: A module from which to add plugins.
+ """
+ for name in dir(module):
+ klass = getattr(module, name)
+ if not inspect.isclass(klass):
+ continue
+ if klass not in self.register:
+ continue
+ kwargs = self.register[klass]
+ self.add_plugin(klass, **kwargs)
def add_plugin(self, klass, override=False):
"""
@@ -679,6 +694,9 @@ class API(DictProxy):
found = True
+ if sub_d.get(klass.__name__) is klass:
+ continue
+
# Check override:
if klass.__name__ in sub_d:
if not override: