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 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())
Beispiel #3
0
    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 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 testSetDefaults(self):
        config.updateDefaults({"SSLPort": 8443})

        config.setDefaults(DEFAULT_CONFIG)

        config.reload()

        self.assertEquals(config.SSLPort, 0)
    def testSetDefaults(self):
        config.updateDefaults({"SSLPort": 8443})

        config.setDefaults(DEFAULT_CONFIG)

        config.reload()

        self.assertEquals(config.SSLPort, 0)
            def sighup_handler(num, frame):
                self.log_info("SIGHUP recieved at %s" % (location(frame),))

                # Reload the config file
                try:
                    config.reload()
                except ConfigurationError, e:
                    self.log_error("Invalid configuration: {0}".format(e))
    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 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 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 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 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 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 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 command_readConfig(self, command):
        """
        Return current configuration

        @param command: the dictionary parsed from the plist read from stdin
        @type command: C{dict}
        """
        config.reload()
        # config.Memcached.Pools.Default.ClientEnabled = False

        result = {}
        for keyPath in WRITABLE_CONFIG_KEYS:
            value = getKeyPath(config, keyPath)
            if value is not None:
                # Note: config contains utf-8 encoded strings, but plistlib
                # wants unicode, so decode here:
                if isinstance(value, str):
                    value = value.decode("utf-8")
                setKeyPath(result, keyPath, value)
        self.respond(command, result)
    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")
Beispiel #19
0
    def command_readConfig(self, command):
        """
        Return current configuration

        @param command: the dictionary parsed from the plist read from stdin
        @type command: C{dict}
        """
        config.reload()
        # config.Memcached.Pools.Default.ClientEnabled = False

        result = {}
        for keyPath in WRITABLE_CONFIG_KEYS:
            value = getKeyPath(config, keyPath)
            if value is not None:
                # Note: config contains utf-8 encoded strings, but plistlib
                # wants unicode, so decode here:
                if isinstance(value, str):
                    value = value.decode("utf-8")
                setKeyPath(result, keyPath, value)
        self.respond(command, result)
Beispiel #20
0
 def tearDown(self):
     config.setDefaults(DEFAULT_CONFIG)
     config.reload()
Beispiel #21
0
        @param command: the dictionary parsed from the plist read from stdin
        @type command: C{dict}
        """
        writable = WritableConfig(config, config.WritableConfigFile)
        writable.read()
        valuesToWrite = command.get("Values", {})
        # Note: values are unicode if they contain non-ascii
        for keyPath, value in flattenDictionary(valuesToWrite):
            if keyPath in WRITABLE_CONFIG_KEYS:
                writable.set(setKeyPath(ConfigDict(), keyPath, value))
        try:
            writable.save(restart=False)
        except Exception, e:
            respond(command, {"error": str(e)})
        else:
            config.reload()
            self.command_readConfig(command)


def setKeyPath(parent, keyPath, value):
    """
    Allows the setting of arbitrary nested dictionary keys via a single
    dot-separated string.  For example, setKeyPath(parent, "foo.bar.baz",
    "xyzzy") would create any intermediate missing directories (or whatever
    class parent is, such as ConfigDict) so that the following structure
    results:  parent = { "foo" : { "bar" : { "baz" : "xyzzy } } }

    @param parent: the object to modify
    @type parent: any dict-like object
    @param keyPath: a dot-delimited string specifying the path of keys to
        traverse
Beispiel #22
0
 def tearDown(self):
     config.setDefaults(DEFAULT_CONFIG)
     config.reload()
Beispiel #23
0
        @param command: the dictionary parsed from the plist read from stdin
        @type command: C{dict}
        """
        writable = WritableConfig(config, config.WritableConfigFile)
        writable.read()
        valuesToWrite = command.get("Values", {})
        # Note: values are unicode if they contain non-ascii
        for keyPath, value in flattenDictionary(valuesToWrite):
            if keyPath in WRITABLE_CONFIG_KEYS:
                writable.set(setKeyPath(ConfigDict(), keyPath, value))
        try:
            writable.save(restart=False)
        except Exception, e:
            respond(command, {"error": str(e)})
        else:
            config.reload()
            if not self.quiet:
                self.command_readConfig(command)



def setKeyPath(parent, keyPath, value):
    """
    Allows the setting of arbitrary nested dictionary keys via a single
    dot-separated string.  For example, setKeyPath(parent, "foo.bar.baz",
    "xyzzy") would create any intermediate missing directories (or whatever
    class parent is, such as ConfigDict) so that the following structure
    results:  parent = { "foo" : { "bar" : { "baz" : "xyzzy } } }

    @param parent: the object to modify
    @type parent: any dict-like object