Skip to content
Permalink
Browse files

Whenever proxies are changed, trigger a group cacher update

  • Loading branch information...
m0rgen committed Jul 30, 2012
1 parent c478ab5 commit 5c722323cc6b8d93cb045a561d8578812fb6ae86
@@ -557,6 +557,7 @@ def startService(self):
"--reactor=%s" % (config.Twisted.reactor,),
"-n", self.maker.groupMembershipCacherTapName,
"-f", self.configPath,
"-o", "PIDFile=groupcacher.pid",
))

self.monitor.addProcess("groupcacher", groupMembershipCacherArgv,
@@ -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,6 +594,8 @@ def addProxy(principal, proxyType, proxyPrincipal):

(yield action_removeProxyPrincipal(principal, proxyPrincipal, proxyTypes=proxyTypes))

triggerGroupCacherUpdate(config)


@inlineCallbacks
def setProxies(principal, readProxyPrincipals, writeProxyPrincipals, directory=None):
@@ -621,6 +624,7 @@ def setProxies(principal, readProxyPrincipals, writeProxyPrincipals, directory=N
memberURLs.append(davxml.HRef(proxyURL))
membersProperty = davxml.GroupMemberSet(*memberURLs)
(yield subPrincipal.writeProperty(membersProperty, None))
triggerGroupCacherUpdate(config)


@inlineCallbacks
@@ -697,7 +701,9 @@ def removeProxy(principal, proxyPrincipal, **kwargs):
membersProperty = davxml.GroupMemberSet(*memberURLs)
(yield subPrincipal.writeProperty(membersProperty, None))

returnValue(removed)
if removed:
triggerGroupCacherUpdate(config)
returnValue(removed)


@inlineCallbacks
@@ -898,6 +904,27 @@ def updateRecord(create, directory, recordType, **kwargs):
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__":
@@ -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 @@ def test_setProxies(self):
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()
@@ -828,7 +828,7 @@ def opt_option(self, option):
def postOptions(self):
config.load(self['config'])
config.updateDefaults(self.overrides)
self.parent['pidfile'] = None
self.parent['pidfile'] = config.PIDFile



0 comments on commit 5c72232

Please sign in to comment.
You can’t perform that action at this time.