@@ -338,16 +338,6 @@ def gzip_then_base64_encode(s: str) -> str:
338
338
except Exception as e :
339
339
logger .warning (f"Error checking init.sh status: { str (e )} " )
340
340
341
- # Capture logs during initialization
342
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 --no-pager' )
343
- logger .info (f"PostgreSQL service logs during initialization:\n { result ['stdout' ]} " )
344
-
345
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 | grep -i "prestart"' )
346
- logger .info (f"Prestart script execution logs during initialization:\n { result ['stdout' ]} " )
347
-
348
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 | grep -i "switch_pg_cron_version"' )
349
- logger .info (f"Version switcher execution logs during initialization:\n { result ['stdout' ]} " )
350
-
351
341
attempt += 1
352
342
logger .warning (f"Waiting for init.sh to complete (attempt { attempt } /{ max_attempts } )" )
353
343
sleep (5 )
@@ -386,18 +376,6 @@ def is_healthy(ssh) -> bool:
386
376
("fail2ban" , "sudo fail2ban-client status" ),
387
377
]
388
378
389
- # Capture systemd logs during startup
390
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 --no-pager' )
391
- logger .info (f"PostgreSQL service logs during startup:\n { result ['stdout' ]} " )
392
-
393
- # Check prestart script execution
394
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 | grep -i "prestart"' )
395
- logger .info (f"Prestart script execution logs:\n { result ['stdout' ]} " )
396
-
397
- # Check version switcher execution
398
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 | grep -i "switch_pg_cron_version"' )
399
- logger .info (f"Version switcher execution logs:\n { result ['stdout' ]} " )
400
-
401
379
service_status = {}
402
380
for service , command in health_checks :
403
381
try :
@@ -605,12 +583,12 @@ def test_pg_cron_extension(host):
605
583
ssh = host ['ssh' ]
606
584
607
585
# Check prestart script
608
- result = run_ssh_command (ssh , 'ls -l /usr/local/bin /postgres_prestart.sh' )
586
+ result = run_ssh_command (ssh , 'ls -l /etc/postgresql/prestart.d /postgres_prestart.sh' )
609
587
assert result ['succeeded' ], f"Failed to find prestart script: { result ['stderr' ]} "
610
588
logger .info (f"Prestart script details: { result ['stdout' ]} " )
611
589
612
590
# Check if extensions file exists
613
- result = run_ssh_command (ssh , 'sudo cat /root/pg_extensions.json' )
591
+ result = run_ssh_command (ssh , 'cat /root/pg_extensions.json' )
614
592
assert result ['succeeded' ], f"Failed to read extensions file: { result ['stderr' ]} "
615
593
logger .info (f"Extensions file contents: { result ['stdout' ]} " )
616
594
@@ -619,71 +597,6 @@ def test_pg_cron_extension(host):
619
597
assert result ['succeeded' ], f"Failed to find version switcher: { result ['stderr' ]} "
620
598
logger .info (f"Version switcher details: { result ['stdout' ]} " )
621
599
622
- # Check if version switching worked correctly
623
- result = run_ssh_command (ssh , 'ls -l /var/lib/postgresql/.nix-profile/lib/pg_cron.so' )
624
- logger .info (f"Current pg_cron library symlink: { result ['stdout' ]} " )
625
- assert "pg_cron-1.3.1" in result ['stdout' ], "pg_cron library not pointing to version 1.3.1"
626
-
627
- # Check the actual symlink target
628
- result = run_ssh_command (ssh , 'readlink -f /var/lib/postgresql/.nix-profile/lib/pg_cron.so' )
629
- logger .info (f"Actual pg_cron library symlink target: { result ['stdout' ]} " )
630
-
631
- # List all available pg_cron versions
632
- result = run_ssh_command (ssh , 'ls -l /var/lib/postgresql/.nix-profile/lib/pg_cron-*' )
633
- logger .info (f"Available pg_cron versions: { result ['stdout' ]} " )
634
-
635
- # Check if the target version exists
636
- result = run_ssh_command (ssh , 'ls -l /var/lib/postgresql/.nix-profile/lib/pg_cron-1.3.1.so' )
637
- logger .info (f"Target version exists: { result ['stdout' ]} " )
638
-
639
- result = run_ssh_command (ssh , 'cat /var/lib/postgresql/.nix-profile/share/postgresql/extension/pg_cron.control' )
640
- logger .info (f"pg_cron control file contents: { result ['stdout' ]} " )
641
- assert "default_version = '1.3.1'" in result ['stdout' ], "pg_cron control file not set to version 1.3.1"
642
-
643
- # Check prestart script execution
644
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 50 | grep -i "prestart"' )
645
- logger .info (f"Prestart script execution logs: { result ['stdout' ]} " )
646
-
647
- # Check systemd service status to see if prestart was attempted
648
- result = run_ssh_command (ssh , 'sudo systemctl status postgresql@main' )
649
- logger .info (f"PostgreSQL service status: { result ['stdout' ]} " )
650
-
651
- # Check if prestart script exists and is executable
652
- result = run_ssh_command (ssh , 'ls -l /usr/local/bin/postgres_prestart.sh' )
653
- logger .info (f"Prestart script permissions: { result ['stdout' ]} " )
654
-
655
- # Check prestart script contents
656
- result = run_ssh_command (ssh , 'sudo cat /usr/local/bin/postgres_prestart.sh' )
657
- logger .info (f"Prestart script contents: { result ['stdout' ]} " )
658
-
659
- # Check pg_cron worker process
660
- result = run_ssh_command (ssh , 'ps aux | grep -i "pg_cron"' )
661
- logger .info (f"pg_cron worker processes: { result ['stdout' ]} " )
662
-
663
- # Check PostgreSQL logs for any errors
664
- result = run_ssh_command (ssh , 'sudo tail -n 100 /var/log/postgresql/postgresql.csv' )
665
- logger .info (f"PostgreSQL logs: { result ['stdout' ]} " )
666
-
667
- # Check if version switcher was executed
668
- result = run_ssh_command (ssh , 'sudo ls -l /var/lib/postgresql/.nix-profile/lib/pg_cron-*' )
669
- logger .info (f"Available pg_cron versions: { result ['stdout' ]} " )
670
-
671
- # Check if version switcher has execute permissions
672
- result = run_ssh_command (ssh , 'ls -l /var/lib/postgresql/.nix-profile/bin/switch_pg_cron_version' )
673
- logger .info (f"Version switcher permissions: { result ['stdout' ]} " )
674
-
675
- # Check if version switcher was called by prestart
676
- result = run_ssh_command (ssh , 'sudo grep -r "switch_pg_cron_version" /var/log/postgresql/' )
677
- logger .info (f"Version switcher execution logs: { result ['stdout' ]} " )
678
-
679
- # Check systemd service file to verify prestart configuration
680
- result = run_ssh_command (ssh , 'sudo cat /etc/systemd/system/postgresql@.service' )
681
- logger .info (f"PostgreSQL service file: { result ['stdout' ]} " )
682
-
683
- # Check if prestart script was called by systemd
684
- result = run_ssh_command (ssh , 'sudo journalctl -u postgresql@main -n 100 | grep -i "executing"' )
685
- logger .info (f"Systemd execution logs: { result ['stdout' ]} " )
686
-
687
600
# Create the extension
688
601
result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "CREATE EXTENSION pg_cron WITH SCHEMA pg_catalog VERSION \' 1.3.1\' ;"' )
689
602
assert result ['succeeded' ], f"Failed to create pg_cron extension: { result ['stderr' ]} "
@@ -695,7 +608,7 @@ def test_pg_cron_extension(host):
695
608
logger .info (f"pg_cron version: { result ['stdout' ]} " )
696
609
697
610
# Check the actual function definition
698
- result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\\ sf cron.schedule"' )
611
+ result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\sf cron.schedule"' )
699
612
assert result ['succeeded' ], f"Failed to get cron.schedule function definition: { result ['stderr' ]} "
700
613
logger .info (f"cron.schedule function definition: { result ['stdout' ]} " )
701
614
@@ -709,12 +622,12 @@ def test_pg_cron_extension(host):
709
622
assert result ['succeeded' ], f"Failed to create test table: { result ['stderr' ]} "
710
623
711
624
# Check the schema of cron.job table
712
- result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\\ d cron.job"' )
625
+ result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\d cron.job"' )
713
626
assert result ['succeeded' ], f"Failed to get cron.job schema: { result ['stderr' ]} "
714
627
logger .info (f"cron.job schema: { result ['stdout' ]} " )
715
628
716
629
# Check available cron functions
717
- result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\\ df cron.*"' )
630
+ result = run_ssh_command (ssh , 'sudo -u postgres psql -d postgres -c "\df cron.*"' )
718
631
assert result ['succeeded' ], f"Failed to get cron functions: { result ['stderr' ]} "
719
632
logger .info (f"Available cron functions: { result ['stdout' ]} " )
720
633
@@ -730,3 +643,4 @@ def test_pg_cron_extension(host):
730
643
assert "INSERT INTO cron_test_log" in result ['stdout' ], "Expected cron command"
731
644
assert "postgres" in result ['stdout' ], "Expected postgres username"
732
645
assert "postgres" in result ['stdout' ], "Expected postgres database"
646
+
0 commit comments