[CalendarServer-changes] [7825] CalendarServer/trunk/calendarserver
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jul 26 15:53:08 PDT 2011
Revision: 7825
http://trac.macosforge.org/projects/calendarserver/changeset/7825
Author: sagen at apple.com
Date: 2011-07-26 15:53:07 -0700 (Tue, 26 Jul 2011)
Log Message:
-----------
Server startup waits for ServerRoot to exist/mount
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tools/test/test_util.py
CalendarServer/trunk/calendarserver/tools/util.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2011-07-25 14:34:41 UTC (rev 7824)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2011-07-26 22:53:07 UTC (rev 7825)
@@ -297,8 +297,8 @@
config.updateDefaults(self.overrides)
- def checkDirectory(self, dirpath, description, access=None, create=None):
- checkDirectory(dirpath, description, access=access, create=create)
+ def checkDirectory(self, dirpath, description, access=None, create=None, wait=False):
+ checkDirectory(dirpath, description, access=access, create=create, wait=wait)
def checkConfiguration(self):
@@ -336,6 +336,7 @@
"Server root",
# Require write access because one might not allow editing on /
access=os.W_OK,
+ wait=True # Wait in a loop until ServerRoot exists
)
#
Modified: CalendarServer/trunk/calendarserver/tools/test/test_util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_util.py 2011-07-25 14:34:41 UTC (rev 7824)
+++ CalendarServer/trunk/calendarserver/tools/test/test_util.py 2011-07-26 22:53:07 UTC (rev 7825)
@@ -15,8 +15,10 @@
##
import os
+import tempfile
from twistedcaldav.test.util import TestCase
-from calendarserver.tools.util import loadConfig
+from twistedcaldav.config import ConfigurationError
+from calendarserver.tools.util import loadConfig, checkDirectory
class UtilTestCase(TestCase):
@@ -26,3 +28,9 @@
config = loadConfig(configPath)
self.assertEquals(config.EnableCalDAV, True)
self.assertEquals(config.EnableCardDAV, True)
+
+ def test_checkDirectory(self):
+ tmpDir = tempfile.mkdtemp()
+ tmpFile = os.path.join(tmpDir, "tmpFile")
+ self.assertRaises(ConfigurationError, checkDirectory, tmpFile, "Test file")
+ os.rmdir(tmpDir)
Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py 2011-07-25 14:34:41 UTC (rev 7824)
+++ CalendarServer/trunk/calendarserver/tools/util.py 2011-07-26 22:53:07 UTC (rev 7825)
@@ -232,41 +232,66 @@
autoDisableMemcached(config)
-def checkDirectory(dirpath, description, access=None, create=None):
+def checkDirectory(dirpath, description, access=None, create=None, wait=False):
+ """
+ Make sure dirpath is an existing directory, and optionally ensure it has the
+ expected permissions. Alternatively the function can create the directory or
+ can wait for someone else to create it.
+
+ @param dirpath: The directory path we're checking
+ @type dirpath: string
+ @param description: A description of what the directory path represents, used in
+ log messages
+ @type description: string
+ @param access: The type of access we're expecting, either os.W_OK or os.R_OK
+ @param create: A tuple of (file permissions mode, username, groupname) to use
+ when creating the directory. If create=None then no attempt will be made
+ to create the directory.
+ @type create: tuple
+ @param wait: Wether the function should wait in a loop for the directory to be
+ created by someone else (or mounted, etc.)
+ @type wait: boolean
+ """
if not os.path.exists(dirpath):
- try:
- mode, username, groupname = create
- except TypeError:
- raise ConfigurationError("%s does not exist: %s"
- % (description, dirpath))
- try:
- os.mkdir(dirpath)
- except (OSError, IOError), e:
- log.error("Could not create %s: %s" % (dirpath, e))
- raise ConfigurationError(
- "%s does not exist and cannot be created: %s"
- % (description, dirpath)
- )
- if username:
- uid = getpwnam(username).pw_uid
+ if wait:
+ while not os.path.exists(dirpath):
+ log.error("Path does not exist: %s" % (dirpath,))
+ sleep(1)
else:
- uid = -1
+ try:
+ mode, username, groupname = create
+ except TypeError:
+ raise ConfigurationError("%s does not exist: %s"
+ % (description, dirpath))
+ try:
+ os.mkdir(dirpath)
+ except (OSError, IOError), e:
+ log.error("Could not create %s: %s" % (dirpath, e))
+ raise ConfigurationError(
+ "%s does not exist and cannot be created: %s"
+ % (description, dirpath)
+ )
- if groupname:
- gid = getgrnam(groupname).gr_gid
- else:
- gid = -1
+ if username:
+ uid = getpwnam(username).pw_uid
+ else:
+ uid = -1
- try:
- os.chmod(dirpath, mode)
- os.chown(dirpath, uid, gid)
- except (OSError, IOError), e:
- log.error("Unable to change mode/owner of %s: %s"
- % (dirpath, e))
+ if groupname:
+ gid = getgrnam(groupname).gr_gid
+ else:
+ gid = -1
- log.info("Created directory: %s" % (dirpath,))
+ try:
+ os.chmod(dirpath, mode)
+ os.chown(dirpath, uid, gid)
+ except (OSError, IOError), e:
+ log.error("Unable to change mode/owner of %s: %s"
+ % (dirpath, e))
+ log.info("Created directory: %s" % (dirpath,))
+
if not os.path.isdir(dirpath):
raise ConfigurationError("%s is not a directory: %s"
% (description, dirpath))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110726/349f30d4/attachment.html>
More information about the calendarserver-changes
mailing list