5
5
import os
6
6
import pytest
7
7
import requests
8
+ import socket
8
9
import testinfra
9
10
from ec2instanceconnectcli .EC2InstanceConnectLogger import EC2InstanceConnectLogger
10
11
from ec2instanceconnectcli .EC2InstanceConnectKey import EC2InstanceConnectKey
11
- from paramiko .ssh_exception import NoValidConnectionsError
12
12
from time import sleep
13
13
14
14
RUN_ID = os .environ .get ("GITHUB_RUN_ID" , "unknown-ci-run" )
@@ -243,7 +243,18 @@ def gzip_then_base64_encode(s: str) -> str:
243
243
assert response ["Success" ]
244
244
245
245
# instance doesn't have public ip yet
246
- instance .reload ()
246
+ while not instance .public_ip_address :
247
+ logger .warning ("waiting for ip to be available" )
248
+ sleep (5 )
249
+ instance .reload ()
250
+
251
+ while True :
252
+ sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
253
+ if sock .connect_ex ((instance .public_ip_address , 22 )) == 0 :
254
+ break
255
+ else :
256
+ logger .warning ("waiting for ssh to be available" )
257
+ sleep (10 )
247
258
248
259
host = testinfra .get_host (
249
260
# paramiko is an ssh backend
@@ -252,51 +263,46 @@ def gzip_then_base64_encode(s: str) -> str:
252
263
)
253
264
254
265
def is_healthy (host ) -> bool :
255
- try :
256
- cmd = host .run ("pg_isready -U postgres" )
257
- if cmd .failed is True :
258
- logger .warn ("pg not ready" )
259
- return False
266
+ cmd = host .run ("pg_isready -U postgres" )
267
+ if cmd .failed is True :
268
+ logger .warning ("pg not ready" )
269
+ return False
260
270
261
- cmd = host .run (f"curl -sf -k https://localhost:8085/health -H 'apikey: { supabase_admin_key } '" )
262
- if cmd .failed is True :
263
- logger .warn ("adminapi not ready" )
264
- return False
271
+ cmd = host .run (f"curl -sf -k https://localhost:8085/health -H 'apikey: { supabase_admin_key } '" )
272
+ if cmd .failed is True :
273
+ logger .warning ("adminapi not ready" )
274
+ return False
265
275
266
- cmd = host .run ("curl -sf http://localhost:3001/ready" )
267
- if cmd .failed is True :
268
- logger .warn ("postgrest not ready" )
269
- return False
276
+ cmd = host .run ("curl -sf http://localhost:3001/ready" )
277
+ if cmd .failed is True :
278
+ logger .warning ("postgrest not ready" )
279
+ return False
270
280
271
- cmd = host .run ("curl -sf http://localhost:8081/health" )
272
- if cmd .failed is True :
273
- logger .warn ("gotrue not ready" )
274
- return False
281
+ cmd = host .run ("curl -sf http://localhost:8081/health" )
282
+ if cmd .failed is True :
283
+ logger .warning ("gotrue not ready" )
284
+ return False
275
285
276
- cmd = host .run ("sudo kong health" )
277
- if cmd .failed is True :
278
- logger .warn ("kong not ready" )
279
- return False
286
+ cmd = host .run ("sudo kong health" )
287
+ if cmd .failed is True :
288
+ logger .warning ("kong not ready" )
289
+ return False
280
290
281
- cmd = host .run ("printf \\ \\ 0 > '/dev/tcp/localhost/6543'" )
282
- if cmd .failed is True :
283
- logger .warn ("pgbouncer not ready" )
284
- return False
291
+ cmd = host .run ("printf \\ \\ 0 > '/dev/tcp/localhost/6543'" )
292
+ if cmd .failed is True :
293
+ logger .warning ("pgbouncer not ready" )
294
+ return False
285
295
286
- cmd = host .run ("sudo fail2ban-client status" )
287
- if cmd .failed is True :
288
- logger .warn ("fail2ban not ready" )
289
- return False
290
- except NoValidConnectionsError :
291
- logger .warn ("unable to connect via ssh" )
296
+ cmd = host .run ("sudo fail2ban-client status" )
297
+ if cmd .failed is True :
298
+ logger .warning ("fail2ban not ready" )
292
299
return False
293
300
294
301
return True
295
302
296
303
while True :
297
304
if is_healthy (host ):
298
305
break
299
- print ("waiting until healthy" )
300
306
sleep (1 )
301
307
302
308
# return a testinfra connection to the instance
0 commit comments