[CalendarServer-changes] [8769] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 28 14:55:08 PST 2012


Revision: 8769
          http://trac.macosforge.org/projects/calendarserver/changeset/8769
Author:   sagen at apple.com
Date:     2012-02-28 14:55:07 -0800 (Tue, 28 Feb 2012)
Log Message:
-----------
Add an explicit reloading= argument to config.upload( ) and update hooks

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/stdconfig.py
    CalendarServer/trunk/twistedcaldav/test/test_config.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2012-02-28 18:57:44 UTC (rev 8768)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2012-02-28 22:55:07 UTC (rev 8769)
@@ -726,7 +726,7 @@
             vary=True,
         )
 
-        def updateFactory(configDict):
+        def updateFactory(configDict, reloading=False):
             httpFactory.maxRequests = configDict.MaxRequests
             httpFactory.maxAccepts = configDict.MaxAccepts
 

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2012-02-28 18:57:44 UTC (rev 8768)
+++ CalendarServer/trunk/twistedcaldav/config.py	2012-02-28 22:55:07 UTC (rev 8769)
@@ -214,7 +214,7 @@
         _mergeData(self._provider.getDefaults(), items)
         self.update(items)
 
-    def update(self, items=None):
+    def update(self, items=None, reloading=False):
         if self._updating:
             return
         self._updating = True
@@ -224,10 +224,10 @@
 
         # Call hooks
         for hook in self._preUpdateHooks:
-            hook(self._data, items)
+            hook(self._data, items, reloading=reloading)
         _mergeData(self._data, items)
         for hook in self._postUpdateHooks:
-            hook(self._data)
+            hook(self._data, reloading=reloading)
 
         self._updating = False
         self._dirty = False
@@ -243,7 +243,6 @@
 
     def reload(self):
         configDict = ConfigDict(self._provider.loadConfig())
-        configDict._reloading = True
         if not self._provider.hasErrors():
             if self._beforeResetHook:
                 # Give the beforeResetHook a chance to stash away values we want
@@ -255,7 +254,7 @@
             if preserved and self._afterResetHook:
                 # Pass the preserved data back to the afterResetHook
                 self._afterResetHook(self._data, preserved)
-            self.update(configDict)
+            self.update(configDict, reloading=True)
         else:
             raise ConfigurationError("Invalid configuration in %s"
                 % (self._provider.getConfigFileName(), ))

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2012-02-28 18:57:44 UTC (rev 8768)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2012-02-28 22:55:07 UTC (rev 8769)
@@ -995,7 +995,7 @@
 ]
 
 
