Skip to content

Commit d38297c

Browse files
committed
fix app to run on non-win platforms (#153)
Also: - relax requirements removing the pyODBC dependency, if not performing tests; - swap trial-mode activation with password generation blocks, since the former is now password-protected. (cherry picked from commit b58692e)
1 parent 116897b commit d38297c

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

test/integration/elasticsearch.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,15 @@ def _start_elasticsearch(self, es_dir):
148148
start_script = os.path.join(es_dir, "bin", "elasticsearch")
149149
if os.name == "nt":
150150
start_script += ".bat"
151+
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
152+
else:
153+
creationflags = 0
151154

152155
if self.is_listening():
153156
raise Exception("an Elasticsearch instance is already running")
154157

155158
# don't daemonize to get the start logs inlined with those that this app generates
156-
es_proc = psutil.Popen(start_script, close_fds=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
159+
es_proc = psutil.Popen(start_script, close_fds=True, creationflags=creationflags)
157160
atexit.register(Elasticsearch._stop_es, es_proc)
158161
# it takes ES a few seconds to start: don't parse output, just wait till it's online
159162
waiting_since = time.time()
@@ -189,20 +192,6 @@ def _gen_passwords(self, es_dir):
189192
p.stderr.read()))
190193

191194
def _enable_xpack(self, es_dir):
192-
# start trial mode
193-
url = "http://localhost:%s/_license/start_trial?acknowledge=true" % self.ES_PORT
194-
failures = 0
195-
while True:
196-
req = requests.post(url)
197-
if req.status_code == 200:
198-
# TODO: check content?
199-
break
200-
print("starting of trial failed (#%s) with status: %s, text: %s" % (failures, req.status_code, req.text))
201-
failures += 1
202-
if self.ES_401_RETRIES < failures:
203-
raise Exception("starting of trial failed with status: %s, text: %s" % (req.status_code, req.text))
204-
time.sleep(.5)
205-
206195
# setup passwords to random generated ones first...
207196
pwd = self._gen_passwords(es_dir)
208197
# ...then change passwords, easier to restart with failed tests
@@ -216,6 +205,21 @@ def _enable_xpack(self, es_dir):
216205
if req.status_code != 200:
217206
print("ERROR: kibana user password change failed with code: %s" % req.status_code)
218207

208+
# start trial mode
209+
auth = ("elastic", self.AUTH_PASSWORD)
210+
url = "http://localhost:%s/_license/start_trial?acknowledge=true" % self.ES_PORT
211+
failures = 0
212+
while True:
213+
req = requests.post(url, auth=auth, timeout=self.REQ_TIMEOUT)
214+
if req.status_code == 200:
215+
# TODO: check content?
216+
break
217+
print("starting of trial failed (#%s) with status: %s, text: %s" % (failures, req.status_code, req.text))
218+
failures += 1
219+
if self.ES_401_RETRIES < failures:
220+
raise Exception("starting of trial failed with status: %s, text: %s" % (req.status_code, req.text))
221+
time.sleep(.5)
222+
219223
def spawn(self, version, root_dir=None, ephemeral=False):
220224
stage_dir = tempfile.mkdtemp(suffix=".ITES", dir=root_dir)
221225
if ephemeral:
@@ -260,7 +264,7 @@ def is_listening(password=None):
260264
auth = ("elastic", password) if password else None
261265
try:
262266
req = requests.get("http://localhost:%s" % Elasticsearch.ES_PORT, auth=auth, timeout=.5)
263-
except requests.Timeout:
267+
except (requests.Timeout, requests.ConnectionError):
264268
return False
265269
if req.status_code != 200:
266270
if password:

test/integration/testing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# you may not use this file except in compliance with the Elastic License.
55
#
66

7-
import pyodbc
87
import datetime
98
import hashlib
109
import unittest
@@ -31,6 +30,9 @@ def __init__(self, test_data, dsn=None):
3130
self._dsn = dsn if dsn else CONNECT_STRING
3231
print("Using DSN: '%s'." % self._dsn)
3332

33+
# only import pyODBC if running tests (vs. for instance only loading test data in ES)
34+
import pyodbc
35+
3436
def _reconstitute_csv(self, index_name):
3537
with pyodbc.connect(self._dsn) as cnxn:
3638
cnxn.autocommit = True

0 commit comments

Comments
 (0)