예제 #1
0
def get_client():
    global client
    if client is not None:
        return client

    # construct kwargs from the environment
    kw = {}
    if 'TEST_ES_CONNECTION' in os.environ:
        from elasticsearch import connection
        kw['connection_class'] = getattr(connection, os.environ['TEST_ES_CONNECTION'])

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        client = local_get_client([os.environ.get('TEST_ES_SERVER', {})], **kw)
    except ImportError:
        # fallback to using vanilla client
        client = Elasticsearch([os.environ.get('TEST_ES_SERVER', {})], **kw)

    # wait for yellow status
    for _ in range(100):
        time.sleep(.1)
        try:
            client.cluster.health(wait_for_status='yellow')
            return client
        except ConnectionError:
            continue
    else:
        # timeout
        raise SkipTest("Elasticsearch failed to start.")
예제 #2
0
def get_client():
    global client
    if client is not None:
        return client

    # construct kwargs from the environment
    kw = {}
    if 'TEST_ES_CONNECTION' in os.environ:
        from elasticsearch import connection
        kw['connection_class'] = getattr(connection,
                                         os.environ['TEST_ES_CONNECTION'])

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        client = local_get_client([os.environ.get('TEST_ES_SERVER', {})], **kw)
    except ImportError:
        # fallback to using vanilla client
        client = Elasticsearch([os.environ.get('TEST_ES_SERVER', {})], **kw)

    # wait for yellow status
    for _ in range(100):
        time.sleep(.1)
        try:
            client.cluster.health(wait_for_status='yellow')
            return client
        except ConnectionError:
            continue
    else:
        # timeout
        raise SkipTest("Elasticsearch failed to start.")
def get_client():
    global client
    if client is not None:
        return client

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        client = local_get_client()
    except ImportError:
        # fallback to using vanilla client
        client = get_test_client()

    return client
예제 #4
0
def get_client():
    global client
    if client is not None:
        return client

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client

        client = local_get_client()
    except ImportError:
        # fallback to using vanilla client
        client = get_test_client()

    return client
예제 #5
0
def get_client(**kwargs):
    # construct kwargs from the environment
    kw = {}
    if 'TEST_ES_CONNECTION' in os.environ:
        from elasticsearch import connection
        kw['connection_class'] = getattr(connection, os.environ['TEST_ES_CONNECTION'])
    # update them with params
    kw.update(kwargs)

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        return local_get_client([os.environ['TEST_ES_SERVER']], **kw)
    except ImportError:
        # fallback to using vanilla client
        return Elasticsearch([os.environ['TEST_ES_SERVER']], **kw)
예제 #6
0
def get_client(**kwargs):
    global client
    if client is not None and not kwargs:
        return client

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        new_client = local_get_client(**kwargs)
    except ImportError:
        # fallback to using vanilla client
        new_client = get_test_client(**kwargs)

    if not kwargs:
        client = new_client

    return new_client
예제 #7
0
def get_client(**kwargs):
    global client
    if client is not None and not kwargs:
        return client

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client
        new_client = local_get_client(**kwargs)
    except ImportError:
        # fallback to using vanilla client
        new_client = get_test_client(**kwargs)

    if not kwargs:
        client = new_client

    return new_client
예제 #8
0
def get_client(**kwargs):
    global client
    if client is False:
        raise SkipTest("No client is available")
    if client is not None and not kwargs:
        return client

    # try and locate manual override in the local environment
    try:
        from test_elasticsearch.local import get_client as local_get_client

        new_client = local_get_client(**kwargs)
    except ImportError:
        # fallback to using vanilla client
        try:
            new_client = test.get_test_client(**kwargs)
        except SkipTest:
            client = False
            raise

    if not kwargs:
        client = new_client

    return new_client