[CalendarServer-changes] [12272] CalendarServer/branches/release/CalendarServer-5.2-dev

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:19:23 PDT 2014


Revision: 12272
          http://trac.calendarserver.org//changeset/12272
Author:   wsanchez at apple.com
Date:     2014-01-08 14:13:14 -0800 (Wed, 08 Jan 2014)
Log Message:
-----------
Pulled u0 r12036 from trunk.

Revision Links:
--------------
    http://trac.calendarserver.org//changeset/12036

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/locking.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/test/test_locking.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py
    CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/test/test_wrapping.py

Property Changed:
----------------
    CalendarServer/branches/release/CalendarServer-5.2-dev/


Property changes on: CalendarServer/branches/release/CalendarServer-5.2-dev
___________________________________________________________________
Modified: svn:mergeinfo
   - /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593
/CalendarServer/trunk:11898,11991,12021,12028,12031,12036,12241,12262-12263
   + /CalDAVTester/trunk:11193-11198
/CalendarServer/branches/config-separation:4379-4443
/CalendarServer/branches/egg-info-351:4589-4625
/CalendarServer/branches/generic-sqlstore:6167-6191
/CalendarServer/branches/new-store:5594-5934
/CalendarServer/branches/new-store-no-caldavfile:5911-5935
/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
/CalendarServer/branches/users/cdaboo/pods:7297-7377
/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
/CalendarServer/branches/users/cdaboo/pycard:7227-7237
/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
/CalendarServer/branches/users/cdaboo/timezones:7443-7699
/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
/CalendarServer/branches/users/glyph/conn-limit:6574-6577
/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
/CalendarServer/branches/users/glyph/dalify:6932-7023
/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
/CalendarServer/branches/users/glyph/deploybuild:7563-7572
/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
/CalendarServer/branches/users/glyph/disable-quota:7718-7727
/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
/CalendarServer/branches/users/glyph/hang-fix:11465-11491
/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
/CalendarServer/branches/users/glyph/linux-tests:6893-6900
/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
/CalendarServer/branches/users/glyph/new-export:7444-7485
/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
/CalendarServer/branches/users/glyph/oracle:7106-7155
/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
/CalendarServer/branches/users/glyph/other-html:8062-8091
/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
/CalendarServer/branches/users/glyph/q:9560-9688
/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
/CalendarServer/branches/users/glyph/quota:7604-7637
/CalendarServer/branches/users/glyph/sendfdport:5388-5424
/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
/CalendarServer/branches/users/glyph/sharedpool:6490-6550
/CalendarServer/branches/users/glyph/sharing-api:9192-9205
/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
/CalendarServer/branches/users/glyph/sql-store:5929-6073
/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
/CalendarServer/branches/users/glyph/subtransactions:7248-7258
/CalendarServer/branches/users/glyph/table-alias:8651-8664
/CalendarServer/branches/users/glyph/uidexport:7673-7676
/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
/CalendarServer/branches/users/sagen/applepush:8126-8184
/CalendarServer/branches/users/sagen/inboxitems:7380-7381
/CalendarServer/branches/users/sagen/locations-resources:5032-5051
/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/branches/users/sagen/resources-2:5084-5093
/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
/CalendarServer/branches/users/wsanchez/transations:5515-5593
/CalendarServer/trunk:11898,11991,12021,12028,12030-12031,12036,12241,12262-12263

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/locking.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/locking.py	2014-01-08 21:53:27 UTC (rev 12271)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/locking.py	2014-01-08 22:13:14 UTC (rev 12272)
@@ -35,6 +35,13 @@
 
 
 
+class LockTimeout(Exception):
+    """
+    The lock you were trying to lock was already locked causing a timeout.
+    """
+
+
+
 def makeLockSchema(inSchema):
     """
     Create a self-contained schema just for L{Locker} use, in C{inSchema}.
@@ -57,7 +64,6 @@
 
 
 
-
 class NamedLock(Record, fromTable(LockSchema.NAMED_LOCK)):
     """
     An L{AcquiredLock} lock against a shared data store that the current
