docker-test-helper.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/bash
  2. # Docker Test Helper - Simplified commands for running integration tests
  3. set -e
  4. # Colors
  5. RED='\033[0;31m'
  6. GREEN='\033[0;32m'
  7. YELLOW='\033[1;33m'
  8. BLUE='\033[0;34m'
  9. NC='\033[0m'
  10. print_usage() {
  11. echo -e "${BLUE}SeaweedFS RDMA Docker Integration Test Helper${NC}"
  12. echo ""
  13. echo "Usage: $0 [command]"
  14. echo ""
  15. echo "Commands:"
  16. echo " start - Start all services"
  17. echo " test - Run integration tests"
  18. echo " stop - Stop all services"
  19. echo " clean - Stop services and clean up volumes"
  20. echo " logs - Show logs from all services"
  21. echo " status - Show status of all services"
  22. echo " shell - Open shell in test client container"
  23. echo ""
  24. echo "Examples:"
  25. echo " $0 start # Start all services"
  26. echo " $0 test # Run full integration test suite"
  27. echo " $0 logs rdma-engine # Show logs from RDMA engine"
  28. echo " $0 shell # Interactive testing shell"
  29. }
  30. start_services() {
  31. echo -e "${GREEN}🚀 Starting SeaweedFS RDMA integration services...${NC}"
  32. docker-compose up -d seaweedfs-master seaweedfs-volume rdma-engine rdma-sidecar
  33. echo -e "${YELLOW}⏳ Waiting for services to be ready...${NC}"
  34. sleep 10
  35. echo -e "${GREEN}✅ Services started. Checking health...${NC}"
  36. docker-compose ps
  37. }
  38. run_tests() {
  39. echo -e "${GREEN}🧪 Running integration tests...${NC}"
  40. # Make sure services are running
  41. docker-compose up -d seaweedfs-master seaweedfs-volume rdma-engine rdma-sidecar
  42. # Wait for services to be ready
  43. echo -e "${YELLOW}⏳ Waiting for services to be ready...${NC}"
  44. sleep 15
  45. # Run the integration tests
  46. docker-compose run --rm integration-tests
  47. }
  48. stop_services() {
  49. echo -e "${YELLOW}🛑 Stopping services...${NC}"
  50. docker-compose down
  51. echo -e "${GREEN}✅ Services stopped${NC}"
  52. }
  53. clean_all() {
  54. echo -e "${YELLOW}🧹 Cleaning up services and volumes...${NC}"
  55. docker-compose down -v --remove-orphans
  56. echo -e "${GREEN}✅ Cleanup complete${NC}"
  57. }
  58. show_logs() {
  59. local service=${1:-}
  60. if [ -n "$service" ]; then
  61. echo -e "${BLUE}📋 Showing logs for $service...${NC}"
  62. docker-compose logs -f "$service"
  63. else
  64. echo -e "${BLUE}📋 Showing logs for all services...${NC}"
  65. docker-compose logs -f
  66. fi
  67. }
  68. show_status() {
  69. echo -e "${BLUE}📊 Service Status:${NC}"
  70. docker-compose ps
  71. echo -e "\n${BLUE}📡 Health Checks:${NC}"
  72. # Check SeaweedFS Master
  73. if curl -s http://localhost:9333/cluster/status >/dev/null 2>&1; then
  74. echo -e " ${GREEN}✅ SeaweedFS Master: Healthy${NC}"
  75. else
  76. echo -e " ${RED}❌ SeaweedFS Master: Unhealthy${NC}"
  77. fi
  78. # Check SeaweedFS Volume
  79. if curl -s http://localhost:8080/status >/dev/null 2>&1; then
  80. echo -e " ${GREEN}✅ SeaweedFS Volume: Healthy${NC}"
  81. else
  82. echo -e " ${RED}❌ SeaweedFS Volume: Unhealthy${NC}"
  83. fi
  84. # Check RDMA Sidecar
  85. if curl -s http://localhost:8081/health >/dev/null 2>&1; then
  86. echo -e " ${GREEN}✅ RDMA Sidecar: Healthy${NC}"
  87. else
  88. echo -e " ${RED}❌ RDMA Sidecar: Unhealthy${NC}"
  89. fi
  90. }
  91. open_shell() {
  92. echo -e "${GREEN}🐚 Opening interactive shell in test client...${NC}"
  93. echo -e "${YELLOW}Use './test-rdma --help' for RDMA testing commands${NC}"
  94. echo -e "${YELLOW}Use 'curl http://rdma-sidecar:8081/health' to test sidecar${NC}"
  95. docker-compose run --rm test-client /bin/bash
  96. }
  97. # Main command handling
  98. case "${1:-}" in
  99. start)
  100. start_services
  101. ;;
  102. test)
  103. run_tests
  104. ;;
  105. stop)
  106. stop_services
  107. ;;
  108. clean)
  109. clean_all
  110. ;;
  111. logs)
  112. show_logs "${2:-}"
  113. ;;
  114. status)
  115. show_status
  116. ;;
  117. shell)
  118. open_shell
  119. ;;
  120. -h|--help|help)
  121. print_usage
  122. ;;
  123. "")
  124. print_usage
  125. exit 1
  126. ;;
  127. *)
  128. echo -e "${RED}❌ Unknown command: $1${NC}"
  129. print_usage
  130. exit 1
  131. ;;
  132. esac