Support running the integration tests on an already running cluster
This commit is contained in:
@@ -5,6 +5,9 @@ import os
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from elasticsearch import Elasticsearch
|
||||||
|
from elasticsearch.exceptions import ConnectionError
|
||||||
|
|
||||||
from unittest import SkipTest
|
from unittest import SkipTest
|
||||||
|
|
||||||
data_dir = None
|
data_dir = None
|
||||||
@@ -27,10 +30,15 @@ server = None
|
|||||||
pidfile = tempfile.mktemp()
|
pidfile = tempfile.mktemp()
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
|
# no integration tests, skip starting the server
|
||||||
if 'YAML_TEST_DIR' not in os.environ:
|
if 'YAML_TEST_DIR' not in os.environ:
|
||||||
raise SkipTest('')
|
raise SkipTest('')
|
||||||
global server
|
global server
|
||||||
|
|
||||||
|
# use running ES instance, don't attempt to start our own
|
||||||
|
if 'TEST_ES_SERVER' in os.environ:
|
||||||
|
return
|
||||||
|
|
||||||
# check installed
|
# check installed
|
||||||
if subprocess.call('which vim >/dev/null 2>&1', shell=True) != 0:
|
if subprocess.call('which vim >/dev/null 2>&1', shell=True) != 0:
|
||||||
raise SkipTest("No Elasticsearch server, skipping integration tests.")
|
raise SkipTest("No Elasticsearch server, skipping integration tests.")
|
||||||
@@ -54,18 +62,17 @@ def setup():
|
|||||||
cmd = CMD % args
|
cmd = CMD % args
|
||||||
|
|
||||||
server = subprocess.Popen(cmd, shell=True)
|
server = subprocess.Popen(cmd, shell=True)
|
||||||
|
os.environ['TEST_ES_SERVER'] = 'localhost:%(port)s' % args
|
||||||
|
client = Elasticsearch([os.environ['TEST_ES_SERVER']])
|
||||||
|
|
||||||
# wait for green status
|
# wait for green status
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
response = None
|
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
try:
|
try:
|
||||||
response = requests.get('http://localhost:%(port)s/_cluster/health?wait_for_status=green' % args)
|
client.cluster.health(wait_for_status='yellow')
|
||||||
except requests.ConnectionError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
break
|
break
|
||||||
|
except ConnectionError:
|
||||||
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# timeout
|
# timeout
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class YamlTestCase(TestCase):
|
|||||||
return ES_VERSION
|
return ES_VERSION
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = Elasticsearch(['localhost:9900'])
|
self.client = Elasticsearch([environ['TEST_ES_SERVER']])
|
||||||
self.last_response = None
|
self.last_response = None
|
||||||
self._state = {}
|
self._state = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user