@@ -79,7 +85,9 @@
         def autoRelease(self):
             txn.preCommit(lambda: self.release(True))
             return self
-        return cls.create(txn, lockName=name).addCallback(autoRelease)
+        def lockFailed(f):
+            raise LockTimeout(name)
+        return cls.create(txn, lockName=name).addCallback(autoRelease).addErrback(lockFailed)
 
 
     def release(self, ignoreAlreadyUnlocked=False):
@@ -98,6 +106,3 @@
             unlocked.
         """
         return self.delete()
-
-
-

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/test/test_locking.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/test/test_locking.py	2014-01-08 21:53:27 UTC (rev 12271)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/twext/enterprise/test/test_locking.py	2014-01-08 22:13:14 UTC (rev 12272)
@@ -22,7 +22,7 @@
 from twisted.trial.unittest import TestCase
 
 from twext.enterprise.fixtures import buildConnectionPool
-from twext.enterprise.locking import NamedLock
+from twext.enterprise.locking import NamedLock, LockTimeout
 from twext.enterprise.dal.syntax import Select
 from twext.enterprise.locking import LockSchema
 
@@ -76,3 +76,17 @@
         txn2 = self.pool.connection()
         rows = yield Select(From=LockSchema.NAMED_LOCK).on(txn2)
         self.assertEquals(rows, [])
+
+
+    @inlineCallbacks
+    def test_timeout(self):
+        """
+        Trying to acquire second lock times out.
+        """
+        txn1 = self.pool.connection()
+        yield NamedLock.acquire(txn1, u"a test lock")
+
+        txn2 = self.pool.connection()
+        yield self.assertFailure(NamedLock.acquire(txn2, u"a test lock"), LockTimeout)
+        yield txn2.abort()
+        self.flushLoggedErrors()

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py	2014-01-08 21:53:27 UTC (rev 12271)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/storebridge.py	2014-01-08 22:13:14 UTC (rev 12272)
@@ -17,7 +17,9 @@
 
 from pycalendar.datetime import PyCalendarDateTime
 
+from twext.enterprise.locking import LockTimeout
 from twext.python.log import Logger
+from twext.web2 import responsecode, http_headers, http
 from twext.web2.dav.http import ErrorResponse, ResponseQueue, MultiStatusResponse
 from twext.web2.dav.noneprops import NonePropertyStore
 from twext.web2.dav.resource import TwistedACLInheritable, AccessDeniedError, \
@@ -26,6 +28,7 @@
 from twext.web2.filter.location import addLocation
 from twext.web2.http import HTTPError, StatusResponse, Response
 from twext.web2.http_headers import ETag, MimeType, MimeDisposition
+from twext.web2.iweb import IResponse
 from twext.web2.responsecode import \
     FORBIDDEN, NO_CONTENT, NOT_FOUND, CREATED, CONFLICT, PRECONDITION_FAILED, \
     BAD_REQUEST, OK, INSUFFICIENT_STORAGE_SPACE, SERVICE_UNAVAILABLE
@@ -41,14 +44,20 @@
     MaxInstances, NoUIDConflict
 from twistedcaldav.carddavxml import carddav_namespace, NoUIDConflict as NovCardUIDConflict
 from twistedcaldav.config import config
+from twistedcaldav.customxml import calendarserver_namespace
 from twistedcaldav.directory.wiki import WikiDirectoryService, getWikiAccess
 from twistedcaldav.ical import Component as VCalendar, Property as VProperty, \
     InvalidICalendarDataError, iCalendarProductID, allowedComponents, Component
+from twistedcaldav.instance import InvalidOverriddenInstanceError, \
+    TooManyInstancesError
 from twistedcaldav.memcachelock import MemcacheLockTimeoutError
 from twistedcaldav.notifications import NotificationCollectionResource, NotificationResource
 from twistedcaldav.resource import CalDAVResource, GlobalAddressBookResource, \
     DefaultAlarmPropertyMixin
 from twistedcaldav.scheduling_store.caldav.resource import ScheduleInboxResource
+from twistedcaldav.sharing import invitationBindStatusToXMLMap, \
+    invitationBindModeToXMLMap
+from twistedcaldav.util import bestAcceptType
 from twistedcaldav.vcard import Component as VCard, InvalidVCardDataError
 
 from txdav.base.propertystore.base import PropertyName
@@ -74,16 +83,10 @@
 from txdav.xml.base import dav_namespace, WebDAVUnknownElement, encodeXMLName
 
 from urlparse import urlsplit
+import collections
 import hashlib
 import time
 import uuid
-from twext.web2 import responsecode, http_headers, http
-from twext.web2.iweb import IResponse
-from twistedcaldav.customxml import calendarserver_namespace
-from twistedcaldav.instance import InvalidOverriddenInstanceError, \
-    TooManyInstancesError
-import collections
-
 """
 Wrappers to translate between the APIs in L{txdav.caldav.icalendarstore} and
 L{txdav.carddav.iaddressbookstore} and those in L{twistedcaldav}.
