def makeService(config): """ Set up the otter-api service. """ set_config_data(dict(config)) if not config_value('mock'): seed_endpoints = [ clientFromString(reactor, str(host)) for host in config_value('cassandra.seed_hosts') ] cassandra_cluster = LoggingCQLClient( RoundRobinCassandraCluster(seed_endpoints, config_value('cassandra.keyspace')), log.bind(system='otter.silverberg')) set_store(CassScalingGroupCollection(cassandra_cluster)) bobby_url = config_value('bobby_url') if bobby_url is not None: set_bobby(BobbyClient(bobby_url)) cache_ttl = config_value('identity.cache_ttl') if cache_ttl is None: # FIXME: Pick an arbitrary cache ttl value based on absolutely no # science. cache_ttl = 300 authenticator = CachingAuthenticator( reactor, ImpersonatingAuthenticator(config_value('identity.username'), config_value('identity.password'), config_value('identity.url'), config_value('identity.admin_url')), cache_ttl) supervisor = Supervisor(authenticator.authenticate_tenant, coiterate) set_supervisor(supervisor) s = MultiService() site = Site(root) site.displayTracebacks = False api_service = service(str(config_value('port')), site) api_service.setServiceParent(s) if config_value('scheduler') and not config_value('mock'): scheduler_service = SchedulerService( int(config_value('scheduler.batchsize')), int(config_value('scheduler.interval')), cassandra_cluster) scheduler_service.setServiceParent(s) return s
def setUp(self): """ Configure a clock and a fake auth function. """ self.authenticator = iMock(IAuthenticator) def authenticate_tenant(tenant_id): return succeed(('auth-token', 'catalog')) self.authenticator.authenticate_tenant.side_effect = authenticate_tenant self.auth_function = self.authenticator.authenticate_tenant self.clock = Clock() self.ca = CachingAuthenticator(self.clock, self.authenticator, 10)
def setUp(self): """ Configure a clock and a fake auth function. """ self.result = ('auth-token', 'catalog') self.resps = {1: self.result} class FakeAuthenticator(object): def authenticate_tenant(fself, tenant_id, log=None): r = self.resps[tenant_id] if isinstance(r, Deferred): return r return fail(r) if isinstance(r, Exception) else succeed(r) self.clock = Clock() self.ca = CachingAuthenticator(self.clock, FakeAuthenticator(), 10)