@@ -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 :
0 commit comments