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
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)
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
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