@@ -2258,11 +2261,53 @@
         returnValue(response)
 
     # The following are used to map store exceptions into HTTP error responses
-    StoreExceptionsStatusErrors = set()
     StoreExceptionsErrors = {}
-    StoreMoveExceptionsStatusErrors = set()
     StoreMoveExceptionsErrors = {}
+    StoreRemoveExceptionsErrors = {}
 
+    @classmethod
+    def _storeExceptionStatus(cls, err, arg):
+        """
+        Raise a status error.
+
+        @param err: the actual exception that caused the error
+        @type err: L{Exception}
+        @param arg: description of error or C{None}
+        @type arg: C{str} or C{None}
+        """
+        raise HTTPError(StatusResponse(responsecode.FORBIDDEN, arg if arg is not None else str(err)))
+
+
+    @classmethod
+    def _storeExceptionError(cls, err, arg):
+        """
+        Raise a DAV:error error with the supplied error element.
+
+        @param err: the actual exception that caused the error
+        @type err: L{Exception}
+        @param arg: the error element
+        @type arg: C{tuple}
+        """
+        raise HTTPError(ErrorResponse(
+            responsecode.FORBIDDEN,
+            arg,
+            str(err),
+        ))
+
+
+    @classmethod
+    def _storeExceptionUnavailable(cls, err, arg):
+        """
+        Raise a service unavailable error.
+
+        @param err: the actual exception that caused the error
+        @type err: L{Exception}
+        @param arg: description of error or C{None}
+        @type arg: C{str} or C{None}
+        """
+        raise HTTPError(StatusResponse(responsecode.SERVICE_UNAVAILABLE, arg if arg is not None else str(err)))
+
+
     @requiresPermissions(fromParent=[davxml.Unbind()])
     def http_DELETE(self, request):
         """
@@ -2354,15 +2399,9 @@
             # Grab the current exception state here so we can use it in a re-raise - we need this because
             # an inlineCallback might be called and that raises an exception when it returns, wiping out the
             # original exception "context".
-            if type(err) in self.StoreMoveExceptionsStatusErrors:
-                raise HTTPError(StatusResponse(responsecode.FORBIDDEN, str(err)))
-
-            elif type(err) in self.StoreMoveExceptionsErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    self.StoreMoveExceptionsErrors[type(err)],
-                    str(err),
-                ))
+            if type(err) in self.StoreMoveExceptionsErrors:
+                error, arg = self.StoreMoveExceptionsErrors[type(err)]
+                error(err, arg)
             else:
                 # Return the original failure (exception) state
                 raise
@@ -2405,15 +2444,9 @@
 
         # Map store exception to HTTP errors
         except Exception as err:
-            if type(err) in self.StoreExceptionsStatusErrors:
-                raise HTTPError(StatusResponse(responsecode.FORBIDDEN, str(err)))
-
-            elif type(err) in self.StoreExceptionsErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    self.StoreExceptionsErrors[type(err)],
-                    str(err),
-                ))
+            if type(err) in self.StoreExceptionsErrors:
+                error, arg = self.StoreExceptionsErrors[type(err)]
+                error(err, arg)
             else:
                 raise
 
@@ -2458,6 +2491,14 @@
         except NoSuchObjectResourceError:
             raise HTTPError(NOT_FOUND)
 
+        # Map store exception to HTTP errors
+        except Exception as err:
+            if type(err) in self.StoreExceptionsErrors:
+                error, arg = self.StoreExceptionsErrors[type(err)]
+                error(err, arg)
+            else:
+                raise
+
         # Re-initialize to get stuff setup again now we have no object
         self._initializeWithObject(None, self._newStoreParent)
 
@@ -2590,51 +2631,51 @@
         else:
             return False
 
-    StoreExceptionsStatusErrors = set((
-        ObjectResourceNameNotAllowedError,
-        ObjectResourceNameAlreadyExistsError,
-    ))
-
     StoreExceptionsErrors = {
-        TooManyObjectResourcesError: customxml.MaxResources(),
-        ObjectResourceTooBigError: (caldav_namespace, "max-resource-size"),
-        InvalidObjectResourceError: (caldav_namespace, "valid-calendar-data"),
-        InvalidComponentForStoreError: (caldav_namespace, "valid-calendar-object-resource"),
-        InvalidComponentTypeError: (caldav_namespace, "supported-component"),
-        TooManyAttendeesError: MaxAttendeesPerInstance.fromString(str(config.MaxAttendeesPerInstance)),
-        InvalidCalendarAccessError: (calendarserver_namespace, "valid-access-restriction"),
-        ValidOrganizerError: (calendarserver_namespace, "valid-organizer"),
-        UIDExistsError: NoUIDConflict(),
-        UIDExistsElsewhereError: (caldav_namespace, "unique-scheduling-object-resource"),
-        InvalidUIDError: NoUIDConflict(),
-        InvalidPerUserDataMerge: (caldav_namespace, "valid-calendar-data"),
-        AttendeeAllowedError: (caldav_namespace, "attendee-allowed"),
-        InvalidOverriddenInstanceError: (caldav_namespace, "valid-calendar-data"),
-        TooManyInstancesError: MaxInstances.fromString(str(config.MaxAllowedInstances)),
-        AttachmentStoreValidManagedID: (caldav_namespace, "valid-managed-id"),
-        ShareeAllowedError: (calendarserver_namespace, "sharee-privilege-needed",),
-        DuplicatePrivateCommentsError: (calendarserver_namespace, "no-duplicate-private-comments",),
+        ObjectResourceNameNotAllowedError: (_CommonObjectResource._storeExceptionStatus, None,),
+        ObjectResourceNameAlreadyExistsError: (_CommonObjectResource._storeExceptionStatus, None,),
+        TooManyObjectResourcesError: (_CommonObjectResource._storeExceptionError, customxml.MaxResources(),),
+        ObjectResourceTooBigError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "max-resource-size"),),
+        InvalidObjectResourceError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-calendar-data"),),
+        InvalidComponentForStoreError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-calendar-object-resource"),),
+        InvalidComponentTypeError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "supported-component"),),
+        TooManyAttendeesError: (_CommonObjectResource._storeExceptionError, MaxAttendeesPerInstance.fromString(str(config.MaxAttendeesPerInstance)),),
+        InvalidCalendarAccessError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "valid-access-restriction"),),
+        ValidOrganizerError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "valid-organizer"),),
+        UIDExistsError: (_CommonObjectResource._storeExceptionError, NoUIDConflict(),),
+        UIDExistsElsewhereError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "unique-scheduling-object-resource"),),
+        InvalidUIDError: (_CommonObjectResource._storeExceptionError, NoUIDConflict(),),
+        InvalidPerUserDataMerge: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-calendar-data"),),
+        AttendeeAllowedError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "attendee-allowed"),),
+        InvalidOverriddenInstanceError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-calendar-data"),),
+        TooManyInstancesError: (_CommonObjectResource._storeExceptionError, MaxInstances.fromString(str(config.MaxAllowedInstances)),),
+        AttachmentStoreValidManagedID: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-managed-id"),),
+        ShareeAllowedError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "sharee-privilege-needed",),),
+        DuplicatePrivateCommentsError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "no-duplicate-private-comments",),),
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
     }
 
-    StoreMoveExceptionsStatusErrors = set((
-        ObjectResourceNameNotAllowedError,
-        ObjectResourceNameAlreadyExistsError,
-    ))
-
     StoreMoveExceptionsErrors = {
-        TooManyObjectResourcesError: customxml.MaxResources(),
-        InvalidResourceMove: (calendarserver_namespace, "valid-move"),
-        InvalidComponentTypeError: (caldav_namespace, "supported-component"),
+        ObjectResourceNameNotAllowedError: (_CommonObjectResource._storeExceptionStatus, None,),
+        ObjectResourceNameAlreadyExistsError: (_CommonObjectResource._storeExceptionStatus, None,),
+        TooManyObjectResourcesError: (_CommonObjectResource._storeExceptionError, customxml.MaxResources(),),
+        InvalidResourceMove: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "valid-move"),),
+        InvalidComponentTypeError: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "supported-component"),),
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
     }
 
+    StoreRemoveExceptionsErrors = {
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
+    }
+
     StoreAttachmentValidErrors = set((
         AttachmentStoreFailed,
         InvalidAttachmentOperation,
     ))
 
     StoreAttachmentExceptionsErrors = {
-        AttachmentStoreValidManagedID: (caldav_namespace, "valid-managed-id-parameter",),
-        AttachmentRemoveFailed: (caldav_namespace, "valid-attachment-remove",),
+        AttachmentStoreValidManagedID: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-managed-id-parameter",),),
+        AttachmentRemoveFailed: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-attachment-remove",),),
     }
 
 
@@ -2947,28 +2988,15 @@
         except Exception as err:
 
             if type(err) in self.StoreAttachmentValidErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    (caldav_namespace, valid_preconditions[action],),
-                    str(err),
-                ))
+                self._storeExceptionError(err, (caldav_namespace, valid_preconditions[action],))
 
             elif type(err) in self.StoreAttachmentExceptionsErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    self.StoreAttachmentExceptionsErrors[type(err)],
-                    str(err),
-                ))
+                error, arg = self.StoreAttachmentExceptionsErrors[type(err)]
+                error(err, arg)
 
-            elif type(err) in self.StoreExceptionsStatusErrors:
-                raise HTTPError(StatusResponse(responsecode.FORBIDDEN, str(err)))
-
             elif type(err) in self.StoreExceptionsErrors:
-                raise HTTPError(ErrorResponse(
-                    responsecode.FORBIDDEN,
-                    self.StoreExceptionsErrors[type(err)],
-                    str(err),
-                ))
+                error, arg = self.StoreExceptionsErrors[type(err)]
+                error(err, arg)
 
             else:
                 raise
@@ -3274,32 +3302,32 @@
 
     vCard = _CommonObjectResource.component
 
-    StoreExceptionsStatusErrors = set((
-        ObjectResourceNameNotAllowedError,
-        ObjectResourceNameAlreadyExistsError,
-    ))
-
     StoreExceptionsErrors = {
-        TooManyObjectResourcesError: customxml.MaxResources(),
-        ObjectResourceTooBigError: (carddav_namespace, "max-resource-size"),
-        InvalidObjectResourceError: (carddav_namespace, "valid-address-data"),
-        InvalidComponentForStoreError: (carddav_namespace, "valid-addressbook-object-resource"),
-        UIDExistsError: NovCardUIDConflict(),
-        InvalidUIDError: NovCardUIDConflict(),
-        InvalidPerUserDataMerge: (carddav_namespace, "valid-address-data"),
+        ObjectResourceNameNotAllowedError: (_CommonObjectResource._storeExceptionStatus, None,),
+        ObjectResourceNameAlreadyExistsError: (_CommonObjectResource._storeExceptionStatus, None,),
+        TooManyObjectResourcesError: (_CommonObjectResource._storeExceptionError, customxml.MaxResources(),),
+        ObjectResourceTooBigError: (_CommonObjectResource._storeExceptionError, (carddav_namespace, "max-resource-size"),),
+        InvalidObjectResourceError: (_CommonObjectResource._storeExceptionError, (carddav_namespace, "valid-address-data"),),
+        InvalidComponentForStoreError: (_CommonObjectResource._storeExceptionError, (carddav_namespace, "valid-addressbook-object-resource"),),
+        UIDExistsError: (_CommonObjectResource._storeExceptionError, NovCardUIDConflict(),),
+        InvalidUIDError: (_CommonObjectResource._storeExceptionError, NovCardUIDConflict(),),
+        InvalidPerUserDataMerge: (_CommonObjectResource._storeExceptionError, (carddav_namespace, "valid-address-data"),),
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
     }
 
-    StoreMoveExceptionsStatusErrors = set((
-        ObjectResourceNameNotAllowedError,
-        ObjectResourceNameAlreadyExistsError,
-    ))
-
     StoreMoveExceptionsErrors = {
-        TooManyObjectResourcesError: customxml.MaxResources(),
-        InvalidResourceMove: (calendarserver_namespace, "valid-move"),
+        ObjectResourceNameNotAllowedError: (_CommonObjectResource._storeExceptionStatus, None,),
+        ObjectResourceNameAlreadyExistsError: (_CommonObjectResource._storeExceptionStatus, None,),
+        TooManyObjectResourcesError: (_CommonObjectResource._storeExceptionError, customxml.MaxResources(),),
+        InvalidResourceMove: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "valid-move"),),
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
     }
 
+    StoreRemoveExceptionsErrors = {
+        LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
+    }
 
+
     def resourceType(self):
         if self.isShared():
             return customxml.ResourceType.sharedownergroup

Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/test/test_wrapping.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/test/test_wrapping.py	2014-01-08 21:53:27 UTC (rev 12271)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/twistedcaldav/test/test_wrapping.py	2014-01-08 22:13:14 UTC (rev 12272)
@@ -19,41 +19,37 @@
 """
 
 
