run-mount-rdma-tests.sh 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. #!/bin/bash
  2. set -euo pipefail
  3. # Colors for output
  4. RED='\033[0;31m'
  5. GREEN='\033[0;32m'
  6. BLUE='\033[0;34m'
  7. YELLOW='\033[1;33m'
  8. NC='\033[0m' # No Color
  9. # Configuration
  10. COMPOSE_FILE="docker-compose.mount-rdma.yml"
  11. PROJECT_NAME="seaweedfs-rdma-mount"
  12. # Function to show usage
  13. show_usage() {
  14. echo -e "${BLUE}🚀 SeaweedFS RDMA Mount Test Runner${NC}"
  15. echo "===================================="
  16. echo ""
  17. echo "Usage: $0 [COMMAND] [OPTIONS]"
  18. echo ""
  19. echo "Commands:"
  20. echo " start Start the RDMA mount environment"
  21. echo " stop Stop and cleanup the environment"
  22. echo " restart Restart the environment"
  23. echo " status Show status of all services"
  24. echo " logs [service] Show logs for all services or specific service"
  25. echo " test Run integration tests"
  26. echo " perf Run performance tests"
  27. echo " shell Open shell in mount container"
  28. echo " cleanup Full cleanup including volumes"
  29. echo ""
  30. echo "Services:"
  31. echo " seaweedfs-master SeaweedFS master server"
  32. echo " seaweedfs-volume SeaweedFS volume server"
  33. echo " seaweedfs-filer SeaweedFS filer server"
  34. echo " rdma-engine RDMA engine (Rust)"
  35. echo " rdma-sidecar RDMA sidecar (Go)"
  36. echo " seaweedfs-mount SeaweedFS mount with RDMA"
  37. echo ""
  38. echo "Examples:"
  39. echo " $0 start # Start all services"
  40. echo " $0 logs seaweedfs-mount # Show mount logs"
  41. echo " $0 test # Run integration tests"
  42. echo " $0 perf # Run performance tests"
  43. echo " $0 shell # Open shell in mount container"
  44. }
  45. # Function to check if Docker Compose is available
  46. check_docker_compose() {
  47. if ! command -v docker-compose >/dev/null 2>&1 && ! docker compose version >/dev/null 2>&1; then
  48. echo -e "${RED}❌ Docker Compose is not available${NC}"
  49. echo "Please install Docker Compose to continue"
  50. exit 1
  51. fi
  52. # Use docker compose if available, otherwise docker-compose
  53. if docker compose version >/dev/null 2>&1; then
  54. DOCKER_COMPOSE="docker compose"
  55. else
  56. DOCKER_COMPOSE="docker-compose"
  57. fi
  58. }
  59. # Function to build required images
  60. build_images() {
  61. echo -e "${BLUE}🔨 Building required Docker images...${NC}"
  62. # Build SeaweedFS binary first
  63. echo "Building SeaweedFS binary..."
  64. cd ..
  65. make
  66. cd seaweedfs-rdma-sidecar
  67. # Copy binary for Docker builds
  68. mkdir -p bin
  69. if [[ -f "../weed" ]]; then
  70. cp ../weed bin/
  71. elif [[ -f "../bin/weed" ]]; then
  72. cp ../bin/weed bin/
  73. elif [[ -f "../build/weed" ]]; then
  74. cp ../build/weed bin/
  75. else
  76. echo "Error: Cannot find weed binary"
  77. find .. -name "weed" -type f
  78. exit 1
  79. fi
  80. # Build RDMA sidecar
  81. echo "Building RDMA sidecar..."
  82. go build -o bin/demo-server cmd/sidecar/main.go
  83. # Build Docker images
  84. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" build
  85. echo -e "${GREEN}✅ Images built successfully${NC}"
  86. }
  87. # Function to start services
  88. start_services() {
  89. echo -e "${BLUE}🚀 Starting SeaweedFS RDMA Mount environment...${NC}"
  90. # Build images if needed
  91. if [[ ! -f "bin/weed" ]] || [[ ! -f "bin/demo-server" ]]; then
  92. build_images
  93. fi
  94. # Start services
  95. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" up -d
  96. echo -e "${GREEN}✅ Services started${NC}"
  97. echo ""
  98. echo "Services are starting up. Use '$0 status' to check their status."
  99. echo "Use '$0 logs' to see the logs."
  100. }
  101. # Function to stop services
  102. stop_services() {
  103. echo -e "${BLUE}🛑 Stopping SeaweedFS RDMA Mount environment...${NC}"
  104. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down
  105. echo -e "${GREEN}✅ Services stopped${NC}"
  106. }
  107. # Function to restart services
  108. restart_services() {
  109. echo -e "${BLUE}🔄 Restarting SeaweedFS RDMA Mount environment...${NC}"
  110. stop_services
  111. sleep 2
  112. start_services
  113. }
  114. # Function to show status
  115. show_status() {
  116. echo -e "${BLUE}📊 Service Status${NC}"
  117. echo "================"
  118. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps
  119. echo ""
  120. echo -e "${BLUE}🔍 Health Checks${NC}"
  121. echo "==============="
  122. # Check individual services
  123. check_service_health "SeaweedFS Master" "http://localhost:9333/cluster/status"
  124. check_service_health "SeaweedFS Volume" "http://localhost:8080/status"
  125. check_service_health "SeaweedFS Filer" "http://localhost:8888/"
  126. check_service_health "RDMA Sidecar" "http://localhost:8081/health"
  127. # Check mount status
  128. echo -n "SeaweedFS Mount: "
  129. if docker exec "${PROJECT_NAME}-seaweedfs-mount-1" mountpoint -q /mnt/seaweedfs 2>/dev/null; then
  130. echo -e "${GREEN}✅ Mounted${NC}"
  131. else
  132. echo -e "${RED}❌ Not mounted${NC}"
  133. fi
  134. }
  135. # Function to check service health
  136. check_service_health() {
  137. local service_name=$1
  138. local health_url=$2
  139. echo -n "$service_name: "
  140. if curl -s "$health_url" >/dev/null 2>&1; then
  141. echo -e "${GREEN}✅ Healthy${NC}"
  142. else
  143. echo -e "${RED}❌ Unhealthy${NC}"
  144. fi
  145. }
  146. # Function to show logs
  147. show_logs() {
  148. local service=$1
  149. if [[ -n "$service" ]]; then
  150. echo -e "${BLUE}📋 Logs for $service${NC}"
  151. echo "===================="
  152. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" logs -f "$service"
  153. else
  154. echo -e "${BLUE}📋 Logs for all services${NC}"
  155. echo "======================="
  156. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" logs -f
  157. fi
  158. }
  159. # Function to run integration tests
  160. run_integration_tests() {
  161. echo -e "${BLUE}🧪 Running integration tests...${NC}"
  162. # Make sure services are running
  163. if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps | grep -q "Up"; then
  164. echo -e "${RED}❌ Services are not running. Start them first with '$0 start'${NC}"
  165. exit 1
  166. fi
  167. # Run integration tests
  168. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" --profile test run --rm integration-test
  169. # Show results
  170. if [[ -d "./test-results" ]]; then
  171. echo -e "${BLUE}📊 Test Results${NC}"
  172. echo "==============="
  173. if [[ -f "./test-results/overall.result" ]]; then
  174. local result
  175. result=$(cat "./test-results/overall.result")
  176. if [[ "$result" == "SUCCESS" ]]; then
  177. echo -e "${GREEN}🎉 ALL TESTS PASSED!${NC}"
  178. else
  179. echo -e "${RED}💥 SOME TESTS FAILED!${NC}"
  180. fi
  181. fi
  182. echo ""
  183. echo "Detailed results available in: ./test-results/"
  184. ls -la ./test-results/
  185. fi
  186. }
  187. # Function to run performance tests
  188. run_performance_tests() {
  189. echo -e "${BLUE}🏁 Running performance tests...${NC}"
  190. # Make sure services are running
  191. if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps | grep -q "Up"; then
  192. echo -e "${RED}❌ Services are not running. Start them first with '$0 start'${NC}"
  193. exit 1
  194. fi
  195. # Run performance tests
  196. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" --profile performance run --rm performance-test
  197. # Show results
  198. if [[ -d "./performance-results" ]]; then
  199. echo -e "${BLUE}📊 Performance Results${NC}"
  200. echo "======================"
  201. echo ""
  202. echo "Results available in: ./performance-results/"
  203. ls -la ./performance-results/
  204. if [[ -f "./performance-results/performance_report.html" ]]; then
  205. echo ""
  206. echo -e "${GREEN}📄 HTML Report: ./performance-results/performance_report.html${NC}"
  207. fi
  208. fi
  209. }
  210. # Function to open shell in mount container
  211. open_shell() {
  212. echo -e "${BLUE}🐚 Opening shell in mount container...${NC}"
  213. if ! $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" ps seaweedfs-mount | grep -q "Up"; then
  214. echo -e "${RED}❌ Mount container is not running${NC}"
  215. exit 1
  216. fi
  217. docker exec -it "${PROJECT_NAME}-seaweedfs-mount-1" /bin/bash
  218. }
  219. # Function to cleanup everything
  220. cleanup_all() {
  221. echo -e "${BLUE}🧹 Full cleanup...${NC}"
  222. # Stop services
  223. $DOCKER_COMPOSE -f "$COMPOSE_FILE" -p "$PROJECT_NAME" down -v --remove-orphans
  224. # Remove images
  225. echo "Removing Docker images..."
  226. docker images | grep "$PROJECT_NAME" | awk '{print $3}' | xargs -r docker rmi -f
  227. # Clean up local files
  228. rm -rf bin/ test-results/ performance-results/
  229. echo -e "${GREEN}✅ Full cleanup completed${NC}"
  230. }
  231. # Main function
  232. main() {
  233. local command=${1:-""}
  234. # Check Docker Compose availability
  235. check_docker_compose
  236. case "$command" in
  237. "start")
  238. start_services
  239. ;;
  240. "stop")
  241. stop_services
  242. ;;
  243. "restart")
  244. restart_services
  245. ;;
  246. "status")
  247. show_status
  248. ;;
  249. "logs")
  250. show_logs "${2:-}"
  251. ;;
  252. "test")
  253. run_integration_tests
  254. ;;
  255. "perf")
  256. run_performance_tests
  257. ;;
  258. "shell")
  259. open_shell
  260. ;;
  261. "cleanup")
  262. cleanup_all
  263. ;;
  264. "build")
  265. build_images
  266. ;;
  267. "help"|"-h"|"--help")
  268. show_usage
  269. ;;
  270. "")
  271. show_usage
  272. ;;
  273. *)
  274. echo -e "${RED}❌ Unknown command: $command${NC}"
  275. echo ""
  276. show_usage
  277. exit 1
  278. ;;
  279. esac
  280. }
  281. # Run main function with all arguments
  282. main "$@"