On 02/04/15 14:11, Jan Cholasta wrote:
Hi,

Dne 1.4.2015 v 17:16 Martin Basti napsal(a):
Since API is not singleton anymore, ldap2 instance should not be shared
between all APIs.

Patch attached.


Works for me. However, it's not the ldap2 instance that was shared, but rather the underlying LDAP connection.

Honza

Reworded patch attached.

--
Martin Basti

From fde4f6434fa746c69ca97b68bbf7e8d08448c21e Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Wed, 25 Mar 2015 15:34:16 +0100
Subject: [PATCH] Fix ldap2 shared connection

Since API is not singleton anymore, ldap2 connections should not be
shared by default.
---
 ipalib/backend.py                    |  2 +-
 ipaserver/plugins/ldap2.py           |  2 +-
 ipatests/test_ipalib/test_backend.py | 12 ++++++------
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/ipalib/backend.py b/ipalib/backend.py
index 4c1001d4d47613537b64c314a2d22769a27f4c69..fcbbd254afc797019e9ea63214b1ee034b8c13f8 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 3211b3390fb979f090467445905513d33e537e17..fd4ed29903fb2f3afe0f4b74467bf53df49654fa 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 c69757cb3d68ebc12f9c91572d37603738357c4e..121c4745bd1dfebfbeed75ba1b46b4420064fe63 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()
-- 
2.1.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to