Branch 'pykolab-0.5' - 5 commits - kolabd/__init__.py kolabd/process.py pykolab/auth pykolab/cli

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Wed Dec 26 11:19:07 CET 2012


 kolabd/__init__.py                |   19 +++++++++++++++++--
 kolabd/process.py                 |   10 +++++++---
 pykolab/auth/ldap/__init__.py     |   29 ++++++++++++++++-------------
 pykolab/auth/ldap/cache.py        |    5 ++++-
 pykolab/cli/cmd_create_mailbox.py |   17 +++++++++++------
 5 files changed, 55 insertions(+), 25 deletions(-)

New commits:
commit d6a9544b3c594daa8756fa4b71d38ef970e792cf
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Nov 28 18:12:58 2012 +0000

    Use our set_metadata() call on IMAP.

diff --git a/pykolab/cli/cmd_create_mailbox.py b/pykolab/cli/cmd_create_mailbox.py
index 4ecc788..5510e56 100644
--- a/pykolab/cli/cmd_create_mailbox.py
+++ b/pykolab/cli/cmd_create_mailbox.py
@@ -34,11 +34,13 @@ def __init__():
 
 def cli_options():
     my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
-    my_option_group.add_option( '--metadata',
-                                dest    = "metadata",
-                                action  = "store",
-                                default = None,
-                                help    = _("Set metadata for folder to ANNOTATION=VALUE"))
+    my_option_group.add_option(
+            '--metadata',
+            dest    = "metadata",
+            action  = "store",
+            default = None,
+            help    = _("Set metadata for folder to ANNOTATION=VALUE")
+        )
 
 def description():
     return """Create a mailbox or sub-folder of an existing mailbox."""
@@ -60,8 +62,11 @@ def execute(*args, **kw):
 
     imap = IMAP()
     imap.connect()
+
+    admin_login = conf.get('cyrus-imap', 'admin_login')
+
     imap.cm(mailbox)
 
     if not conf.metadata == None:
-        imap.setannotation(mailbox, conf.metadata.split('=')[0], conf.metadata.split('=')[1])
+        imap.set_metadata(mailbox, conf.metadata.split('=')[0], conf.metadata.split('=')[1])
 


commit dce9ec73738756d0667647e309966e1728620167
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Tue Dec 4 15:13:44 2012 +0000

    Allow the caller to cache.get_entry() to specify the entry should not be updated automatically

diff --git a/pykolab/auth/ldap/cache.py b/pykolab/auth/ldap/cache.py
index 503c3c5..6688bf7 100644
--- a/pykolab/auth/ldap/cache.py
+++ b/pykolab/auth/ldap/cache.py
@@ -99,12 +99,15 @@ def delete_entry(domain, entry):
         db.delete(_entry)
         db.commit()
 
-def get_entry(domain, entry):
+def get_entry(domain, entry, update=True):
     result_attribute = conf.get('cyrus-sasl', 'result_attribute')
 
     db = init_db(domain)
     _entry = db.query(Entry).filter_by(uniqueid=entry['id']).first()
 
+    if not update:
+        return _entry
+
     if _entry == None:
         log.debug(_("Inserting cache entry %r") % (entry['id']), level=8)
 


commit a7a074685fa4cb03d4e1dffde399459dd847409a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Nov 30 12:01:17 2012 +0000

    Use cache, not conf.changelog
    Use a ReconnectLDAPObject rather than a SimpleLDAPObject

diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 620c5ef..d96270c 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -219,7 +219,13 @@ class LDAP(pykolab.base.Base):
         if conf.debuglevel > 8:
             trace_level = 1
 
-        self.ldap = ldap.initialize(uri, trace_level=trace_level)
+        self.ldap = ldap.ldapobject.ReconnectLDAPObject(
+                uri,
+                trace_level=trace_level,
+                retry_max=200,
+                retry_delay=3.0
+            )
+
         self.ldap.protocol_version = 3
         self.ldap.supported_controls = []
 
