Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions testinfra/test_ami_nix.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,30 @@ def gzip_then_base64_encode(s: str) -> str:
instance.terminate()
raise TimeoutError("init.sh failed to complete within the timeout period")

# Create auth-failures.csv file if it doesn't exist (required for fail2ban to start)
# This matches what setup_fail2ban() does in the init script
logger.info("Ensuring PostgreSQL auth-failures.csv exists...")
result = run_ssh_command(
ssh,
"sudo mkdir -p /var/log/postgresql && sudo chown -R postgres:postgres /var/log/postgresql && sudo chmod 1775 /var/log/postgresql && sudo -u postgres touch /var/log/postgresql/auth-failures.csv && sudo chmod 0664 /var/log/postgresql/auth-failures.csv",
)
if not result["succeeded"]:
logger.warning(f"Failed to create auth-failures.csv: {result['stderr']}")

# Start fail2ban service before health checks
logger.info("Starting fail2ban service...")
result = run_ssh_command(ssh, "sudo systemctl start fail2ban.service")
if not result["succeeded"]:
logger.warning(f"Failed to start fail2ban: {result['stderr']}")
# Check fail2ban logs for more details
log_result = run_ssh_command(
ssh, "sudo journalctl -u fail2ban -n 20 --no-pager"
)
if log_result["succeeded"]:
logger.warning(f"fail2ban logs:\n{log_result['stdout']}")
else:
logger.info("fail2ban service started successfully")

def is_healthy(ssh) -> bool:
health_checks = [
("postgres", "sudo -u postgres /usr/bin/pg_isready -U postgres"),
Expand Down