Exemplo n.º 1
0
    def test_notifier(self):
        enabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
        enabledConfig.Notifications["Enabled"] = True
        notifier = Notifier(None, id="test")

        self.assertEquals(notifier._ids, {"default": "test"})
        clone = notifier.clone(label="alt", id="altID")
        self.assertEquals("altID", clone.getID(label="alt"))
        self.assertEquals(clone._ids, {
            "default" : "test",
            "alt"     : "altID",
        })
        self.assertEquals("test", notifier.getID())
        self.assertEquals(notifier._ids, {
            "default" : "test",
        })
        self.assertEquals(None, notifier.getID(label="notthere"))

        notifier = Notifier(None, id="urn:uuid:foo")
        self.assertEquals("foo", notifier.getID())

        notifier.disableNotify()
        self.assertEquals(notifier._notify, False)
        notifier.enableNotify(None)
        self.assertEquals(notifier._notify, True)
Exemplo n.º 2
0
    def test_sendHeartbeat(self):

        xmppConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
        xmppConfig.Notifications["Services"]["XMPPNotifier"]["Enabled"] = True
        xmppConfig.ServerHostName = "server.example.com"
        xmppConfig.HTTPPort = 80

        clock = Clock()
        xmlStream = StubXmlStream()
        settings = { "ServiceAddress" : "pubsub.example.com", "JID" : "jid",
            "Password" : "password", "KeepAliveSeconds" : 5,
            "NodeConfiguration" : { "pubsub#deliver_payloads" : "1" },
            "HeartbeatMinutes" : 30 }
        notifier = XMPPNotifier(settings, reactor=clock, heartbeat=True,
            roster=False, configOverride=xmppConfig)
        factory = XMPPNotificationFactory(notifier, settings, reactor=clock,
            keepAlive=False)
        factory.connected(xmlStream)
        factory.authenticated(xmlStream)

        self.assertEquals(len(xmlStream.elements), 1)
        heartbeat = xmlStream.elements[0]
        self.assertEquals(heartbeat.name, "iq")

        clock.advance(1800)

        self.assertEquals(len(xmlStream.elements), 2)
        heartbeat = xmlStream.elements[1]
        self.assertEquals(heartbeat.name, "iq")

        factory.disconnected(xmlStream)
        clock.advance(1800)
        self.assertEquals(len(xmlStream.elements), 2)
Exemplo n.º 3
0
    def test_clientNotifier(self):
        enabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
        enabledConfig.Notifications["Enabled"] = True
        resource = StubResource("test")
        subResource = StubResource("sub")
        clientNotifier = ClientNotifier(resource, configOverride=enabledConfig)

        self.assertEquals(clientNotifier.ids, {"default": (resource, None)})
        clone = clientNotifier.clone(subResource, label="alt", id="altID")
        self.assertEquals("altID", clone.getID(label="alt"))
        self.assertEquals(clone.ids, {
            "default" : (resource, None),
            "alt"     : (subResource, "altID"),
        })
        self.assertEquals("test", clientNotifier.getID())
        self.assertEquals(clientNotifier.ids, {
            "default" : (resource, "test"),
        })
        self.assertEquals(None, clientNotifier.getID(label="notthere"))

        resource = StubResource("urn:uuid:foo")
        clientNotifier = ClientNotifier(resource, configOverride=enabledConfig)
        self.assertEquals("foo", clientNotifier.getID())

        clientNotifier.disableNotify()
        self.assertEquals(clientNotifier._notify, False)
        clientNotifier.enableNotify(None)
        self.assertEquals(clientNotifier._notify, True)
def _addOther(conf, nodeid, nodeurl):
    
    # Read main plist
    try:
        cfg = Config(PListConfigProvider(DEFAULT_CONFIG))
        cfg.load(conf)
    except ConfigurationError:
        raise RuntimeError("Could not parse as plist: '%s'" % (conf,))

    # Read in the partitions plist
    partitionsPlist = cfg.Partitioning.PartitionConfigFile
    try:
        dataDict = readPlist(partitionsPlist)
    except (IOError, OSError):                                    
        raise RuntimeError("Partitions plist file does not exist or is inaccessible: %s" % (partitionsPlist,))

    # See if node id already exists
    if nodeid in [partition.get("uid", None) for partition in dataDict.get("partitions", ())]:
        raise RuntimeError("Node '%s' already in partitions plist '%s'" % (nodeid, partitionsPlist,))
    
    # Add new information and write it out
    dataDict.setdefault("partitions", []).append(
        {
            "uid": nodeid,
            "url": nodeurl,
        }
    )
    try:
        writePlist(dataDict, partitionsPlist)
    except (IOError, OSError):                                    
        raise RuntimeError("Could not write partitions plist: %s" % (partitionsPlist,))
Exemplo n.º 5
0
 def test_parseNonASCIIConfig(self):
     """
     Non-ASCII <string>s found as part of a configuration file will be
     retrieved as UTF-8 encoded 'str' objects, as parsed by
     L{NoUnicodePlistParser}.
     """
     cfg = Config(PListConfigProvider({"DataRoot": ""}))
     tempfile = FilePath(self.mktemp())
     tempfile.setContent(nonASCIIConfigPList)
     cfg.load(tempfile.path)
     self.assertEquals(cfg.DataRoot, nonASCIIValue)
