def test_migrateResources(self): # Record location1 has not been migrated record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record, None) # Migrate location1, location2, and resource1 yield migrateResources(self.sourceService, self.directory) record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record.uid, u"location1") self.assertEquals(record.shortNames[0], u"loc1") record = yield self.directory.recordWithUID(u"location2") self.assertEquals(record.uid, u"location2") self.assertEquals(record.shortNames[0], u"loc2") record = yield self.directory.recordWithUID(u"resource1") self.assertEquals(record.uid, u"resource1") self.assertEquals(record.shortNames[0], u"res1") # Add a new location to the sourceService, and modify an existing # location fieldName = self.sourceService.fieldName newRecords = ( TestRecord( self.sourceService, { fieldName.uid: u"location1", fieldName.shortNames: (u"newloc1",), fieldName.recordType: CalRecordType.location, } ), TestRecord( self.sourceService, { fieldName.uid: u"location3", fieldName.shortNames: (u"loc3",), fieldName.recordType: CalRecordType.location, } ), ) yield self.sourceService.updateRecords(newRecords, create=True) yield migrateResources(self.sourceService, self.directory) # Ensure an existing record does not get migrated again; verified by # seeing if shortNames changed, which they should not: record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record.uid, u"location1") self.assertEquals(record.shortNames[0], u"loc1") # Ensure new record does get migrated record = yield self.directory.recordWithUID(u"location3") self.assertEquals(record.uid, u"location3") self.assertEquals(record.shortNames[0], u"loc3")
def test_migrateResources(self): # Record location1 has not been migrated record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record, None) # Migrate location1, location2, and resource1 yield migrateResources(self.sourceService, self.directory) record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record.uid, u"location1") self.assertEquals(record.shortNames[0], u"loc1") record = yield self.directory.recordWithUID(u"location2") self.assertEquals(record.uid, u"location2") self.assertEquals(record.shortNames[0], u"loc2") record = yield self.directory.recordWithUID(u"resource1") self.assertEquals(record.uid, u"resource1") self.assertEquals(record.shortNames[0], u"res1") # Add a new location to the sourceService, and modify an existing # location fieldName = self.sourceService.fieldName newRecords = ( TestRecord( self.sourceService, { fieldName.uid: u"location1", fieldName.shortNames: (u"newloc1",), fieldName.recordType: CalRecordType.location, } ), TestRecord( self.sourceService, { fieldName.uid: u"location3", fieldName.shortNames: (u"loc3",), fieldName.recordType: CalRecordType.location, } ), ) yield self.sourceService.updateRecords(newRecords, create=True) yield migrateResources(self.sourceService, self.directory) # Ensure an existing record does not get migrated again; verified by # seeing if shortNames changed, which they should not: record = yield self.directory.recordWithUID(u"location1") self.assertEquals(record.uid, u"location1") self.assertEquals(record.shortNames[0], u"loc1") # Ensure new record does get migrated record = yield self.directory.recordWithUID(u"location3") self.assertEquals(record.uid, u"location3") self.assertEquals(record.shortNames[0], u"loc3")
def migrateFromOD(directory): # # Migrates locations and resources from OD # log.warn("Migrating locations and resources") # Create internal copies of resources and locations based on what is # found in OD from twext.who.opendirectory import ( DirectoryService as OpenDirectoryService ) from calendarserver.tools.resources import migrateResources return migrateResources(OpenDirectoryService(), directory)
def migrateFromOD(config, directory): # # Migrates locations and resources from OD # log.warn("Migrating locations and resources") userService = directory.serviceForRecordType("users") resourceService = directory.serviceForRecordType("resources") if ( not isinstance(userService, OpenDirectoryService) or not isinstance(resourceService, XMLDirectoryService) ): # Configuration requires no migration return succeed(None) # Create internal copies of resources and locations based on what is # found in OD return migrateResources(userService, resourceService)
def migrateFromOD(directory): # # Migrates locations and resources from OD # log.warn("Migrating locations and resources") # Create internal copies of resources and locations based on what is # found in OD from twext.who.idirectory import RecordType as BaseRecordType from twext.who.opendirectory import (DirectoryService as OpenDirectoryService) from twext.who.util import ConstantsContainer from calendarserver.tools.resources import migrateResources from txdav.who.opendirectory import _CSRecordType # Use this module for the import to make sure constants are setup properly # We need to "patch" twext.who.opendirectory._service.DirectoryService to include resources and locations as supported record types # during migration class EnhancedDirectoryService(OpenDirectoryService): recordType = ConstantsContainer( (BaseRecordType.user, BaseRecordType.group, _CSRecordType.location, _CSRecordType.resource)) return migrateResources(EnhancedDirectoryService(), directory)
def migrateFromOD(config, directory): # # Migrates locations and resources from OD # try: from twistedcaldav.directory.appleopendirectory import OpenDirectoryService from calendarserver.tools.resources import migrateResources except ImportError: return succeed(None) log.warn("Migrating locations and resources") userService = directory.serviceForRecordType("users") resourceService = directory.serviceForRecordType("resources") if ( not isinstance(userService, OpenDirectoryService) or not isinstance(resourceService, XMLDirectoryService) ): # Configuration requires no migration return succeed(None) # Create internal copies of resources and locations based on what is # found in OD return migrateResources(userService, resourceService)
def test_migrateResources(self): data = { dsattributes.kDSStdRecordTypeResources : [ ['projector1', { strGUID : '6C99E240-E915-4012-82FA-99E0F638D7EF', strName : 'Projector 1' }], ['projector2', { strGUID : '7C99E240-E915-4012-82FA-99E0F638D7EF', strName : 'Projector 2' }], ], dsattributes.kDSStdRecordTypePlaces : [ ['office1', { strGUID : '8C99E240-E915-4012-82FA-99E0F638D7EF', strName : 'Office 1' }], ], } def queryMethod(sourceService, recordType, verbose=False): return data[recordType] directoryService = StubDirectoryService(StubAugmentService()) yield migrateResources(None, directoryService, queryMethod=queryMethod) for guid, recordType in ( ('6C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_resources), ('7C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_resources), ('8C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_locations), ): self.assertTrue(guid in directoryService.records) record = directoryService.records[guid] self.assertEquals(record.recordType, recordType) self.assertTrue(guid in StubAugmentService.records) # # Add more to OD and re-migrate # data[dsattributes.kDSStdRecordTypeResources].append( ['projector3', { strGUID : '9C99E240-E915-4012-82FA-99E0F638D7EF', strName : 'Projector 3' }] ) data[dsattributes.kDSStdRecordTypePlaces].append( ['office2', { strGUID : 'AC99E240-E915-4012-82FA-99E0F638D7EF', strName : 'Office 2' }] ) yield migrateResources(None, directoryService, queryMethod=queryMethod) for guid, recordType in ( ('6C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_resources), ('7C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_resources), ('9C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_resources), ('8C99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_locations), ('AC99E240-E915-4012-82FA-99E0F638D7EF', DirectoryService.recordType_locations), ): self.assertTrue(guid in directoryService.records) record = directoryService.records[guid] self.assertEquals(record.recordType, recordType) self.assertTrue(guid in StubAugmentService.records)