def test_upgradeFromEmptyDropbox(self):
        """
        Test L{attachment_migration.doUpgrade} when managed attachments is enabled and dropbox items do not exist.
        """

        didUpgrade = [False, ]
        def _hasDropboxAttachments(_self, txn):
            return succeed(False)
        self.patch(CalendarStoreFeatures, "hasDropboxAttachments", _hasDropboxAttachments)

        def _upgradeToManagedAttachments(_self, batchSize=10):
            didUpgrade[0] = True
            return succeed(None)
        self.patch(CalendarStoreFeatures, "upgradeToManagedAttachments", _upgradeToManagedAttachments)

        store = (yield self._initStore())

        upgrader = UpgradeDatabaseOtherStep(store)
        yield attachment_migration.doUpgrade(upgrader)
        self.assertFalse(didUpgrade[0])

        txn = upgrader.sqlStore.newTransaction()
        managed = (yield txn.calendarserverValue("MANAGED-ATTACHMENTS", raiseIfMissing=False))
        yield txn.commit()
        self.assertNotEqual(managed, None)
Example #2
0
    def test_upgradeFromEmptyDropbox(self):
        """
        Test L{attachment_migration.doUpgrade} when managed attachments is enabled and dropbox items do not exist.
        """

        didUpgrade = [
            False,
        ]

        def _hasDropboxAttachments(_self, txn):
            return succeed(False)

        self.patch(CalendarStoreFeatures, "hasDropboxAttachments",
                   _hasDropboxAttachments)

        def _upgradeToManagedAttachments(_self, batchSize=10):
            didUpgrade[0] = True
            return succeed(None)

        self.patch(CalendarStoreFeatures, "upgradeToManagedAttachments",
                   _upgradeToManagedAttachments)

        store = (yield self._initStore())

        upgrader = UpgradeDatabaseOtherStep(store)
        yield attachment_migration.doUpgrade(upgrader)
        self.assertFalse(didUpgrade[0])

        txn = upgrader.sqlStore.newTransaction()
        managed = (yield txn.calendarserverValue("MANAGED-ATTACHMENTS",
                                                 raiseIfMissing=False))
        yield txn.commit()
        self.assertNotEqual(managed, None)
Example #3
0
    def test_upgradeOrphanedAttachment(self):
        """
        Test L{attachment_migration.doUpgrade} when an orphaned attachment is present.
        """
        def _hasDropboxAttachments(_self, txn):
            return succeed(True)

        self.patch(CalendarStoreFeatures, "hasDropboxAttachments",
                   _hasDropboxAttachments)

        # Create orphaned attachment
        dropboxID = "ABCD.dropbox"
        attachmentName = "test.txt"
        home = yield self.homeUnderTest(name="user01")
        at = schema.ATTACHMENT
        yield Insert({
            at.CALENDAR_HOME_RESOURCE_ID: home._resourceID,
            at.DROPBOX_ID: dropboxID,
            at.CONTENT_TYPE: "text/plain",
            at.SIZE: 10,
            at.MD5: "abcd",
            at.PATH: attachmentName,
        }).on(self.transactionUnderTest())
        yield self.commit()

        hasheduid = hashlib.md5(dropboxID).hexdigest()
        fp = self._sqlCalendarStore.attachmentsPath.child(
            hasheduid[0:2]).child(hasheduid[2:4]).child(hasheduid)
        fp.makedirs()
        fp = fp.child(attachmentName)
        fp.setContent("1234567890")

        self.assertTrue(os.path.exists(fp.path))

        upgrader = UpgradeDatabaseOtherStep(self._sqlCalendarStore)
        yield attachment_migration.doUpgrade(upgrader)

        txn = upgrader.sqlStore.newTransaction()
        managed = (yield txn.calendarserverValue("MANAGED-ATTACHMENTS",
                                                 raiseIfMissing=False))
        count = (yield Select(
            [
                Count(at.DROPBOX_ID),
            ],
            From=at,
        ).on(txn))[0][0]
        yield txn.commit()
        self.assertEqual(count, 1)
        self.assertNotEqual(managed, None)

        self.assertTrue(os.path.exists(fp.path))
    def test_upgradeOrphanedAttachment(self):
        """
        Test L{attachment_migration.doUpgrade} when an orphaned attachment is present.
        """

        def _hasDropboxAttachments(_self, txn):
            return succeed(True)
        self.patch(CalendarStoreFeatures, "hasDropboxAttachments", _hasDropboxAttachments)

        # Create orphaned attachment
        dropboxID = "ABCD.dropbox"
        attachmentName = "test.txt"
        home = yield self.homeUnderTest(name="user01")
        at = schema.ATTACHMENT
        yield Insert(
            {
                at.CALENDAR_HOME_RESOURCE_ID: home._resourceID,
                at.DROPBOX_ID: dropboxID,
                at.CONTENT_TYPE: "text/plain",
                at.SIZE: 10,
                at.MD5: "abcd",
                at.PATH: attachmentName,
            }
        ).on(self.transactionUnderTest())
        yield self.commit()

        hasheduid = hashlib.md5(dropboxID).hexdigest()
        fp = self._sqlCalendarStore.attachmentsPath.child(hasheduid[0:2]).child(hasheduid[2:4]).child(hasheduid)
        fp.makedirs()
        fp = fp.child(attachmentName)
        fp.setContent("1234567890")

        self.assertTrue(os.path.exists(fp.path))

        upgrader = UpgradeDatabaseOtherStep(self._sqlCalendarStore)
        yield attachment_migration.doUpgrade(upgrader)

        txn = upgrader.sqlStore.newTransaction()
        managed = (yield txn.calendarserverValue("MANAGED-ATTACHMENTS", raiseIfMissing=False))
        count = (yield Select(
            [Count(at.DROPBOX_ID), ],
            From=at,
        ).on(txn))[0][0]
        yield txn.commit()
        self.assertEqual(count, 1)
        self.assertNotEqual(managed, None)

        self.assertTrue(os.path.exists(fp.path))
Example #5
0
    def databaseUpgrade(self):
        """
        Do upgrades.
        """
        self.log.warn("Beginning database %s check." % (self.versionDescriptor,))

        # Do each upgrade in our own predefined order
        self.sqlStore.setUpgrading(True)

        # Migration from dropbox to managed attachments
        yield attachment_migration.doUpgrade(self)

        self.sqlStore.setUpgrading(False)

        self.log.warn("Database %s check complete." % (self.versionDescriptor,))

        returnValue(None)
Example #6
0
    def databaseUpgrade(self):
        """
        Do upgrades.
        """
        self.log.warn("Beginning database {vers} check.", vers=self.versionDescriptor)

        # Do each upgrade in our own predefined order
        self.sqlStore.setUpgrading(True)

        # Migration from dropbox to managed attachments
        yield attachment_migration.doUpgrade(self)

        self.sqlStore.setUpgrading(False)

        self.log.warn("Database {vers} check complete.", vers=self.versionDescriptor)

        returnValue(None)
Example #7
0
    def databaseUpgrade(self):
        """
        Do upgrades.
        """
        self.log_warn("Beginning database %s check." % (self.versionDescriptor,))

        # Do each upgrade in our own predefined order
        self.sqlStore.setUpgrading(True)

        # Migration from dropbox to managed attachments
        yield attachment_migration.doUpgrade(self)

        self.sqlStore.setUpgrading(False)

        self.log_warn("Database %s check complete." % (self.versionDescriptor,))

        # see http://twistedmatrix.com/trac/ticket/4649
        if self.wrappedService is not None:
            reactor.callLater(0, self.wrappedService.setServiceParent, self.parent)