Skip to content

Commit

Permalink
Make sure null entries in old resourceinfo.sql databases don't preven…
Browse files Browse the repository at this point in the history
…t upgrade/migration from happening.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk@15563 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information
cyrusdaboo committed Mar 1, 2016
1 parent 64bdd72 commit 29913a4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 21 deletions.
67 changes: 57 additions & 10 deletions twistedcaldav/test/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@
# limitations under the License.
##

import cPickle
import hashlib
import os
import zlib

from twisted.internet.defer import inlineCallbacks, succeed
from twisted.python.filepath import FilePath
from twisted.python.reflect import namedClass

from twistedcaldav.config import config
from twistedcaldav.directory.calendaruserproxy import ProxySqliteDB
from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
from twistedcaldav.test.util import StoreTestCase
from twistedcaldav.upgrade import (
xattrname, upgradeData, updateFreeBusySet,
removeIllegalCharacters, normalizeCUAddrs,
loadDelegatesFromXMLintoProxyDB, migrateDelegatesToStore,
upgradeResourcesXML, upgradeAugmentsXML
)
from twistedcaldav.upgrade import xattrname, upgradeData, updateFreeBusySet, \
removeIllegalCharacters, normalizeCUAddrs, \
loadDelegatesFromXMLintoProxyDB, migrateDelegatesToStore, \
upgradeResourcesXML, upgradeAugmentsXML, migrateAutoSchedule

from txdav.caldav.datastore.index_file import db_basename
from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
from txdav.who.delegates import Delegates
from txdav.xml.parser import WebDAVDocument

import cPickle
import hashlib
import os
import zlib



freeBusyAttr = xattrname(
Expand Down Expand Up @@ -1505,6 +1508,50 @@ def test_migrateDelegates(self):
sqliteProxyService.close()


@inlineCallbacks
def test_migrateAutoSchedule(self):

serviceClass = {
"xml": "twistedcaldav.directory.augment.AugmentXMLDB",
}
augmentClass = namedClass(serviceClass[config.AugmentService.type])

# Auto-schedule not currently set
augmentService = augmentClass(**config.AugmentService.params)
augmentRecord = (
yield augmentService.getAugmentRecord(
"mercury",
"locations"
)
)
self.assertEqual(augmentRecord.autoScheduleMode, "default")

# Create bogus record in resourceinfo db
resourceInfoDatabase = ResourceInfoDatabase(config.DataRoot)
resourceInfoDatabase._db_execute(
"insert into RESOURCEINFO (GUID, AUTOSCHEDULE) values (:1, :2)",
"mercury", 1,
)
resourceInfoDatabase._db_execute(
"insert into RESOURCEINFO (GUID, AUTOSCHEDULE) values (:1, :2)",
None, 1,
)
resourceInfoDatabase._db_commit()

# Migrate auto-schedule from sqlite into directory
yield migrateAutoSchedule(config, self.directory)

# Auto-schedule now set
augmentService = augmentClass(**config.AugmentService.params)
augmentRecord = (
yield augmentService.getAugmentRecord(
"mercury",
"locations"
)
)
self.assertEqual(augmentRecord.autoScheduleMode, "automatic")


def test_resourcesXML(self):
"""
Verify conversion of old resources.xml format to twext.who.xml format
Expand Down
23 changes: 12 additions & 11 deletions twistedcaldav/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,18 +1011,19 @@ def migrateAutoSchedule(config, directory):
"select GUID, AUTOSCHEDULE from RESOURCEINFO"
)
for uid, autoSchedule in results:
record = yield directory.recordWithUID(uid)
if record is not None:
augmentRecord = (
yield augmentService.getAugmentRecord(
uid,
directory.recordTypeToOldName(record.recordType)
if uid is not None:
record = yield directory.recordWithUID(uid)
if record is not None:
augmentRecord = (
yield augmentService.getAugmentRecord(
uid,
directory.recordTypeToOldName(record.recordType)
)
)
)
augmentRecord.autoScheduleMode = (
"automatic" if autoSchedule else "default"
)
augmentRecords.append(augmentRecord)
augmentRecord.autoScheduleMode = (
"automatic" if autoSchedule else "default"
)
augmentRecords.append(augmentRecord)

if augmentRecords:
yield augmentService.addAugmentRecords(augmentRecords)
Expand Down

0 comments on commit 29913a4

Please sign in to comment.