def _configure(self, config_yml, dockerArgs={}, dockerOnSocket=False): self.dockerAPI = TrafficLoggingFactory(testtools.FakeDockerServer(**dockerArgs), "docker-") if dockerOnSocket: self.socketPath = self.mktemp() self.dockerServer = reactor.listenUNIX(self.socketPath, self.dockerAPI) else: self.dockerServer = reactor.listenTCP(0, self.dockerAPI) self.dockerPort = self.dockerServer.getHost().port self.config = PluginConfiguration() tmp = self.mktemp() self.config._default_file = tmp fp = FilePath(tmp) fp.setContent(config_yml) self.parser = EndpointParser(self.config) if dockerOnSocket: self.proxyAPI = TrafficLoggingFactory(powerstrip.ServerProtocolFactory( dockerSocket=self.socketPath, config=self.config), "proxy-") else: self.proxyAPI = TrafficLoggingFactory( powerstrip.ServerProtocolFactory( dockerAddr="127.0.0.1", dockerPort=self.dockerPort, config=self.config), "proxy-") self.proxyServer = reactor.listenTCP(0, self.proxyAPI) self.proxyPort = self.proxyServer.getHost().port
def makeService(self, options): """ Create a service which will run a scram server. @param options: mapping of configuration """ from scram.network import ScramFactory from scram.world import (TCP_SERVICE_NAME, SCRAM_SERVICE_NAME, ScramService, World) from twisted.internet import reactor from twisted.application.service import MultiService from twisted.protocols.policies import TrafficLoggingFactory world = World(granularity=60, platformClock=reactor) service = MultiService() factory = ScramFactory(world) if options['log-directory'] is not None: factory = TrafficLoggingFactory( factory, join(options['log-directory'], 'scram')) tcp = TCPServer(options['port'], factory, interface='127.0.0.1') tcp.setName(TCP_SERVICE_NAME) tcp.setServiceParent(service) scram = ScramService(world) scram.setName(SCRAM_SERVICE_NAME) scram.setServiceParent(service) return service
def _getAdderTwo(self, *args, **kw): kw["incrementBy"] = 2 self.adderTwoAPI = TrafficLoggingFactory(AdderPlugin(*args, **kw), "adder2-") self.adderTwoServer = reactor.listenTCP(0, self.adderTwoAPI) self.adderTwoPort = self.adderTwoServer.getHost().port
def _getAdder(self, *args, **kw): self.adderAPI = TrafficLoggingFactory(AdderPlugin(*args, **kw), "adder-") self.adderServer = reactor.listenTCP(0, self.adderAPI) self.adderPort = self.adderServer.getHost().port