def check(self): """ Examine the routing configuration of the ``GridRouter`` and fail if it diverges from what's expected given the pods which currently exist. """ assume(self.service.running) # Advance the clock to make sure the router has had a chance to look # at the current state. self.clock.advance(self.interval) # GridRouter ought to have a mapping from the active subscription tub # identifiers to the internal addresses that own those tubs. mapping = self.service.route_mapping() expected = {} for pod, values in self.pods.iteritems(): (ip, storage_pem, storage_port, intro_pem, intro_port) = values expected[Tub(storage_pem).getTubID()] = (ip, storage_port) expected[Tub(intro_pem).getTubID()] = (ip, intro_port) self.case.assertThat( mapping, AfterPreprocessing( lambda m: { tub_id: address for (tub_id, (pod, address)) in m.iteritems() }, Equals(expected), ), )
def remote_reference(): tub = Tub() tub.setLocation("127.0.0.1:12345") url = tub.buildURL(b"efgh") # Ugh ugh ugh. Skip over the extra correctness checking in # RemoteReferenceTracker.__init__ that requires having a broker by passing # the url as None and setting it after. tracker = RemoteReferenceTracker(None, None, None, RIStub) tracker.url = url ref = RemoteReferenceOnly(tracker) return ref
def remove_pod(self, data): """ An existing customer grid pod goes away, as would happen if a user cancelled their subscription. """ assume(0 < len(self.pods)) pod, values = data.draw(sampled_from(sorted(self.pods.items()))) _, storage_pem, _, intro_pem, _ = values del self.pods[pod] self.used_tubs.difference_update({ Tub(storage_pem).getTubID(), Tub(intro_pem).getTubID(), }) self.case.successResultOf(self.client.delete(pod))
def create_pod(self, ip, storage_pem, storage_port, intro_pem, intro_port): """ A new customer grid pod shows up, as would happen if a new user just signed up and got provisioned. """ assume(storage_pem != intro_pem and Tub(storage_pem).getTubID() not in self.used_tubs and Tub(intro_pem).getTubID() not in self.used_tubs) details = SubscriptionDetails( bucketname=u"foo", # Set the node secrets. From these, tub identifiers can be # derived. oldsecrets={ # Storage server. u"server_node_pem": storage_pem, u"introducer_node_pem": intro_pem, }, customer_email=u"foo", customer_pgpinfo=u"foo", product_id=u"foo", customer_id=u"foo", subscription_id=u"foo", stripe_subscription_id=u"foo", introducer_port_number=intro_port, storage_port_number=storage_port, ) deployment = create_deployment( self.deploy_config, details, self.model, ) self.deployments.append(deployment) pod = derive_pod(self.model, deployment, ip) self.case.successResultOf(self.client.create(pod)) self.pods[pod] = (ip, storage_pem, storage_port, intro_pem, intro_port) self.used_tubs.update({ Tub(storage_pem).getTubID(), Tub(intro_pem).getTubID(), })
class EchoerFixture(Fixture): def __init__(self, reactor, tub_path): self.reactor = reactor self.tub = Tub() self.tub.setLocation(b"tcp:0") def _setUp(self): self.tub.startService() self.furl = self.tub.registerReference(Echoer()) def _cleanUp(self): return self.tub.stopService()
def storage_tub_id(self): return Tub(self.server_node_pem).getTubID().decode("ascii")
def introducer_tub_id(self): return Tub(self.introducer_node_pem).getTubID().decode("ascii")
def test_proxying(self): pems = node_pems() # Create client and server tubs we can use to speak Foolscap through # the proxy. This should demonstrate the proxy is working. client = Tub(pems.example()) client.startService() self.addCleanup(client.stopService) server = Tub(pems.example()) server.startService() self.addCleanup(server.stopService) # Get an arbitrary local address on which the server tub can listen. while True: server_socket = socket() try: server_socket.bind(("", 0)) except Exception as e: print(e) server_socket.close() else: server_socket.listen(1) self.addCleanup(server_socket.close) break server_address = server_socket.getsockname() msg("Got server address {}".format(server_address)) server_endpoint = AdoptedStreamServerEndpoint( self.reactor, server_socket.fileno(), AF_INET, ) server.listenOn(server_endpoint) # Get a grid router that knows where the server tub really is and so # should be able to proxy connections to it for us. grid_router = _GridRouterService(self.reactor) grid_router.set_route_mapping( freeze({ server.getTubID().decode("ascii"): (None, server_address), })) # Start the proxy listening. factory = grid_router.factory() d = TCP4ServerEndpoint(self.reactor, 0).listen(factory) def listening(proxy_port): self.addCleanup(proxy_port.stopListening) # Tell the server tub where the _proxy_ is it generates a furl # pointing at the proxy. We'll use that furl to connect with the # client tub and rely on the proxy to get us to the right place. host = proxy_port.getHost().host.decode("ascii") port_number = proxy_port.getHost().port location = u"{host}:{port}".format( host=host, port=port_number, ) server.setLocation(location.encode("ascii")) msg("Set server Tub location {}".format(location)) # Register something arbitrary that we can poke at. furl = server.registerReference(Referenceable()) # Try to connect to the server tub with the client tub through the # proxy. d = Deferred() reconn = client.connectTo(furl, d.callback) self.addCleanup(reconn.stopConnecting) return d d.addCallback(listening) def connected(ref): pass d.addCallback(connected) return d
def test_proxying(self): pems = node_pems() # Create client and server tubs we can use to speak Foolscap through # the proxy. This should demonstrate the proxy is working. client = Tub(pems.example()) client.startService() self.addCleanup(client.stopService) server = Tub(pems.example()) server.startService() self.addCleanup(server.stopService) # Get an arbitrary local address on which the server tub can listen. while True: server_socket = socket() try: server_socket.bind(("", 0)) except Exception as e: print(e) server_socket.close() else: server_socket.listen(1) self.addCleanup(server_socket.close) break server_address = server_socket.getsockname() msg("Got server address {}".format(server_address)) server_endpoint = AdoptedStreamServerEndpoint( self.reactor, server_socket.fileno(), AF_INET, ) server.listenOn(server_endpoint) # Get a grid router that knows where the server tub really is and so # should be able to proxy connections to it for us. grid_router = _GridRouterService(self.reactor) grid_router.set_route_mapping(freeze({ server.getTubID().decode("ascii"): (None, server_address), })) # Start the proxy listening. factory = grid_router.factory() d = TCP4ServerEndpoint(self.reactor, 0).listen(factory) def listening(proxy_port): self.addCleanup(proxy_port.stopListening) # Tell the server tub where the _proxy_ is it generates a furl # pointing at the proxy. We'll use that furl to connect with the # client tub and rely on the proxy to get us to the right place. host = proxy_port.getHost().host.decode("ascii") port_number = proxy_port.getHost().port location = u"{host}:{port}".format( host=host, port=port_number, ) server.setLocation(location.encode("ascii")) msg("Set server Tub location {}".format(location)) # Register something arbitrary that we can poke at. furl = server.registerReference(Referenceable()) # Try to connect to the server tub with the client tub through the # proxy. d = Deferred() reconn = client.connectTo(furl, d.callback) self.addCleanup(reconn.stopConnecting) return d d.addCallback(listening) def connected(ref): pass d.addCallback(connected) return d
def __init__(self, reactor, tub_path): self.reactor = reactor self.tub = Tub() self.tub.setLocation(b"tcp:0")