+from twext.enterprise.ienterprise import AlreadyFinishedError
+from twext.enterprise.locking import NamedLock
+from twext.web2 import responsecode
+from twext.web2.http import HTTPError
+from twext.web2.http_headers import Headers, MimeType
+from twext.web2.responsecode import INSUFFICIENT_STORAGE_SPACE
 from twext.web2.responsecode import UNAUTHORIZED
-from twext.web2.http_headers import Headers
-from twext.enterprise.ienterprise import AlreadyFinishedError
+from twext.web2.stream import MemoryStream
 
-from txdav.xml import element as davxml
-from twistedcaldav.config import config
-
 from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import maybeDeferred
 
+from twistedcaldav.config import config
+from twistedcaldav.directory.test.test_xmlfile import XMLFileBase
 from twistedcaldav.ical import Component as VComponent
-from twistedcaldav.vcard import Component as VCComponent
-
 from twistedcaldav.storebridge import DropboxCollection, \
     CalendarCollectionResource
-
 from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
+from twistedcaldav.vcard import Component as VCComponent
 
-from txdav.idav import IDataStore
+from txdav.caldav.datastore.file import Calendar
 from txdav.caldav.datastore.test.test_file import test_event_text
-
+from txdav.caldav.icalendarstore import ICalendarHome
 from txdav.carddav.datastore.test.test_file import vcard4_text
