[CalendarServer-changes] [11446] CalendarServer/trunk/calendarserver
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jul 1 12:41:55 PDT 2013
Revision: 11446
http://trac.calendarserver.org//changeset/11446
Author: sagen at apple.com
Date: 2013-07-01 12:41:54 -0700 (Mon, 01 Jul 2013)
Log Message:
-----------
Allow the agent to read/write settings
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tools/gateway.py
CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2013-07-01 19:21:24 UTC (rev 11445)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2013-07-01 19:41:54 UTC (rev 11446)
@@ -547,7 +547,7 @@
Removes pidfile, registers an exec to happen after shutdown, then
stops the reactor.
"""
- self.log.info("SIGHUP received - restarting")
+ self.log.warn("SIGHUP received - restarting")
try:
self.log.info("Removing pidfile: %s" % (self.pidfilePath,))
os.remove(self.pidfilePath)
@@ -1243,8 +1243,13 @@
# Don't use memcached -- calendar server might take it away at any
# moment
- config.Memcached.Pools.Default.ClientEnabled = False
+ def agentPostUpdateHook(configDict, reloading=False):
+ configDict.Memcached.Pools.Default.ClientEnabled = False
+ config.addPostUpdateHooks((agentPostUpdateHook,))
+ config.reload()
+
+ # These we need to set in order to open the store
config.EnableCalDAV = config.EnableCardDAV = True
def agentServiceCreator(pool, store, ignored):
Modified: CalendarServer/trunk/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/gateway.py 2013-07-01 19:21:24 UTC (rev 11445)
+++ CalendarServer/trunk/calendarserver/tools/gateway.py 2013-07-01 19:41:54 UTC (rev 11446)
@@ -38,7 +38,10 @@
from pycalendar.datetime import PyCalendarDateTime
+from twistedcaldav.config import config, ConfigDict
+from calendarserver.tools.config import WRITABLE_CONFIG_KEYS, setKeyPath, getKeyPath, flattenDictionary, WritableConfig
+
def usage(e=None):
name = os.path.basename(sys.argv[0])
@@ -359,6 +362,53 @@
self.respondWithRecordsOfTypes(self.dir, command, ["locations", "resources"])
+ # Config
+
+ def command_readConfig(self, command):
+ """
+ Return current configuration
+
+ @param command: the dictionary parsed from the plist read from stdin
+ @type command: C{dict}
+ """
+ config.reload()
+ # config.Memcached.Pools.Default.ClientEnabled = False
+
+ result = {}
+ for keyPath in WRITABLE_CONFIG_KEYS:
+ value = getKeyPath(config, keyPath)
+ if value is not None:
+ # Note: config contains utf-8 encoded strings, but plistlib
+ # wants unicode, so decode here:
+ if isinstance(value, str):
+ value = value.decode("utf-8")
+ setKeyPath(result, keyPath, value)
+ self.respond(command, result)
+
+
+ def command_writeConfig(self, command):
+ """
+ Write config to secondary, writable plist
+
+ @param command: the dictionary parsed from the plist read from stdin
+ @type command: C{dict}
+ """
+ writable = WritableConfig(config, config.WritableConfigFile)
+ writable.read()
+ valuesToWrite = command.get("Values", {})
+ # Note: values are unicode if they contain non-ascii
+ for keyPath, value in flattenDictionary(valuesToWrite):
+ if keyPath in WRITABLE_CONFIG_KEYS:
+ writable.set(setKeyPath(ConfigDict(), keyPath, value))
+ try:
+ writable.save(restart=False)
+ except Exception, e:
+ self.respond(command, {"error": str(e)})
+ else:
+ self.command_readConfig(command)
+
+
+
# Proxies
Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py 2013-07-01 19:21:24 UTC (rev 11445)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py 2013-07-01 19:41:54 UTC (rev 11446)
@@ -28,6 +28,7 @@
from twistedcaldav.test.util import TestCase, CapturingProcessProtocol
from calendarserver.tools.util import getDirectory
from txdav.common.datastore.test.util import SQLStoreBuilder
+import plistlib
class RunCommandTestCase(TestCase):
@@ -314,8 +315,49 @@
results = yield self.runCommand(command_purgeOldEventsNoDays)
self.assertEquals(results["result"]["RetainDays"], 365)
+ @inlineCallbacks
+ def test_readConfig(self):
+ """
+ Verify readConfig returns with only the writable keys
+ """
+ results = yield self.runCommand(command_readConfig,
+ script="calendarserver_config")
+ self.assertEquals(results["result"]["RedirectHTTPToHTTPS"], False)
+ self.assertEquals(results["result"]["EnableSearchAddressBook"], False)
+ self.assertEquals(results["result"]["EnableCalDAV"], True)
+ self.assertEquals(results["result"]["EnableCardDAV"], True)
+ self.assertEquals(results["result"]["EnableSSL"], False)
+ self.assertEquals(results["result"]["DefaultLogLevel"], "warn")
+ self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["Enabled"], False)
+ self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["CalDAV"]["CertificatePath"], "/example/calendar.cer")
+
+ # Verify not all keys are present, such as ServerRoot which is not writable
+ self.assertFalse("ServerRoot" in results["result"])
+
+
+ @inlineCallbacks
+ def test_writeConfig(self):
+ """
+ Verify writeConfig updates the writable plist file only
+ """
+ results = yield self.runCommand(command_writeConfig,
+ script="calendarserver_config")
+
+ self.assertEquals(results["result"]["EnableCalDAV"], False)
+ self.assertEquals(results["result"]["EnableCardDAV"], False)
+ self.assertEquals(results["result"]["EnableSSL"], True)
+ self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["Enabled"], True)
+ self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["CalDAV"]["CertificatePath"], "/example/changed.cer")
+ dataRoot = "Data/%s/%s" % (unichr(208), u"\ud83d\udca3")
+ self.assertTrue(results["result"]["DataRoot"].endswith(dataRoot))
+
+ # The static plist should still have EnableCalDAV = True
+ staticPlist = plistlib.readPlist(self.configFileName)
+ self.assertTrue(staticPlist["EnableCalDAV"])
+
+
command_addReadProxy = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@@ -658,3 +700,38 @@
</dict>
</plist>
"""
+
+command_readConfig = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>command</key>
+ <string>readConfig</string>
+</dict>
+</plist>
+"""
+
+command_writeConfig = """<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>command</key>
+ <string>writeConfig</string>
+ <key>Values</key>
+ <dict>
+ <key>EnableCalDAV</key>
+ <false/>
+ <key>EnableCardDAV</key>
+ <false/>
+ <key>EnableSSL</key>
+ <true/>
+ <key>Notifications.Services.APNS.Enabled</key>
+ <true/>
+ <key>Notifications.Services.APNS.CalDAV.CertificatePath</key>
+ <string>/example/changed.cer</string>
+ <key>DataRoot</key>
+ <string>Data/%s/%s</string>
+ </dict>
+</dict>
+</plist>
+""" % (unichr(208), u"\ud83d\udca3")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130701/26fae7d0/attachment.html>
More information about the calendarserver-changes
mailing list