Exemplo n.º 6
0
 def test_parseNonASCIIConfig(self):
     """
     Non-ASCII <string>s found as part of a configuration file will be
     retrieved as UTF-8 encoded 'str' objects, as parsed by
     L{NoUnicodePlistParser}.
     """
     cfg = Config(PListConfigProvider({"DataRoot": ""}))
     tempfile = FilePath(self.mktemp())
     tempfile.setContent(nonASCIIConfigPList)
     cfg.load(tempfile.path)
     self.assertEquals(cfg.DataRoot, nonASCIIValue)
Exemplo n.º 7
0
    def test_includes(self):

        plist1 = """
<plist version="1.0">
  <dict>
    <key>ServerRoot</key>
    <string>/root</string>
    <key>DocumentRoot</key>
    <string>defaultdoc</string>
    <key>DataRoot</key>
    <string>defaultdata</string>
    <key>ConfigRoot</key>
    <string>defaultconfig</string>
    <key>LogRoot</key>
    <string>defaultlog</string>
    <key>RunRoot</key>
    <string>defaultrun</string>
    <key>Includes</key>
    <array>
        <string>%s</string>
    </array>
  </dict>
</plist>
"""

        plist2 = """
<plist version="1.0">
  <dict>
    <key>DataRoot</key>
    <string>overridedata</string>
  </dict>
</plist>
"""

        tempfile2 = FilePath(self.mktemp())
        tempfile2.setContent(plist2)

        tempfile1 = FilePath(self.mktemp())
        tempfile1.setContent(plist1 % (tempfile2.path,))

        cfg = Config(PListConfigProvider({
            "ServerRoot": "",
            "DocumentRoot": "",
            "DataRoot": "",
            "ConfigRoot": "",
            "LogRoot": "",
            "RunRoot": "",
            "Includes": [],
        }))
        cfg.addPostUpdateHooks([_updateDataStore])
        cfg.load(tempfile1.path)
        self.assertEquals(cfg.DocumentRoot, "/root/overridedata/defaultdoc")
        self.assertEquals(cfg.DataRoot, "/root/overridedata")
Exemplo n.º 8
0
    def test_installNotificationClient(self):
        self.assertEquals(getNotificationClient(), None)
        self.clock = Clock()
        installNotificationClient(None, None,
            klass=StubNotificationClient, reactor=self.clock)
        notificationClient = getNotificationClient()
        self.assertNotEquals(notificationClient, None)

        enabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
        enabledConfig.Notifications["Enabled"] = True
        resource = StubResource("test")
        clientNotifier = ClientNotifier(resource, configOverride=enabledConfig)
        clientNotifier.notify()
        self.assertEquals(notificationClient.lines, ["test"])

        notificationClient.clear()
        clientNotifier = clientNotifier.clone(StubResource("sub"), label="alt")
        clientNotifier.notify()
        self.assertEquals(notificationClient.lines, ["test", "sub"])
Exemplo n.º 9
0
    def test_includes(self):

        plist1 = """
<plist version="1.0">
  <dict>
    <key>ServerRoot</key>
    <string>/root</string>
    <key>DocumentRoot</key>
    <string>defaultdoc</string>
    <key>DataRoot</key>
    <string>defaultdata</string>
    <key>ConfigRoot</key>
    <string>defaultconfig</string>
    <key>LogRoot</key>
    <string>defaultlog</string>
    <key>RunRoot</key>
    <string>defaultrun</string>
    <key>Includes</key>
    <array>
        <string>%s</string>
    </array>
  </dict>
</plist>
"""

        plist2 = """
<plist version="1.0">
  <dict>
    <key>DataRoot</key>
    <string>overridedata</string>
  </dict>
</plist>
"""

        tempfile2 = FilePath(self.mktemp())
        tempfile2.setContent(plist2)

        tempfile1 = FilePath(self.mktemp())
        tempfile1.setContent(plist1 % (tempfile2.path, ))

        cfg = Config(
            PListConfigProvider({
                "ServerRoot": "",
                "DocumentRoot": "",
                "DataRoot": "",
                "ConfigRoot": "",
                "LogRoot": "",
                "RunRoot": "",
                "Includes": [],
            }))
        cfg.addPostUpdateHooks([_updateDataStore])
        cfg.load(tempfile1.path)
        self.assertEquals(cfg.DocumentRoot, "/root/overridedata/defaultdoc")
        self.assertEquals(cfg.DataRoot, "/root/overridedata")
Exemplo n.º 10
0
 def test_relativeDefaultPaths(self):
     """
     The paths specified in the default configuration should be interpreted
     as relative to the paths specified in the configuration file.
     """
     cfg = Config(PListConfigProvider(
         {"AccountingLogRoot": "some-path",
          "LogRoot": "should-be-ignored"}))
     cfg.addPostUpdateHooks([_updateDataStore])
     tempfile = FilePath(self.mktemp())
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/some/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/some/root/some-path")
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/other/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/other/root/some-path")
Exemplo n.º 11
0
 def test_relativeDefaultPaths(self):
     """
     The paths specified in the default configuration should be interpreted
     as relative to the paths specified in the configuration file.
     """
     cfg = Config(PListConfigProvider(
         {"AccountingLogRoot": "some-path",
          "LogRoot": "should-be-ignored"}))
     cfg.addPostUpdateHooks([_updateDataStore])
     tempfile = FilePath(self.mktemp())
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/some/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/some/root/some-path")
     tempfile.setContent("<plist version='1.0'><dict>"
                         "<key>LogRoot</key><string>/other/root</string>"
                         "</dict></plist>")
     cfg.load(tempfile.path)
     self.assertEquals(cfg.AccountingLogRoot, "/other/root/some-path")