Add swarm config
This commit is contained in:
@@ -109,7 +109,7 @@ start_all() {
|
||||
test_ssh() {
|
||||
print_header "Testing SSH Connectivity"
|
||||
|
||||
local machines=("host" "machine1" "machine2" "machine3" "machine4")
|
||||
local machines=("swarm-manager" "swarm-worker1" "swarm-worker2" "swarm-worker3")
|
||||
local failed_machines=()
|
||||
|
||||
for machine in "${machines[@]}"; do
|
||||
@@ -231,6 +231,203 @@ run_tests() {
|
||||
test_results+=("Docker: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 7: Verify Docker Swarm is initialized
|
||||
print_info "Verifying Docker Swarm cluster..."
|
||||
if ansible swarm_managers -i inventory -m shell -a "docker node ls" >/dev/null 2>&1; then
|
||||
test_results+=("Swarm: ✅ PASS")
|
||||
else
|
||||
test_results+=("Swarm: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Display test results
|
||||
print_header "Test Results Summary"
|
||||
for result in "${test_results[@]}"; do
|
||||
echo " $result"
|
||||
done
|
||||
|
||||
# Count failures
|
||||
local failures=$(printf '%s\n' "${test_results[@]}" | grep -c "❌ FAIL" || true)
|
||||
|
||||
if [ "$failures" -eq 0 ]; then
|
||||
print_success "All tests passed! 🎉"
|
||||
return 0
|
||||
else
|
||||
print_error "$failures test(s) failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
echo "Reset and Test Script for Debian Vagrant Cluster"
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " full-reset Destroy everything and run full test cycle"
|
||||
echo " destroy-only Only destroy all machines"
|
||||
echo " start-only Only start all machines"
|
||||
echo " test-only Only run tests (assumes machines are running)"
|
||||
echo " ssh-test Only test SSH connectivity"
|
||||
echo " ansible-test Only test Ansible connectivity"
|
||||
echo " setup-only Only run setup playbook"
|
||||
echo " deploy-only Only run deployment playbook"
|
||||
echo " help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 full-reset # Complete destroy/recreate/test cycle"
|
||||
echo " $0 test-only # Run tests on existing machines"
|
||||
echo " $0 ssh-test # Quick SSH connectivity check"
|
||||
echo ""
|
||||
echo "This script will:"
|
||||
echo " 1. Check prerequisites (vagrant, ansible, make)"
|
||||
echo " 2. Destroy all VMs and clean up"
|
||||
echo " 3. Start all VMs fresh"
|
||||
echo " 4. Test SSH connectivity"
|
||||
echo " 5. Test Ansible connectivity"
|
||||
echo " 6. Run setup playbook (dependencies, swap)"
|
||||
echo " 7. Run deployment playbook (Docker, services)"
|
||||
echo " 8. Verify everything is working"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
main() {
|
||||
local command=${1:-help}
|
||||
|
||||
case "$command" in
|
||||
full-reset)
|
||||
print_header "Full Reset and Test Cycle"
|
||||
check_prerequisites
|
||||
destroy_all
|
||||
start_all
|
||||
run_tests
|
||||
;;
|
||||
destroy-only)
|
||||
print_header "Destroy Only"
|
||||
check_prerequisites
|
||||
destroy_all
|
||||
;;
|
||||
start-only)
|
||||
print_header "Start Only"
|
||||
check_prerequisites
|
||||
start_all
|
||||
;;
|
||||
test-only)
|
||||
print_header "Test Only"
|
||||
check_prerequisites
|
||||
run_tests
|
||||
;;
|
||||
ssh-test)
|
||||
print_header "SSH Test Only"
|
||||
check_prerequisites
|
||||
test_ssh
|
||||
;;
|
||||
ansible-test)
|
||||
print_header "Ansible Test Only"
|
||||
check_prerequisites
|
||||
test_ansible
|
||||
;;
|
||||
setup-only)
|
||||
print_header "Setup Only"
|
||||
check_prerequisites
|
||||
run_setup
|
||||
;;
|
||||
deploy-only)
|
||||
print_header "Deploy Only"
|
||||
check_prerequisites
|
||||
run_deployment
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown command: $command"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
else
|
||||
print_error "Setup playbook failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run deployment playbook
|
||||
run_deployment() {
|
||||
print_header "Running Deployment Playbook"
|
||||
|
||||
print_info "Deploying applications and services..."
|
||||
if ansible-playbook -i inventory deploy-playbook.yml; then
|
||||
print_success "Deployment playbook completed successfully"
|
||||
return 0
|
||||
else
|
||||
print_error "Deployment playbook failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run comprehensive tests
|
||||
run_tests() {
|
||||
print_header "Running Comprehensive Tests"
|
||||
|
||||
local test_results=()
|
||||
|
||||
# Test 1: SSH Connectivity
|
||||
if test_ssh; then
|
||||
test_results+=("SSH: ✅ PASS")
|
||||
else
|
||||
test_results+=("SSH: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 2: Ansible Connectivity
|
||||
if test_ansible; then
|
||||
test_results+=("Ansible: ✅ PASS")
|
||||
else
|
||||
test_results+=("Ansible: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 3: Setup Playbook
|
||||
if run_setup; then
|
||||
test_results+=("Setup: ✅ PASS")
|
||||
else
|
||||
test_results+=("Setup: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 4: Deployment Playbook
|
||||
if run_deployment; then
|
||||
test_results+=("Deployment: ✅ PASS")
|
||||
else
|
||||
test_results+=("Deployment: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 5: Verify swap is active
|
||||
print_info "Verifying swap is active..."
|
||||
if ansible all -i inventory -m shell -a "cat /proc/swaps" | grep -q "swapfile"; then
|
||||
test_results+=("Swap: ✅ PASS")
|
||||
else
|
||||
test_results+=("Swap: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 6: Verify Docker is running
|
||||
print_info "Verifying Docker is running..."
|
||||
if ansible all -i inventory -m shell -a "docker --version" >/dev/null 2>&1; then
|
||||
test_results+=("Docker: ✅ PASS")
|
||||
else
|
||||
test_results+=("Docker: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Test 7: Verify Docker Swarm is initialized
|
||||
print_info "Verifying Docker Swarm cluster..."
|
||||
if ansible swarm_managers -i inventory -m shell -a "docker node ls" >/dev/null 2>&1; then
|
||||
test_results+=("Swarm: ✅ PASS")
|
||||
else
|
||||
test_results+=("Swarm: ❌ FAIL")
|
||||
fi
|
||||
|
||||
# Display test results
|
||||
print_header "Test Results Summary"
|
||||
for result in "${test_results[@]}"; do
|
||||
|
||||
Reference in New Issue
Block a user