-
+from txdav.carddav.iaddressbookstore import IAddressBookHome
 from txdav.common.datastore.test.util import assertProvides
-
-
-from twext.web2.http import HTTPError
-from twext.web2.responsecode import INSUFFICIENT_STORAGE_SPACE
-from twext.web2.stream import MemoryStream
 from txdav.common.datastore.test.util import deriveQuota
-from twistedcaldav.directory.test.test_xmlfile import XMLFileBase
-from txdav.caldav.icalendarstore import ICalendarHome
-from txdav.carddav.iaddressbookstore import IAddressBookHome
+from txdav.idav import IDataStore
+from txdav.xml import element as davxml
 
-from twisted.internet.defer import maybeDeferred
-from txdav.caldav.datastore.file import Calendar
+import hashlib
 
 def _todo(f, why):
     f.todo = why
@@ -560,3 +556,90 @@
         self.requestUnderTest = None
         yield self.assertCalendarEmpty(wsanchez)
         yield self.assertCalendarEmpty(cdaboo)
+
+
+
+class TimeoutTests(StoreTestCase):
+    """
+    Tests for L{twistedcaldav.storebridge} lock timeouts.
+    """
+
+    @inlineCallbacks
+    def test_timeoutOnPUT(self):
+        """
+        PUT gets a 503 on a lock timeout.
+        """
+
+        # Create a fake lock
+        txn = self.transactionUnderTest()
+        yield NamedLock.acquire(txn, "ImplicitUIDLock:%s" % (hashlib.md5("uid1").hexdigest(),))
+
+        # PUT fails
+        request = SimpleStoreRequest(
+            self,
+            "PUT",
+            "/calendars/users/wsanchez/calendar/1.ics",
+            headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
+            authid="wsanchez"
+        )
+        request.stream = MemoryStream("""BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Apple Computer\, Inc//iCal 2.0//EN
+VERSION:2.0
+BEGIN:VEVENT
+UID:uid1
+DTSTART;VALUE=DATE:20020101
+DTEND;VALUE=DATE:20020102
+DTSTAMP:20020101T121212Z
+SUMMARY:New Year's Day
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n"))
+        response = yield self.send(request)
+        self.assertEqual(response.code, responsecode.SERVICE_UNAVAILABLE)
+
+
+    @inlineCallbacks
+    def test_timeoutOnDELETE(self):
+        """
+        DELETE gets a 503 on a lock timeout.
+        """
+
+        # PUT works
+        request = SimpleStoreRequest(
+            self,
+            "PUT",
+            "/calendars/users/wsanchez/calendar/1.ics",
+            headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
+            authid="wsanchez"
+        )
+        request.stream = MemoryStream("""BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Apple Computer\, Inc//iCal 2.0//EN
+VERSION:2.0
+BEGIN:VEVENT
+UID:uid1
+DTSTART;VALUE=DATE:20020101
+DTEND;VALUE=DATE:20020102
+DTSTAMP:20020101T121212Z
+ORGANIZER:mailto:wsanchez at example.com
+ATTENDEE:mailto:wsanchez at example.com
+SUMMARY:New Year's Day
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n"))
+        response = yield self.send(request)
+        self.assertEqual(response.code, responsecode.CREATED)
+
+        # Create a fake lock
+        txn = self.transactionUnderTest()
+        yield NamedLock.acquire(txn, "ImplicitUIDLock:%s" % (hashlib.md5("uid1").hexdigest(),))
+
+        request = SimpleStoreRequest(
+            self,
+            "DELETE",
+            "/calendars/users/wsanchez/calendar/1.ics",
+            authid="wsanchez"
+        )
+        response = yield self.send(request)
+        self.assertEqual(response.code, responsecode.SERVICE_UNAVAILABLE)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/2d8385df/attachment.html>


More information about the calendarserver-changes mailing list