[CalendarServer-changes] [4635] CalendarServer/branches/more-deferreds-3/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 25 16:53:22 PDT 2009
Revision: 4635
http://trac.macosforge.org/projects/calendarserver/changeset/4635
Author: glyph at apple.com
Date: 2009-10-25 16:53:20 -0700 (Sun, 25 Oct 2009)
Log Message:
-----------
make test_upgrade pass.
Modified Paths:
--------------
CalendarServer/branches/more-deferreds-3/twistedcaldav/__init__.py
CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_upgrade.py
CalendarServer/branches/more-deferreds-3/twistedcaldav/upgrade.py
Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/__init__.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/__init__.py 2009-10-22 19:19:32 UTC (rev 4634)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/__init__.py 2009-10-25 23:53:20 UTC (rev 4635)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twistedcaldav -*-
##
# Copyright (c) 2005-2007 Apple Inc. All rights reserved.
#
Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_upgrade.py 2009-10-22 19:19:32 UTC (rev 4634)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_upgrade.py 2009-10-25 23:53:20 UTC (rev 4635)
@@ -14,6 +14,10 @@
# limitations under the License.
##
+from twisted.internet.defer import inlineCallbacks, succeed
+
+from twisted.web2.dav import davxml
+
from twistedcaldav.config import config
from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
from twistedcaldav.directory.xmlfile import XMLDirectoryService
@@ -21,8 +25,8 @@
from twistedcaldav.mail import MailGatewayTokensDatabase
from twistedcaldav.upgrade import UpgradeError, upgradeData, updateFreeBusySet
from twistedcaldav.test.util import TestCase
+
from calendarserver.tools.util import getDirectory
-from twisted.web2.dav import davxml
import hashlib
import os, zlib, cPickle
@@ -33,7 +37,7 @@
class ProxyDBUpgradeTests(TestCase):
-
+
def setUpXMLDirectory(self):
xmlFile = os.path.join(os.path.dirname(os.path.dirname(__file__)),
"directory", "test", "accounts.xml")
@@ -46,12 +50,12 @@
self.setUpOldDocRoot()
self.setUpOldDocRootWithoutDB()
self.setUpNewDocRoot()
-
+
self.setUpNewDataRoot()
self.setUpDataRootWithProxyDB()
def setUpOldDocRoot(self):
-
+
# Set up doc root
self.olddocroot = self.mktemp()
os.mkdir(self.olddocroot)
@@ -74,7 +78,7 @@
def setUpOldDocRootWithoutDB(self):
-
+
# Set up doc root
self.olddocrootnodb = self.mktemp()
os.mkdir(self.olddocrootnodb)
@@ -90,7 +94,7 @@
os.mkdir(os.path.join(self.olddocrootnodb, "calendars"))
def setUpNewDocRoot(self):
-
+
# Set up doc root
self.newdocroot = self.mktemp()
os.mkdir(self.newdocroot)
@@ -98,13 +102,13 @@
os.mkdir(os.path.join(self.newdocroot, "calendars"))
def setUpNewDataRoot(self):
-
+
# Set up data root
self.newdataroot = self.mktemp()
os.mkdir(self.newdataroot)
def setUpDataRootWithProxyDB(self):
-
+
# Set up data root
self.existingdataroot = self.mktemp()
os.mkdir(self.existingdataroot)
@@ -122,7 +126,7 @@
config.DocumentRoot = self.olddocroot
config.DataRoot = self.newdataroot
-
+
# Check pre-conditions
self.assertTrue(os.path.exists(os.path.join(config.DocumentRoot, "principals")))
self.assertTrue(os.path.isdir(os.path.join(config.DocumentRoot, "principals")))
@@ -130,7 +134,7 @@
self.assertFalse(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
upgradeData(config)
-
+
# Check post-conditions
self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals",)))
self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
@@ -145,18 +149,19 @@
config.DocumentRoot = self.newdocroot
config.DataRoot = self.existingdataroot
-
+
# Check pre-conditions
self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals")))
self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
upgradeData(config)
-
+
# Check post-conditions
self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals",)))
self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
+ @inlineCallbacks
def test_freeBusyUpgrade(self):
"""
Test the updating of calendar-free-busy-set xattrs on inboxes
@@ -171,18 +176,18 @@
# Uncompressed XML
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/__uids__/BB05932F-DCE7-4195-9ED4-0896EAFF3B0B/calendar</href>\r\n</calendar-free-busy-set>\r\n"
- self.assertEquals(updateFreeBusySet(value, directory), None)
+ self.assertEquals((yield updateFreeBusySet(value, directory)), None)
# Zlib compressed XML
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/__uids__/BB05932F-DCE7-4195-9ED4-0896EAFF3B0B/calendar</href>\r\n</calendar-free-busy-set>\r\n"
value = zlib.compress(value)
- self.assertEquals(updateFreeBusySet(value, directory), None)
+ self.assertEquals((yield updateFreeBusySet(value, directory)), None)
# Pickled XML
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/__uids__/BB05932F-DCE7-4195-9ED4-0896EAFF3B0B/calendar</href>\r\n</calendar-free-busy-set>\r\n"
doc = davxml.WebDAVDocument.fromString(value)
value = cPickle.dumps(doc.root_element)
- self.assertEquals(updateFreeBusySet(value, directory), None)
+ self.assertEquals((yield updateFreeBusySet(value, directory)), None)
#
@@ -193,14 +198,14 @@
# Uncompressed XML
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/users/wsanchez/calendar</href>\r\n</calendar-free-busy-set>\r\n"
- newValue = updateFreeBusySet(value, directory)
+ newValue = yield updateFreeBusySet(value, directory)
newValue = zlib.decompress(newValue)
self.assertEquals(newValue, expected)
# Zlib compressed XML
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/users/wsanchez/calendar</href>\r\n</calendar-free-busy-set>\r\n"
value = zlib.compress(value)
- newValue = updateFreeBusySet(value, directory)
+ newValue = yield updateFreeBusySet(value, directory)
newValue = zlib.decompress(newValue)
self.assertEquals(newValue, expected)
@@ -208,7 +213,7 @@
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/users/wsanchez/calendar</href>\r\n</calendar-free-busy-set>\r\n"
doc = davxml.WebDAVDocument.fromString(value)
value = cPickle.dumps(doc.root_element)
- newValue = updateFreeBusySet(value, directory)
+ newValue = yield updateFreeBusySet(value, directory)
newValue = zlib.decompress(newValue)
self.assertEquals(newValue, expected)
@@ -219,7 +224,7 @@
expected = "<?xml version='1.0' encoding='UTF-8'?><calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'/>"
value = "<?xml version='1.0' encoding='UTF-8'?>\r\n<calendar-free-busy-set xmlns='urn:ietf:params:xml:ns:caldav'>\r\n <href xmlns='DAV:'>/calendars/users/nonexistent/calendar</href>\r\n</calendar-free-busy-set>\r\n"
- newValue = updateFreeBusySet(value, directory)
+ newValue = yield updateFreeBusySet(value, directory)
newValue = zlib.decompress(newValue)
self.assertEquals(newValue, expected)
@@ -231,7 +236,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"calendars" :
@@ -379,7 +383,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"calendars" :
@@ -459,6 +462,7 @@
self.assertTrue(self.verifyHierarchy(root, after))
+ @inlineCallbacks
def test_calendarsUpgradeWithDuplicateOrphans(self):
"""
Verify that calendar homes in the /calendars/<type>/<shortname>/ form
@@ -466,7 +470,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"archived" :
@@ -553,11 +556,11 @@
config.DocumentRoot = root
config.DataRoot = root
- upgradeData(config)
+ yield upgradeData(config)
self.assertTrue(self.verifyHierarchy(root, after))
# Ensure that repeating the process doesn't change anything
- upgradeData(config)
+ yield upgradeData(config)
self.assertTrue(self.verifyHierarchy(root, after))
@@ -568,7 +571,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
".DS_Store" :
@@ -665,7 +667,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
@@ -779,7 +780,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"calendars" :
@@ -910,7 +910,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"calendars" :
@@ -1039,7 +1038,6 @@
"""
self.setUpXMLDirectory()
- directory = getDirectory()
before = {
"calendars" :
@@ -1127,9 +1125,13 @@
config.DocumentRoot = root
config.DataRoot = root
+ def failTest(result):
+ self.fail("oops")
+ def checkUpgradeError(result):
+ self.assertIsInstance(result.value, UpgradeError)
+ self.assertTrue(self.verifyHierarchy(root, after))
- self.assertRaises(UpgradeError, upgradeData, config)
- self.assertTrue(self.verifyHierarchy(root, after))
+ return upgradeData(config).addCallbacks(failTest, checkUpgradeError)
def test_migrateResourceInfo(self):
# Fake getResourceInfo( )
@@ -1298,7 +1300,7 @@
except zlib.error:
return False
try:
- doc = davxml.WebDAVDocument.fromString(value)
+ davxml.WebDAVDocument.fromString(value)
return True
except ValueError:
return False
Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/upgrade.py 2009-10-22 19:19:32 UTC (rev 4634)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/upgrade.py 2009-10-25 23:53:20 UTC (rev 4635)
@@ -1,3 +1,4 @@
+# -*- test-case-name: twistedcaldav.test.test_upgrade -*-
##
# Copyright (c) 2008 Apple Inc. All rights reserved.
#
@@ -16,6 +17,7 @@
from __future__ import with_statement
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2.dav.fileop import rmdir
from twisted.web2.dav import davxml
from twistedcaldav.directory.directory import DirectoryService
@@ -52,14 +54,12 @@
return uid, gid
-#
-# upgrade_to_1
-#
-# Upconverts data from any calendar server version prior to data format 1
-#
+ at inlineCallbacks
def upgrade_to_1(config):
-
+ """
+ Upconverts data from any calendar server version prior to data format 1
+ """
errorOccurred = False
def fixBadQuotes(data):
@@ -82,7 +82,6 @@
return data, False
-
@inlineCallbacks
def normalizeCUAddrs(data, directory):
cal = Component.fromString(data)
@@ -108,6 +107,7 @@
returnValue((newData, not newData == data))
+ @inlineCallbacks
def upgradeCalendarCollection(calPath, directory):
errorOccurred = False
@@ -142,7 +142,7 @@
try:
# MOR: Defer this:
- data, fixed = normalizeCUAddrs(data, directory)
+ data, fixed = yield normalizeCUAddrs(data, directory)
if fixed:
log.debug("Normalized CUAddrs in %s" % (resPath,))
needsRewrite = True
@@ -168,9 +168,10 @@
ctagValue = zlib.compress(ctagValue)
xattr.setxattr(calPath, "WebDAV:{http:%2F%2Fcalendarserver.org%2Fns%2F}getctag", ctagValue)
- return errorOccurred
+ returnValue(errorOccurred)
+ @inlineCallbacks
def upgradeCalendarHome(homePath, directory):
errorOccurred = False
@@ -181,7 +182,7 @@
for cal in os.listdir(homePath):
calPath = os.path.join(homePath, cal)
log.debug("Upgrading calendar: %s" % (calPath,))
- if not upgradeCalendarCollection(calPath, directory):
+ if not (yield upgradeCalendarCollection(calPath, directory)):
errorOccurred = True
# Change the calendar-free-busy-set xattrs of the inbox to the
@@ -189,7 +190,7 @@
if cal == "inbox":
for attr, value in xattr.xattr(calPath).iteritems():
if attr == "WebDAV:{urn:ietf:params:xml:ns:caldav}calendar-free-busy-set":
- value = updateFreeBusySet(value, directory)
+ value = yield updateFreeBusySet(value, directory)
if value is not None:
# Need to write the xattr back to disk
xattr.setxattr(calPath, attr, value)
@@ -198,7 +199,7 @@
log.error("Failed to upgrade calendar home %s: %s" % (homePath, e))
raise
- return errorOccurred
+ returnValue(errorOccurred)
def doProxyDatabaseMoveUpgrade(config, uid=-1, gid=-1):
@@ -367,7 +368,7 @@
dirPath = os.path.join(calRoot, dirName)
if os.path.exists(dirPath):
for shortName in os.listdir(dirPath):
- record = directory.recordWithShortName(recordType,
+ record = yield directory.recordWithShortName(recordType,
shortName)
oldHome = os.path.join(dirPath, shortName)
if record is not None:
@@ -424,8 +425,8 @@
homePath = os.path.join(secondPath, home)
- if not upgradeCalendarHome(homePath,
- directory):
+ if not (yield upgradeCalendarHome(
+ homePath, directory)):
errorOccurred = True
count += 1
@@ -450,6 +451,7 @@
(1, upgrade_to_1),
]
+ at inlineCallbacks
def upgradeData(config):
docRoot = config.DocumentRoot
@@ -461,10 +463,10 @@
try:
with open(versionFilePath) as versionFile:
onDiskVersion = int(versionFile.read().strip())
- except IOError, e:
+ except IOError:
log.error("Cannot open %s; skipping migration" %
(versionFilePath,))
- except ValueError, e:
+ except ValueError:
log.error("Invalid version number in %s; skipping migration" %
(versionFilePath,))
@@ -473,7 +475,7 @@
for version, method in upgradeMethods:
if onDiskVersion < version:
log.warn("Upgrading to version %d" % (version,))
- method(config)
+ yield method(config)
with open(versionFilePath, "w") as verFile:
verFile.write(str(version))
os.chown(versionFilePath, uid, gid)
@@ -489,25 +491,27 @@
#
# Utility functions
#
+ at inlineCallbacks
def updateFreeBusyHref(href, directory):
pieces = href.split("/")
if pieces[2] == "__uids__":
# Already updated
- return None
+ returnValue(None)
recordType = pieces[2]
shortName = pieces[3]
- record = directory.recordWithShortName(recordType, shortName)
+ record = yield directory.recordWithShortName(recordType, shortName)
if record is None:
# We will simply ignore this and not write out an fb-set entry
log.error("Can't update free-busy href; %s is not in the directory" % shortName)
- return ""
+ returnValue("")
uid = record.uid
newHref = "/calendars/__uids__/%s/%s/" % (uid, pieces[4])
- return newHref
+ returnValue(newHref)
+ at inlineCallbacks
def updateFreeBusySet(value, directory):
try:
@@ -525,13 +529,13 @@
except UnpicklingError:
log.err("Invalid free/busy property value")
# MOR: continue on?
- return None
+ returnValue(None)
fbset = set()
didUpdate = False
for href in freeBusySet.children:
href = str(href)
- newHref = updateFreeBusyHref(href, directory)
+ newHref = yield updateFreeBusyHref(href, directory)
if newHref is None:
fbset.add(href)
else:
@@ -543,9 +547,9 @@
property = caldavxml.CalendarFreeBusySet(*[davxml.HRef(href)
for href in fbset])
value = compress(property.toxml())
- return value
+ returnValue(value)
- return None # no update required
+ returnValue(None) # no update required
def makeDirsUserGroup(path, uid=-1, gid=-1):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091025/5441bc67/attachment-0001.html>
More information about the calendarserver-changes
mailing list