Example #1
0
    def setUp(self):
        """
        Shortcut by mocking all the helper functions that do IO.
        """
        self.authenticate_user = patch(self, 'otter.auth.authenticate_user')
        self.user_for_tenant = patch(self, 'otter.auth.user_for_tenant')
        self.impersonate_user = patch(self, 'otter.auth.impersonate_user')
        self.endpoints_for_token = patch(self,
                                         'otter.auth.endpoints_for_token')

        self.authenticate_user.return_value = succeed(
            {'access': {
                'token': {
                    'id': 'auth-token'
                }
            }})
        self.user_for_tenant.return_value = succeed('test_user')
        self.impersonate_user.return_value = succeed(
            {'access': {
                'token': {
                    'id': 'impersonation_token'
                }
            }})
        self.endpoints_for_token.return_value = succeed(
            {'endpoints': [{
                'name': 'anEndpoint',
                'type': 'anType'
            }]})

        self.url = 'http://identity/v2.0'
        self.admin_url = 'http://identity_admin/v2.0'
        self.user = '******'
        self.password = '******'
        self.ia = ImpersonatingAuthenticator(self.user, self.password,
                                             self.url, self.admin_url)
Example #2
0
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