From e8aaf39b18bf251a024e07c20bccb5f1e187d15b Mon Sep 17 00:00:00 2001 From: William Brown Date: Tue, 5 Jul 2016 16:54:37 +1000 Subject: [PATCH] Ticket 48911 - Plugin improvements for lib389 Bug Description: We broke some legacy compatability. It's also useful to be able to check the plugin status. Fix Description: Add the needed helpers, and add a status helper https://fedorahosted.org/389/ticket/48911 Author: wibrown Review by: ??? --- lib389/plugins.py | 24 ++++++++++++++++++++++++ lib389/tests/plugin_test.py | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/lib389/plugins.py b/lib389/plugins.py index f599d9e..7e22783 100644 --- a/lib389/plugins.py +++ b/lib389/plugins.py @@ -28,6 +28,11 @@ class Plugin(DSLdapObject): def disable(self): self.set('nsslapd-pluginEnabled', 'off') + def status(self): + if self.get_attr_val('nsslapd-pluginEnabled') == 'on': + return True + return False + class AttributeUniquenessPlugin(Plugin): def __init__(self, instance, dn="cn=attribute uniqueness,cn=plugins,cn=config", batch=False): super(AttributeUniquenessPlugin, self).__init__(instance, dn, batch) @@ -104,6 +109,25 @@ class Plugins(DSLdapObjects): return super(Plugins, self)._entry_to_instance(dn) + # To maintain compat with pluginslegacy, here are some helpers. + + def enable(self, name=None, plugin_dn=None): + if plugin_dn is not None: + raise ValueError('You should swap to the new Plugin API!') + if name is None: + raise ldap.NO_SUCH_OBJECT('Must provide a selector for name') + plugin = self.get(selector=name) + plugin.enable() + + def disable(self, name=None, plugin_dn=None): + if plugin_dn is not None: + raise ValueError('You should swap to the new Plugin API!') + if name is None: + raise ldap.NO_SUCH_OBJECT('Must provide a selector for name') + plugin = self.get(selector=name) + plugin.disable() + + class PluginsLegacy(object): proxied_methods = 'search_s getEntry'.split() diff --git a/lib389/tests/plugin_test.py b/lib389/tests/plugin_test.py index 84231a8..adbff56 100644 --- a/lib389/tests/plugin_test.py +++ b/lib389/tests/plugin_test.py @@ -117,6 +117,14 @@ def test_plugin_management(topology): uniqplugin.enable_all_subtrees() uniqplugin.enable() + # Test compat with the old api + + topology.standalone.plugins.enable('attribute uniqueness') + + # Show the status + + assert(uniqplugin.status()) + log.info('Test PASSED') -- 1.8.3.1