@@ -1230,17 +1236,14 @@ class LDAP(pykolab.base.Base):
         pass
 
     def _change_modify_user(self, entry, change):
-        for entry_key in conf.changelog.keys():
-            log.debug(
-                    _("Current changelog entry %s with %s") % (
-                            entry_key,
-                            conf.changelog[entry_key]
-                        ),
-                    level=8
-                )
+        result_attribute = conf.get('cyrus-sasl','result_attribute')
+
+        _entry = cache.get_entry(self.domain, entry)
 
-        if conf.changelog.has_key(entry['id']):
-            old_canon_attr = conf.changelog[entry['id']]
+        log.debug("Entry.__dict__: %r" % (_entry.__dict__))
+
+        if _entry.__dict__.has_key('result_attribute') and not _entry.result_attribute == '':
+            old_canon_attr = _entry.result_attribute
 
         entry_changes = self.recipient_policy(entry)
 
@@ -1249,7 +1252,6 @@ class LDAP(pykolab.base.Base):
                 level=8
             )
 
-        result_attribute = conf.get('cyrus-sasl','result_attribute')
         if entry_changes.has_key(result_attribute):
             if not entry_changes[result_attribute] == old_canon_attr:
                 self.imap.user_mailbox_rename(
@@ -1257,7 +1259,8 @@ class LDAP(pykolab.base.Base):
                         entry_changes[result_attribute]
                     )
 
-                conf.changelog[entry['id']] = entry_changes[result_attribute]
+                entry[result_attribute] = entry_changes[result_attribute]
+                cache.get_entry(self.domain, entry)
 
         self.user_quota(entry, "user%s%s" % (self.imap.separator,entry[result_attribute]))
 


commit 7777262894cf4d1e5ef72eeb69cd9f3dacc89dc6
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Nov 30 12:00:04 2012 +0000

    try/except synchronizing and gracefully exit if something goes wrong. The master kolabd process will restart synchronization

diff --git a/kolabd/process.py b/kolabd/process.py
index 9fe525d..ddaac63 100644
--- a/kolabd/process.py
+++ b/kolabd/process.py
@@ -37,6 +37,10 @@ class KolabdProcess(multiprocessing.Process):
             )
 
     def synchronize(self, domain):
-        auth = Auth(domain)
-        auth.connect(domain)
-        auth.synchronize()
+        try:
+            auth = Auth(domain)
+            auth.connect(domain)
+            auth.synchronize()
+        except:
+            log.error(_("Error in process %r, terminating") % (self.name))
+            return
\ No newline at end of file


commit bce3066e540a8c1c2e22b875dc77c8d20741b254
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Fri Nov 30 11:59:30 2012 +0000

    Check if a domain name space synchronization process is still alive
    try/except removing our PID file

diff --git a/kolabd/__init__.py b/kolabd/__init__.py
index 230088c..b345b8d 100644
--- a/kolabd/__init__.py
+++ b/kolabd/__init__.py
@@ -243,7 +243,11 @@ class KolabDaemon(object):
 
             for domain in all_domains:
                 if domain in domain_auth.keys() and domain in primary_domains:
-                    continue
+                    if not domain_auth[domain].is_alive():
+                        domain_auth[domain].terminate()
+                        added_domains.append(domain)
+                    else:
+                        continue
                 elif domain in domain_auth.keys():
                     removed_domains.append(domain)
                 else:
@@ -268,8 +272,19 @@ class KolabDaemon(object):
         pass
 
     def remove_pid(self, *args, **kw):
+        """
+            Remove our PID file.
+
+            Note that multiple processes can attempt to do this very same thing
+            at the same time, and therefore we need to test if the PID file
+            exists, and only try/except removing it.
+        """
         if os.access(conf.pidfile, os.R_OK):
-            os.remove(conf.pidfile)
+            try:
+                os.remove(conf.pidfile)
+            except:
+                pass
+
         raise SystemExit
 
     def set_signal_handlers(self):





More information about the commits mailing list