-def _updateDataStore(configDict):
+def _updateDataStore(configDict, reloading=False):
     """
     Post-update configuration hook for making all configured paths relative to
     their respective root directories rather than the current working directory.
@@ -1044,14 +1044,14 @@
                 configDict[previousAbsoluteName] = newAbsolutePath
 
 
-def _updateHostName(configDict):
+def _updateHostName(configDict, reloading=False):
     if not configDict.ServerHostName:
         hostname = getfqdn()
         if not hostname:
             hostname = "localhost"
         configDict.ServerHostName = hostname
 
-def _preUpdateDirectoryService(configDict, items):
+def _preUpdateDirectoryService(configDict, items, reloading=False):
     # Special handling for directory services configs
     dsType = items.get("DirectoryService", {}).get("type", None)
     if dsType is None:
@@ -1071,13 +1071,13 @@
         if dsType in DEFAULT_SERVICE_PARAMS and param not in DEFAULT_SERVICE_PARAMS[dsType]:
             log.warn("Parameter %s is not supported by service %s" % (param, dsType))
             
-def _postUpdateDirectoryService(configDict):
+def _postUpdateDirectoryService(configDict, reloading=False):
     if configDict.DirectoryService.type in DEFAULT_SERVICE_PARAMS:
         for param in tuple(configDict.DirectoryService.params):
             if param not in DEFAULT_SERVICE_PARAMS[configDict.DirectoryService.type]:
                 del configDict.DirectoryService.params[param]
 
-def _preUpdateResourceService(configDict, items):
+def _preUpdateResourceService(configDict, items, reloading=False):
     # Special handling for directory services configs
     dsType = items.get("ResourceService", {}).get("type", None)
     if dsType is None:
@@ -1097,14 +1097,14 @@
         if dsType in DEFAULT_RESOURCE_PARAMS and param not in DEFAULT_RESOURCE_PARAMS[dsType]:
             log.warn("Parameter %s is not supported by service %s" % (param, dsType))
             
-def _postUpdateResourceService(configDict):
+def _postUpdateResourceService(configDict, reloading=False):
     if configDict.ResourceService.type in DEFAULT_RESOURCE_PARAMS:
         for param in tuple(configDict.ResourceService.params):
             if param not in DEFAULT_RESOURCE_PARAMS[configDict.ResourceService.type]:
                 del configDict.ResourceService.params[param]
 
 
-def _preUpdateDirectoryAddressBookBackingDirectoryService(configDict, items):
+def _preUpdateDirectoryAddressBookBackingDirectoryService(configDict, items, reloading=False):
     #
     # Special handling for directory address book configs
     #
@@ -1132,21 +1132,21 @@
         if param not in directoryAddressBookBackingServiceDefaultParams[configDict.DirectoryAddressBook.type]:
             del configDict.DirectoryAddressBook.params[param]
 
-def _postUpdateAugmentService(configDict):
+def _postUpdateAugmentService(configDict, reloading=False):
     if configDict.AugmentService.type in DEFAULT_AUGMENT_PARAMS:
         for param in tuple(configDict.AugmentService.params):
             if param not in DEFAULT_AUGMENT_PARAMS[configDict.AugmentService.type]:
                 log.warn("Parameter %s is not supported by service %s" % (param, configDict.AugmentService.type))
                 del configDict.AugmentService.params[param]
 
-def _postUpdateProxyDBService(configDict):
+def _postUpdateProxyDBService(configDict, reloading=False):
     if configDict.ProxyDBService.type in DEFAULT_PROXYDB_PARAMS:
         for param in tuple(configDict.ProxyDBService.params):
             if param not in DEFAULT_PROXYDB_PARAMS[configDict.ProxyDBService.type]:
                 log.warn("Parameter %s is not supported by service %s" % (param, configDict.ProxyDBService.type))
                 del configDict.ProxyDBService.params[param]
 
-def _updateACLs(configDict):
+def _updateACLs(configDict, reloading=False):
     #
     # Base resource ACLs
     #
@@ -1232,7 +1232,7 @@
 
 
 
-def _updateRejectClients(configDict):
+def _updateRejectClients(configDict, reloading=False):
     #
     # Compile RejectClients expressions for speed
     #
@@ -1241,7 +1241,7 @@
     except re.error, e:
         raise ConfigurationError("Invalid regular expression in RejectClients: %s" % (e,))
 
-def _updateLogLevels(configDict):
+def _updateLogLevels(configDict, reloading=False):
     clearLogLevels()
 
     try:
@@ -1257,9 +1257,9 @@
     except InvalidLogLevelError, e:
         raise ConfigurationError("Invalid log level: %s" % (e.level))
 
-def _updateNotifications(configDict):
+def _updateNotifications(configDict, reloading=False):
     # Reloading not supported -- requires process running as root
-    if getattr(configDict, "_reloading", False):
+    if reloading:
         return
 
     for key, service in configDict.Notifications["Services"].iteritems():
@@ -1351,13 +1351,13 @@
 
 
 
-def _updateScheduling(configDict):
+def _updateScheduling(configDict, reloading=False):
     #
     # Scheduling
     #
 
     # Reloading not supported -- requires process running as root
-    if getattr(configDict, "_reloading", False):
+    if reloading:
         return
 
     service = configDict.Scheduling["iMIP"]
@@ -1400,7 +1400,7 @@
                     log.info("iMIP %s password not found in keychain" %
                         (direction,))
 
-def _updateServers(configDict):
+def _updateServers(configDict, reloading=False):
     import servers
     if configDict.Servers.Enabled:
         servers.Servers.load()
@@ -1411,7 +1411,7 @@
     else:
         servers.Servers.clear()
 
-def _updateCompliance(configDict):
+def _updateCompliance(configDict, reloading=False):
 
     if configDict.EnableCalDAV:
         if configDict.Scheduling.CalDAV.OldDraftCompatibility:

Modified: CalendarServer/trunk/twistedcaldav/test/test_config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_config.py	2012-02-28 18:57:44 UTC (rev 8768)
+++ CalendarServer/trunk/twistedcaldav/test/test_config.py	2012-02-28 22:55:07 UTC (rev 8769)
@@ -130,6 +130,10 @@
 
         _testResponseCompression(self)
 
+    def _myUpdateHook(self, data, reloading=False):
+        # A stub hook to record the value of reloading=
+        self._reloadingValue = reloading
+
     def testReloading(self):
         self.assertEquals(config.HTTPPort, 0)
 
@@ -139,8 +143,13 @@
 
         writePlist({}, self.testConfig)
 
+        self._reloadingValue = None
+        config.addPostUpdateHooks([self._myUpdateHook])
         config.reload()
 
+        # Make sure reloading=True was passed to the update hooks
+        self.assertTrue(self._reloadingValue)
+
         self.assertEquals(config.HTTPPort, 0)
 
     def testUpdateAndReload(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120228/69f8b1da/attachment-0001.html>


More information about the calendarserver-changes mailing list