[CalendarServer-changes] [9508] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 30 13:50:37 PDT 2012


Revision: 9508
          http://trac.macosforge.org/projects/calendarserver/changeset/9508
Author:   sagen at apple.com
Date:     2012-07-30 13:50:34 -0700 (Mon, 30 Jul 2012)
Log Message:
-----------
Whenever proxies are changed, trigger a group cacher update

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/test/test_principals.py
    CalendarServer/trunk/twistedcaldav/directory/directory.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2012-07-30 17:23:16 UTC (rev 9507)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2012-07-30 20:50:34 UTC (rev 9508)
@@ -557,6 +557,7 @@
                 "--reactor=%s" % (config.Twisted.reactor,),
                 "-n", self.maker.groupMembershipCacherTapName,
                 "-f", self.configPath,
+                "-o", "PIDFile=groupcacher.pid",
             ))
 
             self.monitor.addProcess("groupcacher", groupMembershipCacherArgv,

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2012-07-30 17:23:16 UTC (rev 9507)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2012-07-30 20:50:34 UTC (rev 9508)
@@ -19,6 +19,7 @@
 import sys
 import os
 import operator
+import signal
 from getopt import getopt, GetoptError
 from uuid import UUID
 from pwd import getpwnam
@@ -593,7 +594,9 @@
 
     (yield action_removeProxyPrincipal(principal, proxyPrincipal, proxyTypes=proxyTypes))
 
+    triggerGroupCacherUpdate(config)
 
+
 @inlineCallbacks
 def setProxies(principal, readProxyPrincipals, writeProxyPrincipals, directory=None):
     """
@@ -621,6 +624,7 @@
             memberURLs.append(davxml.HRef(proxyURL))
         membersProperty = davxml.GroupMemberSet(*memberURLs)
         (yield subPrincipal.writeProperty(membersProperty, None))
+        triggerGroupCacherUpdate(config)
 
 
 @inlineCallbacks
@@ -697,7 +701,9 @@
         membersProperty = davxml.GroupMemberSet(*memberURLs)
         (yield subPrincipal.writeProperty(membersProperty, None))
 
-        returnValue(removed)
+    if removed:
+        triggerGroupCacherUpdate(config)
+    returnValue(removed)
 
 
 @inlineCallbacks
@@ -898,7 +904,28 @@
     returnValue(record)
 
 
+def triggerGroupCacherUpdate(config, killMethod=None):
+    """
+    Look up the pid of the group cacher sidecar and HUP it to trigger an update
+    """
+    if killMethod is None:
+        killMethod = os.kill
 
+    pidFilename = os.path.join(config.RunRoot, "groupcacher.pid")
+    if os.path.exists(pidFilename):
+        pidFile = open(pidFilename, "r")
+        pid = pidFile.read().strip()
+        pidFile.close()
+        try:
+            pid = int(pid)
+        except ValueError:
+            return
+        try:
+            killMethod(pid, signal.SIGHUP)
+        except OSError:
+            pass
 
+
+
 if __name__ == "__main__":
     main()

Modified: CalendarServer/trunk/calendarserver/tools/test/test_principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2012-07-30 17:23:16 UTC (rev 9507)
+++ CalendarServer/trunk/calendarserver/tools/test/test_principals.py	2012-07-30 20:50:34 UTC (rev 9508)
@@ -15,6 +15,7 @@
 ##
 
 import os
+import signal
 import sys
 
 from twext.python.filepath import CachingFilePath as FilePath
@@ -29,7 +30,9 @@
     ErrorOutput
 
 from calendarserver.tap.util import directoryFromConfig
-from calendarserver.tools.principals import parseCreationArgs, matchStrings, updateRecord, principalForPrincipalID, getProxies, setProxies
+from calendarserver.tools.principals import (parseCreationArgs, matchStrings,
+    updateRecord, principalForPrincipalID, getProxies, setProxies,
+    triggerGroupCacherUpdate)
 
 
 class ManagePrincipalsTestCase(TestCase):
@@ -347,3 +350,25 @@
         self.assertEquals(readProxies, []) # now empty
         self.assertEquals(set(writeProxies), set(["user05"])) # unchanged
 
+
+    def test_triggerGroupCacherUpdate(self):
+        """
+        Verify triggerGroupCacherUpdate can read a pidfile and send a SIGHUP
+        """
+
+        self.calledArgs = None
+        def killMethod(pid, sig):
+            self.calledArgs = (pid, sig)
+
+        class StubConfig(object):
+            def __init__(self, runRootPath):
+                self.RunRoot = runRootPath
+
+        runRootDir = FilePath(self.mktemp())
+        runRootDir.createDirectory()
+        pidFile = runRootDir.child("groupcacher.pid")
+        pidFile.setContent("1234")
+        testConfig = StubConfig(runRootDir.path)
+        triggerGroupCacherUpdate(testConfig, killMethod=killMethod)
+        self.assertEquals(self.calledArgs, (1234, signal.SIGHUP))
+        runRootDir.remove()

Modified: CalendarServer/trunk/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/directory.py	2012-07-30 17:23:16 UTC (rev 9507)
+++ CalendarServer/trunk/twistedcaldav/directory/directory.py	2012-07-30 20:50:34 UTC (rev 9508)
@@ -828,7 +828,7 @@
     def postOptions(self):
         config.load(self['config'])
         config.updateDefaults(self.overrides)
-        self.parent['pidfile'] = None
+        self.parent['pidfile'] = config.PIDFile
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120730/ed857c42/attachment.html>


More information about the calendarserver-changes mailing list