Skip to content

Commit f32610f

Browse files
committed
test: reorg and print logs while waiting continue on other checks when ready
1 parent 1184112 commit f32610f

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

testinfra/test_ami_nix.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,31 @@ def gzip_then_base64_encode(s: str) -> str:
346346
instance.terminate()
347347
raise TimeoutError("init.sh failed to complete within the timeout period")
348348

349+
<<<<<<< HEAD
349350
def is_healthy(ssh) -> bool:
351+
=======
352+
# Check PostgreSQL logs directory
353+
logger.info("Checking PostgreSQL logs directory:")
354+
result = host.run("sudo ls -la /var/log/postgresql/")
355+
logger.info(f"log directory contents:\n{result.stdout}\n{result.stderr}")
356+
357+
# Check any existing PostgreSQL logs
358+
logger.info("Checking existing PostgreSQL logs:")
359+
result = host.run("sudo cat /var/log/postgresql/*.log")
360+
logger.info(f"postgresql logs:\n{result.stdout}\n{result.stderr}")
361+
362+
# Check the startup log
363+
logger.info("PostgreSQL startup log:")
364+
result = host.run(f"sudo cat {startup_log}")
365+
logger.info(f"startup log contents:\n{result.stdout}\n{result.stderr}")
366+
367+
# Check PostgreSQL environment
368+
logger.info("PostgreSQL environment:")
369+
result = host.run("sudo -u postgres env | grep POSTGRES")
370+
logger.info(f"postgres environment:\n{result.stdout}\n{result.stderr}")
371+
372+
def is_healthy(host, instance_ip, ssh_identity_file) -> bool:
373+
>>>>>>> c2631e8c (test: reorg and print logs while waiting continue on other checks when ready)
350374
health_checks = [
351375
("postgres", "sudo -u postgres /usr/bin/pg_isready -U postgres"),
352376
("adminapi", f"curl -sf -k --connect-timeout 30 --max-time 60 https://localhost:8085/health -H 'apikey: {supabase_admin_key}'"),
@@ -367,18 +391,36 @@ def is_healthy(ssh) -> bool:
367391
logger.error(f"{service} stderr: {cmd.stderr}")
368392
=======
369393
if service == "postgres":
370-
# For PostgreSQL, we need to check multiple things
371394
pg_isready = check(host)
372395
>>>>>>> 65ef0692 (test: do not unpack result)
373396

374-
if pg_isready.failed:
375-
logger.error("PostgreSQL is not ready")
376-
logger.error(f"pg_isready stdout: {pg_isready.stdout}")
377-
logger.error(f"pg_isready stderr: {pg_isready.stderr}")
397+
# Always read and log the PostgreSQL logs first
398+
logger.warning("PostgreSQL status check:")
399+
try:
400+
# Read both .log and .csv files
401+
log_files = [
402+
"/var/log/postgresql/*.log",
403+
"/var/log/postgresql/*.csv"
404+
]
378405

379-
# Run detailed checks since we know we have a working connection
380-
run_detailed_checks(host)
381-
return False
406+
for log_pattern in log_files:
407+
log_result = host.run(f"sudo cat {log_pattern}")
408+
if not log_result.failed:
409+
logger.error(f"PostgreSQL logs from {log_pattern}:")
410+
logger.error(log_result.stdout)
411+
if log_result.stderr:
412+
logger.error(f"Log read errors: {log_result.stderr}")
413+
else:
414+
logger.error(f"Failed to read PostgreSQL logs from {log_pattern}: {log_result.stderr}")
415+
except Exception as e:
416+
logger.error(f"Error reading PostgreSQL logs: {str(e)}")
417+
418+
# Then check the status and return
419+
if not pg_isready.failed:
420+
continue
421+
# Wait before next attempt
422+
sleep(5)
423+
return False
382424
else:
383425
cmd = check(host)
384426
if cmd.failed is True:

0 commit comments

Comments
 (0)