From a0cab9ac6e60115979e49789addb061ae63e5358 Mon Sep 17 00:00:00 2001 From: Sprite Date: Sun, 8 Feb 2026 02:01:53 +0000 Subject: [PATCH] refactor: use generic_ssh_wait in AWS Lightsail verify_server_connectivity - Replace 13 lines of duplicate SSH waiting logic - Call generic_ssh_wait() with ubuntu username - Improves maintainability and reduces code duplication Score: 14 (Impact: 7, Confidence: 8, Risk: 4) --- aws-lightsail/lib/common.sh | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/aws-lightsail/lib/common.sh b/aws-lightsail/lib/common.sh index 5f08293a..f61bf545 100644 --- a/aws-lightsail/lib/common.sh +++ b/aws-lightsail/lib/common.sh @@ -133,17 +133,10 @@ create_server() { } verify_server_connectivity() { - local ip="${1}" max_attempts=${2:-30} attempt=1 - log_warn "Waiting for SSH connectivity to ${ip}..." - while [[ ${attempt} -le ${max_attempts} ]]; do - # SSH_OPTS is defined in shared/common.sh - # shellcheck disable=SC2154,SC2086 - if ssh ${SSH_OPTS} -o ConnectTimeout=5 "ubuntu@${ip}" "echo ok" >/dev/null 2>&1; then - log_info "SSH connection established"; return 0 - fi - log_warn "Waiting for SSH... (${attempt}/${max_attempts})"; sleep 5; attempt=$((attempt + 1)) - done - log_error "Server failed to respond via SSH after ${max_attempts} attempts"; return 1 + local ip="${1}" max_attempts=${2:-30} + # Use shared generic_ssh_wait with exponential backoff + # shellcheck disable=SC2086,SC2154 + generic_ssh_wait "ubuntu" "${ip}" "${SSH_OPTS}" "echo ok" "SSH connectivity" "${max_attempts}" } wait_for_cloud_init() {