Skip to content

Commit e5a4383

Browse files
soedirgodarora
authored andcommitted
chore: fix flaky AMI test
1 parent 935d5f9 commit e5a4383

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

testinfra/test_ami.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import testinfra
99
from ec2instanceconnectcli.EC2InstanceConnectLogger import EC2InstanceConnectLogger
1010
from ec2instanceconnectcli.EC2InstanceConnectKey import EC2InstanceConnectKey
11+
from paramiko.ssh_exception import NoValidConnectionsError
1112
from time import sleep
1213

13-
RUN_ID = os.environ["GITHUB_RUN_ID"] if os.environ["GITHUB_RUN_ID"] else "unknown-ci-run"
14+
RUN_ID = os.environ.get("GITHUB_RUN_ID", "unknown-ci-run")
1415

1516
postgresql_schema_sql_content = """
1617
ALTER DATABASE postgres SET "app.settings.jwt_secret" TO 'my_jwt_secret_which_is_not_so_secret';
@@ -251,39 +252,43 @@ def gzip_then_base64_encode(s: str) -> str:
251252
)
252253

253254
def is_healthy(host) -> bool:
254-
cmd = host.run("pg_isready -U postgres")
255-
if cmd.failed is True:
256-
logger.warn("pg not ready")
257-
return False
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
258260

259-
cmd = host.run(f"curl -sf -k https://localhost:8085/health -H 'apikey: {supabase_admin_key}'")
260-
if cmd.failed is True:
261-
logger.warn("adminapi not ready")
262-
return False
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
263265

264-
cmd = host.run("curl -sf http://localhost:3001/ready")
265-
if cmd.failed is True:
266-
logger.warn("postgrest not ready")
267-
return False
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
268270

269-
cmd = host.run("curl -sf http://localhost:8081/health")
270-
if cmd.failed is True:
271-
logger.warn("gotrue not ready")
272-
return False
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
273275

274-
cmd = host.run("sudo kong health")
275-
if cmd.failed is True:
276-
logger.warn("kong not ready")
277-
return False
276+
cmd = host.run("sudo kong health")
277+
if cmd.failed is True:
278+
logger.warn("kong not ready")
279+
return False
278280

279-
cmd = host.run("printf \\\\0 > '/dev/tcp/localhost/6543'")
280-
if cmd.failed is True:
281-
logger.warn("pgbouncer not ready")
282-
return False
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
283285

284-
cmd = host.run("sudo fail2ban-client status")
285-
if cmd.failed is True:
286-
logger.warn("fail2ban not ready")
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")
287292
return False
288293

289294
return True

0 commit comments

Comments
 (0)