def test_logging(self): """ Logging module configures properly. """ defaultLogLevel = Logger.filterPredicate.logLevelForNamespace(None) self.assertNotEqual( defaultLogLevel, LogLevel.error, "This test assumes the default log level is not error." ) config.setDefaults(DEFAULT_CONFIG) config.reload() self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), defaultLogLevel) self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), defaultLogLevel) config.load(self.testConfig) self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), LogLevel.error) self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), LogLevel.debug) writePlist({}, self.testConfig) config.reload() self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), defaultLogLevel) self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), defaultLogLevel)
def test_logging(self): """ Logging module configures properly. """ self.assertNotEqual( defaultLogLevel, LogLevel.error, "This test assumes the default log level is not error." ) config.setDefaults(DEFAULT_CONFIG) config.reload() self.assertEquals(logLevelForNamespace(None), defaultLogLevel) self.assertEquals(logLevelForNamespace("some.namespace"), defaultLogLevel) config.load(self.testConfig) self.assertEquals(logLevelForNamespace(None), LogLevel.error) self.assertEquals(logLevelForNamespace("some.namespace"), LogLevel.debug) writePlist({}, self.testConfig) config.reload() self.assertEquals(logLevelForNamespace(None), defaultLogLevel) self.assertEquals(logLevelForNamespace("some.namespace"), defaultLogLevel)
def testSyncToken(self): config.load(self.testConfig) # no sync token keys specified; need to empty this array here because # stdconfig is registering keys automatically config._syncTokenKeys = [] self.assertEquals("d41d8cd98f00b204e9800998ecf8427e", config.syncToken()) # add sync token keys (some with multiple levels) config.addSyncTokenKey("DefaultLogLevel") config.addSyncTokenKey("Notifications.Services.APNS.Enabled") config.addSyncTokenKey("Notifications.Services.APNS.CalDAV.Topic") config.addSyncTokenKey("Notifications.Services.APNS.CardDAV.Topic") self.assertEquals("7473205187d7a6ff0c61a2b6b04053c5", config.syncToken()) # modify a sync token key value config.Notifications.Services.APNS.CalDAV.Topic = "changed" # direct manipulation of config requires explicit invalidation self.assertEquals("7473205187d7a6ff0c61a2b6b04053c5", config.syncToken()) config.invalidateSyncToken() self.assertEquals("4cdbb3841625d001dc768439f5a88cba", config.syncToken()) # add a non existent key (not an error because it could exist later) config.addSyncTokenKey("Notifications.Services.APNS.CalDAV.NonExistent") config.invalidateSyncToken() self.assertEquals("2ffb128cee5a4b217cef82fd31ae7767", config.syncToken()) # reload automatically invalidates config.reload() self.assertEquals("a1c46c5aff1899658dac033ee8520b07", config.syncToken())
def testScoping(self): self.assertEquals(config.ResponseCompression, False) config.load(self.testConfig) self.assertEquals(config.ResponseCompression, True) _testResponseCompression(self)
def loadConfig(configFileName): if configFileName is None: configFileName = DEFAULT_CONFIG_FILE if not os.path.isfile(configFileName): raise ConfigurationError("No config file: %s" % (configFileName,)) config.load(configFileName) return config
def testReloading(self): self.assertEquals(config.HTTPPort, 0) config.load(self.testConfig) self.assertEquals(config.HTTPPort, 8008) writePlist({}, self.testConfig) config.reload() self.assertEquals(config.HTTPPort, 0)
def loadConfiguration(self): if not os.path.exists(self["config"]): print "Config file %s not found. Exiting." % (self["config"],) sys.exit(1) print "Reading configuration from file: %s" % (self["config"],) try: config.load(self["config"]) except ConfigurationError, e: print "Invalid configuration: %s" % (e,) sys.exit(1)
def loadConfiguration(self): if not os.path.exists(self["config"]): self.log_info("Config file %s not found, using defaults" % (self["config"],)) self.log_info("Reading configuration from file: %s" % (self["config"],)) try: config.load(self["config"]) except ConfigurationError, e: log.err("Invalid configuration: %s" % (e,)) sys.exit(1)
def testUpdateDefaults(self): self.assertEquals(config.SSLPort, 0) config.load(self.testConfig) config.updateDefaults({"SSLPort": 8009}) self.assertEquals(config.SSLPort, 8009) config.reload() self.assertEquals(config.SSLPort, 8009) config.updateDefaults({"SSLPort": 0})
def testUpdateAndReload(self): self.assertEquals(config.HTTPPort, 0) config.load(self.testConfig) self.assertEquals(config.HTTPPort, 8008) config.update({"HTTPPort": 80}) self.assertEquals(config.HTTPPort, 80) config.reload() self.assertEquals(config.HTTPPort, 8008)
def testPreserveAcrossReload(self): self.assertEquals(config.Scheduling.iMIP.Sending.Password, "") self.assertEquals(config.Scheduling.iMIP.Receiving.Password, "") config.load(self.testConfig) self.assertEquals(config.Scheduling.iMIP.Sending.Password, "sending") self.assertEquals(config.Scheduling.iMIP.Receiving.Password, "receiving") writePlist({}, self.testConfig) config.reload() self.assertEquals(config.Scheduling.iMIP.Sending.Password, "sending") self.assertEquals(config.Scheduling.iMIP.Receiving.Password, "receiving")
def setUp(self): super(ManagePrincipalsTestCase, self).setUp() # Since this test operates on proxy db, we need to assign the service: calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp())) config.GlobalAddressBook.Enabled = False testRoot = os.path.join(os.path.dirname(__file__), "principals") templateName = os.path.join(testRoot, "caldavd.plist") templateFile = open(templateName) template = templateFile.read() templateFile.close() databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid())) newConfig = template % { "ServerRoot" : os.path.abspath(config.ServerRoot), "DataRoot" : os.path.abspath(config.DataRoot), "DatabaseRoot" : databaseRoot, "DocumentRoot" : os.path.abspath(config.DocumentRoot), "LogRoot" : os.path.abspath(config.LogRoot), } configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist")) configFilePath.setContent(newConfig) self.configFileName = configFilePath.path config.load(self.configFileName) origUsersFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "users-groups.xml")) copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml")) origUsersFile.copyTo(copyUsersFile) origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "resources-locations.xml")) copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml")) origResourcesFile.copyTo(copyResourcesFile) origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "augments.xml")) copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml")) origAugmentFile.copyTo(copyAugmentFile) # Make sure trial puts the reactor in the right state, by letting it # run one reactor iteration. (Ignore me, please.) d = Deferred() reactor.callLater(0, d.callback, True) return d
def testReloading(self): self.assertEquals(config.HTTPPort, 0) config.load(self.testConfig) self.assertEquals(config.HTTPPort, 8008) writePlist({}, self.testConfig) self._reloadingValue = None config.addPostUpdateHooks([self._myUpdateHook]) config.reload() # Make sure reloading=True was passed to the update hooks self.assertTrue(self._reloadingValue) self.assertEquals(config.HTTPPort, 0)
def loadConfig(configFileName): """ Helper method for command-line utilities to load configuration plist and override certain values. """ if configFileName is None: configFileName = DEFAULT_CONFIG_FILE if not os.path.isfile(configFileName): raise ConfigurationError("No config file: %s" % (configFileName, )) config.load(configFileName) # Command-line utilities always want these enabled: config.EnableCalDAV = True config.EnableCardDAV = True return config
def loadConfig(configFileName): """ Helper method for command-line utilities to load configuration plist and override certain values. """ if configFileName is None: configFileName = DEFAULT_CONFIG_FILE if not os.path.isfile(configFileName): raise ConfigurationError("No config file: %s" % (configFileName,)) config.load(configFileName) # Command-line utilities always want these enabled: config.EnableCalDAV = True config.EnableCardDAV = True return config
def test_logging(self): """ Logging module configures properly. """ config.setDefaults(DEFAULT_CONFIG) config.reload() self.assertEquals(logLevelForNamespace(None), "warn") self.assertEquals(logLevelForNamespace("some.namespace"), "warn") config.load(self.testConfig) self.assertEquals(logLevelForNamespace(None), "info") self.assertEquals(logLevelForNamespace("some.namespace"), "debug") writePlist({}, self.testConfig) config.reload() self.assertEquals(logLevelForNamespace(None), "warn") self.assertEquals(logLevelForNamespace("some.namespace"), "warn")
def setUp(self): super(RunCommandTestCase, self).setUp() testRoot = os.path.join(os.path.dirname(__file__), "gateway") templateName = os.path.join(testRoot, "caldavd.plist") templateFile = open(templateName) template = templateFile.read() templateFile.close() databaseRoot = os.path.abspath("_spawned_scripts_db" + str(os.getpid())) newConfig = template % { "ServerRoot" : os.path.abspath(config.ServerRoot), "DatabaseRoot" : databaseRoot, "WritablePlist" : os.path.join(os.path.abspath(config.ConfigRoot), "caldavd-writable.plist"), } configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist")) configFilePath.setContent(newConfig) self.configFileName = configFilePath.path config.load(self.configFileName) origUsersFile = FilePath(os.path.join(os.path.dirname(__file__), "gateway", "users-groups.xml")) copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml")) origUsersFile.copyTo(copyUsersFile) origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__), "gateway", "resources-locations.xml")) copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml")) origResourcesFile.copyTo(copyResourcesFile) origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__), "gateway", "augments.xml")) copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml")) origAugmentFile.copyTo(copyAugmentFile) # Make sure trial puts the reactor in the right state, by letting it # run one reactor iteration. (Ignore me, please.) d = Deferred() reactor.callLater(0, d.callback, True) return d
def setUp(self): super(ManagePrincipalsTestCase, self).setUp() config.GlobalAddressBook.Enabled = False testRoot = os.path.join(os.path.dirname(__file__), "principals") templateName = os.path.join(testRoot, "caldavd.plist") templateFile = open(templateName) template = templateFile.read() templateFile.close() newConfig = template % { "ServerRoot" : os.path.abspath(config.ServerRoot), } configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist")) configFilePath.setContent(newConfig) self.configFileName = configFilePath.path config.load(self.configFileName) origUsersFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "users-groups.xml")) copyUsersFile = FilePath(os.path.join(config.DataRoot, "accounts.xml")) origUsersFile.copyTo(copyUsersFile) origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "resources-locations.xml")) copyResourcesFile = FilePath(os.path.join(config.DataRoot, "resources.xml")) origResourcesFile.copyTo(copyResourcesFile) origAugmentFile = FilePath(os.path.join(os.path.dirname(__file__), "principals", "augments.xml")) copyAugmentFile = FilePath(os.path.join(config.DataRoot, "augments.xml")) origAugmentFile.copyTo(copyAugmentFile) # Make sure trial puts the reactor in the right state, by letting it # run one reactor iteration. (Ignore me, please.) d = Deferred() reactor.callLater(0, d.callback, True) return d
def setUp(self): super(DeprovisionTestCase, self).setUp() testRootPath = FilePath(__file__).sibling("deprovision") template = testRootPath.child("caldavd.plist").getContent() newConfig = template % { "ServerRoot" : os.path.abspath(config.ServerRoot), } configFilePath = FilePath(os.path.join(config.ConfigRoot, "caldavd.plist")) configFilePath.setContent(newConfig) self.configFileName = configFilePath.path config.load(self.configFileName) origUsersFile = FilePath(__file__).sibling( "deprovision").child("users-groups.xml") copyUsersFile = FilePath(config.DataRoot).child("accounts.xml") origUsersFile.copyTo(copyUsersFile) origResourcesFile = FilePath(__file__).sibling( "deprovision").child("resources-locations.xml") copyResourcesFile = FilePath(config.DataRoot).child("resources.xml") origResourcesFile.copyTo(copyResourcesFile) origAugmentFile = FilePath(__file__).sibling( "deprovision").child("augments.xml") copyAugmentFile = FilePath(config.DataRoot).child("augments.xml") origAugmentFile.copyTo(copyAugmentFile) self.rootResource = getRootResource(config) self.directory = self.rootResource.getDirectory() # Make sure trial puts the reactor in the right state, by letting it # run one reactor iteration. (Ignore me, please.) d = Deferred() reactor.callLater(0, d.callback, True) return d
def postOptions(self): config.load(self['config']) config.updateDefaults(self.overrides) self.parent['pidfile'] = None
def testLoadConfig(self): self.assertEquals(config.ResponseCompression, False) config.load(self.testConfig) self.assertEquals(config.ResponseCompression, True)
configFileName = DEFAULT_CONFIG_FILE writeConfigFileName = "" for opt, arg in optargs: if opt in ("-h", "--help"): usage() elif opt in ("-f", "--config"): configFileName = arg elif opt in ("-w", "--writeconfig"): writeConfigFileName = arg try: config.load(configFileName) except ConfigurationError, e: sys.stdout.write("%s\n" % (e, )) sys.exit(1) if not writeConfigFileName: # If --writeconfig was not passed, use WritableConfigFile from # main plist. If that's an empty string, writes will happen to # the main file. writeConfigFileName = config.WritableConfigFile if not writeConfigFileName: writeConfigFileName = configFileName writable = WritableConfig(config, writeConfigFileName) writable.read()
def test_HostnameInclude(self): testConfigMaster = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>ResponseCompression</key> <false/> <key>ServerRoot</key> <string></string> <key>ConfigRoot</key> <string></string> <key>HTTPPort</key> <integer>8008</integer> <key>SSLPort</key> <integer>8443</integer> <key>DefaultLogLevel</key> <string>info</string> <key>LogLevels</key> <dict> <key>some.namespace</key> <string>debug</string> </dict> <key>Includes</key> <array> <string>%s.#</string> </array> </dict> </plist> """ testConfigInclude = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>HTTPPort</key> <integer>9008</integer> </dict> </plist> """ config.setProvider(PListConfigProvider(DEFAULT_CONFIG)) self.testIncludeRoot = self.mktemp() self.testInclude = self.testIncludeRoot + "." + socket.gethostbyname(socket.getfqdn()) open(self.testInclude, "w").write(testConfigInclude) self.testMaster = self.mktemp() open(self.testMaster, "w").write(testConfigMaster % (self.testIncludeRoot,)) config.load(self.testMaster) self.assertEquals(config.HTTPPort, 9008) self.assertEquals(config.SSLPort, 8443)
configFileName = arg elif opt in ("-w", "--writeconfig"): writeConfigFileName = arg if opt == "--stop": doStop = True if opt == "--start": doStart = True if opt in ("-r", "--restart"): doRestart = True try: config.load(configFileName) except ConfigurationError, e: sys.stdout.write("%s\n" % (e,)) sys.exit(1) if not writeConfigFileName: # If --writeconfig was not passed, use WritableConfigFile from # main plist. If that's an empty string, writes will happen to # the main file. writeConfigFileName = config.WritableConfigFile if not writeConfigFileName: writeConfigFileName = configFileName if doStop: setServiceState("org.calendarserver.agent", "disable")
def test_HostnameInclude(self): testConfigMaster = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>ResponseCompression</key> <false/> <key>ServerRoot</key> <string></string> <key>ConfigRoot</key> <string></string> <key>HTTPPort</key> <integer>8008</integer> <key>SSLPort</key> <integer>8443</integer> <key>DefaultLogLevel</key> <string>info</string> <key>LogLevels</key> <dict> <key>some.namespace</key> <string>debug</string> </dict> <key>Includes</key> <array> <string>%s.#</string> </array> </dict> </plist> """ testConfigInclude = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>HTTPPort</key> <integer>9008</integer> </dict> </plist> """ config.setProvider(PListConfigProvider(DEFAULT_CONFIG)) self.testIncludeRoot = self.mktemp() self.testInclude = self.testIncludeRoot + "." + socket.gethostbyname(socket.getfqdn()) with open(self.testInclude, "w") as f: f.write(testConfigInclude) self.testMaster = self.mktemp() with open(self.testMaster, "w") as f: f.write(testConfigMaster % (self.testIncludeRoot,)) config.load(self.testMaster) self.assertEquals(config.HTTPPort, 9008) self.assertEquals(config.SSLPort, 8443)