55import os
66import pytest
77import requests
8+ import socket
89import testinfra
910from ec2instanceconnectcli .EC2InstanceConnectLogger import EC2InstanceConnectLogger
1011from ec2instanceconnectcli .EC2InstanceConnectKey import EC2InstanceConnectKey
11- from paramiko .ssh_exception import NoValidConnectionsError
1212from time import sleep
1313
1414RUN_ID = os .environ .get ("GITHUB_RUN_ID" , "unknown-ci-run" )
@@ -243,7 +243,18 @@ def gzip_then_base64_encode(s: str) -> str:
243243 assert response ["Success" ]
244244
245245 # 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 )
247258
248259 host = testinfra .get_host (
249260 # paramiko is an ssh backend
@@ -252,51 +263,46 @@ def gzip_then_base64_encode(s: str) -> str:
252263 )
253264
254265 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
260270
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
265275
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
270280
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
275285
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
280290
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
285295
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" )
292299 return False
293300
294301 return True
295302
296303 while True :
297304 if is_healthy (host ):
298305 break
299- print ("waiting until healthy" )
300306 sleep (1 )
301307
302308 # return a testinfra connection to the instance
0 commit comments