From b92136cba287e38d9c2f41c3163f5a6b0b62ca17 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Apr 02 2015 12:26:04 +0000 Subject: Fix ldap2 shared connection Since API is not singleton anymore, ldap2 connections should not be shared by default. https://fedorahosted.org/freeipa/ticket/4904 Reviewed-By: Jan Cholasta --- diff --git a/ipalib/backend.py b/ipalib/backend.py index 4c1001d..fcbbd25 100644 --- a/ipalib/backend.py +++ b/ipalib/backend.py @@ -46,7 +46,7 @@ class Connectible(Backend): `request.destroy_context()` can properly close all open connections. """ - def __init__(self, shared_instance=True): + def __init__(self, shared_instance=False): Backend.__init__(self) if shared_instance: self.id = self.name diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 3211b33..fd4ed29 100644 --- a/ipaserver/plugins/ldap2.py +++ b/ipaserver/plugins/ldap2.py @@ -61,7 +61,7 @@ class ldap2(LDAPClient, CrudBackend): LDAP Backend Take 2. """ - def __init__(self, shared_instance=True, ldap_uri=None, base_dn=None, + def __init__(self, shared_instance=False, ldap_uri=None, base_dn=None, schema=None): self.__ldap_uri = None diff --git a/ipatests/test_ipalib/test_backend.py b/ipatests/test_ipalib/test_backend.py index c69757c..121c474 100644 --- a/ipatests/test_ipalib/test_backend.py +++ b/ipatests/test_ipalib/test_backend.py @@ -76,7 +76,7 @@ class test_Connectible(ClassChecker): object.__setattr__(self, 'args', args) object.__setattr__(self, 'kw', kw) return 'The connection.' - o = example() + o = example(shared_instance=True) args = ('Arg1', 'Arg2', 'Arg3') kw = dict(key1='Val1', key2='Val2', key3='Val3') assert not hasattr(context, 'example') @@ -104,7 +104,7 @@ class test_Connectible(ClassChecker): class example(self.cls): pass for klass in (self.cls, example): - o = klass() + o = klass(shared_instance=True) e = raises(NotImplementedError, o.create_connection) assert str(e) == '%s.create_connection()' % klass.__name__ @@ -114,7 +114,7 @@ class test_Connectible(ClassChecker): """ class example(self.cls): destroy_connection = Disconnect() - o = example() + o = example(shared_instance=True) m = "disconnect: 'context.%s' does not exist in thread %r" e = raises(StandardError, o.disconnect) @@ -131,7 +131,7 @@ class test_Connectible(ClassChecker): class example(self.cls): pass for klass in (self.cls, example): - o = klass() + o = klass(shared_instance=True) e = raises(NotImplementedError, o.destroy_connection) assert str(e) == '%s.destroy_connection()' % klass.__name__ @@ -142,7 +142,7 @@ class test_Connectible(ClassChecker): class example(self.cls): pass for klass in (self.cls, example): - o = klass() + o = klass(shared_instance=True) assert o.isconnected() is False conn = 'whatever' setattr(context, klass.__name__, conn) @@ -157,7 +157,7 @@ class test_Connectible(ClassChecker): class example(self.cls): pass for klass in (self.cls, example): - o = klass() + o = klass(shared_instance=True) e = raises(AttributeError, getattr, o, 'conn') assert str(e) == msg % ( klass.__name__, threading.currentThread().getName()