def test_wait_for_brokers(self): """ The L{Deferred} returned by L{Tub.stopService} fires only after the L{Broker} connections belonging to the L{Tub} have disconnected. """ tub = Tub() tub.startService() another_tub = Tub() another_tub.startService() brokers = list(tub.brokerClass(None) for i in range(3)) for n, b in enumerate(brokers): b.makeConnection(StringTransport()) ref = SturdyRef(encode_furl(another_tub.tubID, [], str(n))) tub.brokerAttached(ref, b, isClient=(n % 2) == 1) stopping = tub.stopService() d = flushEventualQueue() def event(ignored): self.assertNoResult(stopping) for b in brokers: b.connectionLost(failure.Failure(Exception("Connection lost"))) return flushEventualQueue() d.addCallback(event) def connectionsLost(ignored): self.successResultOf(stopping) d.addCallback(connectionsLost) return d
def test_wait_for_brokers(self): """ The L{Deferred} returned by L{Tub.stopService} fires only after the L{Broker} connections belonging to the L{Tub} have disconnected. """ tub = Tub() tub.startService() another_tub = Tub() another_tub.startService() brokers = list(tub.brokerClass(None) for i in range(3)) for n, b in enumerate(brokers): b.makeConnection(StringTransport()) ref = SturdyRef(encode_furl(another_tub.tubID, [], str(n))) tub.brokerAttached(ref, b, isClient=(n % 2)==1) stopping = tub.stopService() d = flushEventualQueue() def event(ignored): self.assertNoResult(stopping) for b in brokers: b.connectionLost(failure.Failure(Exception("Connection lost"))) return flushEventualQueue() d.addCallback(event) def connectionsLost(ignored): self.successResultOf(stopping) d.addCallback(connectionsLost) return d
def _introduce(adave): # The third way is to mangle the location hints, which will # result in a failure during negotiation as it attempts to # establish a TCP connection. (tubid, location_hints, name) = decode_furl(adave.tracker.url) # highly unlikely that there's anything listening on this port location_hints = ["tcp:127.0.0.1:2"] adave.tracker.url = encode_furl(tubid, location_hints, name) return self.shouldFail(ConnectionRefusedError, "Bad.test_location", "Connection was refused by other side", self.acarol.callRemote, "set", adave)
def _introduce(adave): # The second way is to mangle the tubid, which will result in a # failure during negotiation. We mangle it by reversing the # characters: this makes it syntactically valid but highly # unlikely to remain the same. NOTE: this will have to change # when we modify the way gifts are referenced, since tracker.url # is scheduled to go away. (tubid, location_hints, name) = decode_furl(adave.tracker.url) tubid = "".join(reversed(tubid)) adave.tracker.url = encode_furl(tubid, location_hints, name) return self.shouldFail(BananaError, "Bad.test_tubid", "unknown TubID", self.acarol.callRemote, "set", adave)
def furls(): # XXX Not well factored probably. return strategies.builds( lambda pem, addr, port, swissnum: encode_furl( Tub(pem).getTubID(), ["{}:{}".format(addr, port)], swissnum, ), node_pems(), ipv4_addresses(), port_number(), swissnum(), )
def _introduce(adave): # The next form of mangling is to connect to a port which never # responds, which could happen if a firewall were silently # dropping the TCP packets. We can't accurately simulate this # case, but we can connect to a port which accepts the connection # and then stays silent. This should trigger the overall # connection timeout. (tubid, location_hints, name) = decode_furl(adave.tracker.url) location_hints = ["tcp:127.0.0.1:%d" % p.getHost().port] adave.tracker.url = encode_furl(tubid, location_hints, name) self.tubD._test_options['connect_timeout'] = 2 return self.shouldFail(NegotiationError, "Bad.test_hang", "no connection established within client timeout", self.acarol.callRemote, "set", adave)
def _introduce(adave): # The next form of mangling is to connect to a port which never # responds, which could happen if a firewall were silently # dropping the TCP packets. We can't accurately simulate this # case, but we can connect to a port which accepts the connection # and then stays silent. This should trigger the overall # connection timeout. (tubid, location_hints, name) = decode_furl(adave.tracker.url) location_hints = ["tcp:127.0.0.1:%d" % p.getHost().port] adave.tracker.url = encode_furl(tubid, location_hints, name) self.tubD._test_options['connect_timeout'] = 2 return self.shouldFail( NegotiationError, "Bad.test_hang", "no connection established within client timeout", self.acarol.callRemote, "set", adave)
def make_external_furl(internal_furl, publichost, port): tub_id, location_hints, name = decode_furl(internal_furl) location_hints[:] = [u"{}:{}".format(publichost, port).encode("ascii")] return encode_furl(tub_id, location_hints, name)
def test_complete(self, introducer_config, storage_config): """ Introducer and storage configuration can be supplied via ``configure_tahoe``. """ introducer_furl = introducer_config["introducer_furl"] config = marshal_tahoe_configuration( introducer_pem=introducer_config["node_pem"], storage_pem=storage_config["node_pem"], storage_privkey=storage_config["node_privkey"], introducer_port=introducer_config["port"], storageserver_port=storage_config["port"], bucket_name=storage_config["bucket_name"], key_prefix=storage_config["key_prefix"], publichost=storage_config["publichost"], privatehost=storage_config["privatehost"], introducer_furl=introducer_furl, s3_access_key_id=storage_config["s3_access_key_id"], s3_secret_key=storage_config["s3_secret_key"], log_gatherer_furl=introducer_config["log_gatherer_furl"], stats_gatherer_furl=introducer_config["stats_gatherer_furl"], ) configure_tahoe({"introducer": config["introducer"]}, self.nodes.introducer.path) configure_tahoe({"storage": config["storage"]}, self.nodes.storage.path) intro_config_path = self.nodes.introducer.child(b"tahoe.cfg") storage_config_path = self.nodes.storage.child(b"tahoe.cfg") config_files = [intro_config_path, storage_config_path] # If the log and stats gatherers are given, the storage and # introducer configurations are written with those values for # those fields. self.expectThat( config_files, AllMatch( hasConfiguration({ ("node", "log_gatherer.furl", introducer_config["log_gatherer_furl"]), ("client", "stats_gatherer.furl", introducer_config["stats_gatherer_furl"]), }))) # The introducer furl in the introducer configuration is # written to the ``private/introducer.furl`` file in the # introducer's state/configuration directory and to the # storage node's configuration file. self.expectThat( self.nodes.introducer.descendant([b"private", b"introducer.furl"]), hasContents(introducer_furl), ) tub_id, location_hints, name = decode_furl(introducer_furl) port = location_hints[0].split(":")[1] location_hints[:0] = [storage_config["privatehost"] + ":" + port] internal_introducer_furl = encode_furl(tub_id, location_hints, name) self.expectThat( storage_config_path, hasConfiguration({ ("client", "introducer.furl", internal_introducer_furl), }), ) self.expectThat( self.nodes.storage.child(b"announcement-seqnum"), hasContentsMatching( # The second hand could click over between when the file is # written and when this test code runs. In fact, it could # click over multiple times... But the only way to really fix # that is to parameterize the clock and the structure of # configure_tahoe makes that tricky. So just suppose that one # second is all the leeway we need to make this reliable. AfterPreprocessing(int, Not(LessThan(int(time() - 1)))), ), )
def add(config): num = config.pop(swissnum) tubID = Tub(config["node_pem"]).getTubID() config[target] = encode_furl(tubID, ["127.0.0.1:12345"], num) return config
def test_complete(self, introducer_config, storage_config): """ Introducer and storage configuration can be supplied via ``configure_tahoe``. """ introducer_furl = introducer_config["introducer_furl"] config = marshal_tahoe_configuration( introducer_pem=introducer_config["node_pem"], storage_pem=storage_config["node_pem"], storage_privkey=storage_config["node_privkey"], introducer_port=introducer_config["port"], storageserver_port=storage_config["port"], bucket_name=storage_config["bucket_name"], publichost=storage_config["publichost"], privatehost=storage_config["privatehost"], introducer_furl=introducer_furl, s3_access_key_id=storage_config["s3_access_key_id"], s3_secret_key=storage_config["s3_secret_key"], log_gatherer_furl=introducer_config["log_gatherer_furl"], stats_gatherer_furl=introducer_config["stats_gatherer_furl"], ) configure_tahoe({"introducer": config["introducer"]}, self.nodes.introducer.path) configure_tahoe({"storage": config["storage"]}, self.nodes.storage.path) intro_config_path = self.nodes.introducer.child(b"tahoe.cfg") storage_config_path = self.nodes.storage.child(b"tahoe.cfg") config_files = [intro_config_path, storage_config_path] # If the log and stats gatherers are given, the storage and # introducer configurations are written with those values for # those fields. self.expectThat( config_files, AllMatch( hasConfiguration({ ("node", "log_gatherer.furl", introducer_config["log_gatherer_furl"]), ("client", "stats_gatherer.furl", introducer_config["stats_gatherer_furl"]), }))) # The introducer furl in the introducer configuration is # written to the ``private/introducer.furl`` file in the # introducer's state/configuration directory and to the # storage node's configuration file. self.expectThat( self.nodes.introducer.descendant([b"private", b"introducer.furl"]), hasContents(introducer_furl), ) tub_id, location_hints, name = decode_furl(introducer_furl) port = location_hints[0].split(":")[1] location_hints[:0] = [storage_config["privatehost"] + ":" + port] internal_introducer_furl = encode_furl(tub_id, location_hints, name) self.expectThat( storage_config_path, hasConfiguration({ ("client", "introducer.furl", internal_introducer_furl), }), )