Makefile 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. # Makefile for S3 SSE Integration Tests
  2. # This Makefile provides targets for running comprehensive S3 Server-Side Encryption tests
  3. # Default values
  4. SEAWEEDFS_BINARY ?= weed
  5. S3_PORT ?= 8333
  6. FILER_PORT ?= 8888
  7. VOLUME_PORT ?= 8080
  8. MASTER_PORT ?= 9333
  9. TEST_TIMEOUT ?= 15m
  10. BUCKET_PREFIX ?= test-sse-
  11. ACCESS_KEY ?= some_access_key1
  12. SECRET_KEY ?= some_secret_key1
  13. VOLUME_MAX_SIZE_MB ?= 50
  14. VOLUME_MAX_COUNT ?= 100
  15. # SSE-KMS configuration
  16. KMS_KEY_ID ?= test-key-123
  17. KMS_TYPE ?= local
  18. OPENBAO_ADDR ?= http://127.0.0.1:8200
  19. OPENBAO_TOKEN ?= root-token-for-testing
  20. DOCKER_COMPOSE ?= docker-compose
  21. # Test directory
  22. TEST_DIR := $(shell pwd)
  23. SEAWEEDFS_ROOT := $(shell cd ../../../ && pwd)
  24. # Colors for output
  25. RED := \033[0;31m
  26. GREEN := \033[0;32m
  27. YELLOW := \033[1;33m
  28. NC := \033[0m # No Color
  29. .PHONY: all test clean start-seaweedfs stop-seaweedfs stop-seaweedfs-safe start-seaweedfs-ci check-binary build-weed help help-extended test-with-server test-quick-with-server test-metadata-persistence setup-openbao test-with-kms test-ssekms-integration clean-kms start-full-stack stop-full-stack
  30. all: test-basic
  31. # Build SeaweedFS binary (GitHub Actions compatible)
  32. build-weed:
  33. @echo "Building SeaweedFS binary..."
  34. @cd $(SEAWEEDFS_ROOT)/weed && go install -buildvcs=false
  35. @echo "✅ SeaweedFS binary built successfully"
  36. help:
  37. @echo "SeaweedFS S3 SSE Integration Tests"
  38. @echo ""
  39. @echo "Available targets:"
  40. @echo " test-basic - Run basic S3 put/get tests first"
  41. @echo " test - Run all S3 SSE integration tests"
  42. @echo " test-ssec - Run SSE-C tests only"
  43. @echo " test-ssekms - Run SSE-KMS tests only"
  44. @echo " test-copy - Run SSE copy operation tests"
  45. @echo " test-multipart - Run SSE multipart upload tests"
  46. @echo " test-errors - Run SSE error condition tests"
  47. @echo " benchmark - Run SSE performance benchmarks"
  48. @echo " KMS Integration:"
  49. @echo " setup-openbao - Set up OpenBao KMS for testing"
  50. @echo " test-with-kms - Run full SSE integration with real KMS"
  51. @echo " test-ssekms-integration - Run SSE-KMS with OpenBao only"
  52. @echo " start-full-stack - Start SeaweedFS + OpenBao with Docker"
  53. @echo " stop-full-stack - Stop Docker services"
  54. @echo " clean-kms - Clean up KMS test environment"
  55. @echo " start-seaweedfs - Start SeaweedFS server for testing"
  56. @echo " stop-seaweedfs - Stop SeaweedFS server"
  57. @echo " clean - Clean up test artifacts"
  58. @echo " check-binary - Check if SeaweedFS binary exists"
  59. @echo ""
  60. @echo "Configuration:"
  61. @echo " SEAWEEDFS_BINARY=$(SEAWEEDFS_BINARY)"
  62. @echo " S3_PORT=$(S3_PORT)"
  63. @echo " FILER_PORT=$(FILER_PORT)"
  64. @echo " VOLUME_PORT=$(VOLUME_PORT)"
  65. @echo " MASTER_PORT=$(MASTER_PORT)"
  66. @echo " TEST_TIMEOUT=$(TEST_TIMEOUT)"
  67. @echo " VOLUME_MAX_SIZE_MB=$(VOLUME_MAX_SIZE_MB)"
  68. check-binary:
  69. @if ! command -v $(SEAWEEDFS_BINARY) > /dev/null 2>&1; then \
  70. echo "$(RED)Error: SeaweedFS binary '$(SEAWEEDFS_BINARY)' not found in PATH$(NC)"; \
  71. echo "Please build SeaweedFS first by running 'make' in the root directory"; \
  72. exit 1; \
  73. fi
  74. @echo "$(GREEN)SeaweedFS binary found: $$(which $(SEAWEEDFS_BINARY))$(NC)"
  75. start-seaweedfs: check-binary
  76. @echo "$(YELLOW)Starting SeaweedFS server for SSE testing...$(NC)"
  77. @# Use port-based cleanup for consistency and safety
  78. @echo "Cleaning up any existing processes..."
  79. @lsof -ti :$(MASTER_PORT) | xargs -r kill -TERM || true
  80. @lsof -ti :$(VOLUME_PORT) | xargs -r kill -TERM || true
  81. @lsof -ti :$(FILER_PORT) | xargs -r kill -TERM || true
  82. @lsof -ti :$(S3_PORT) | xargs -r kill -TERM || true
  83. @sleep 2
  84. # Create necessary directories
  85. @mkdir -p /tmp/seaweedfs-test-sse-master
  86. @mkdir -p /tmp/seaweedfs-test-sse-volume
  87. @mkdir -p /tmp/seaweedfs-test-sse-filer
  88. # Start master server with volume size limit and explicit gRPC port
  89. @nohup $(SEAWEEDFS_BINARY) master -port=$(MASTER_PORT) -port.grpc=$$(( $(MASTER_PORT) + 10000 )) -mdir=/tmp/seaweedfs-test-sse-master -volumeSizeLimitMB=$(VOLUME_MAX_SIZE_MB) -ip=127.0.0.1 > /tmp/seaweedfs-sse-master.log 2>&1 &
  90. @sleep 3
  91. # Start volume server with master HTTP port and increased capacity
  92. @nohup $(SEAWEEDFS_BINARY) volume -port=$(VOLUME_PORT) -mserver=127.0.0.1:$(MASTER_PORT) -dir=/tmp/seaweedfs-test-sse-volume -max=$(VOLUME_MAX_COUNT) -ip=127.0.0.1 > /tmp/seaweedfs-sse-volume.log 2>&1 &
  93. @sleep 5
  94. # Start filer server (using standard SeaweedFS gRPC port convention: HTTP port + 10000)
  95. @nohup $(SEAWEEDFS_BINARY) filer -port=$(FILER_PORT) -port.grpc=$$(( $(FILER_PORT) + 10000 )) -master=127.0.0.1:$(MASTER_PORT) -dataCenter=defaultDataCenter -ip=127.0.0.1 > /tmp/seaweedfs-sse-filer.log 2>&1 &
  96. @sleep 3
  97. # Create S3 configuration with SSE-KMS support
  98. @printf '{"identities":[{"name":"%s","credentials":[{"accessKey":"%s","secretKey":"%s"}],"actions":["Admin","Read","Write"]}],"kms":{"type":"%s","configs":{"keyId":"%s","encryptionContext":{},"bucketKey":false}}}' "$(ACCESS_KEY)" "$(ACCESS_KEY)" "$(SECRET_KEY)" "$(KMS_TYPE)" "$(KMS_KEY_ID)" > /tmp/seaweedfs-sse-s3.json
  99. # Start S3 server with KMS configuration
  100. @nohup $(SEAWEEDFS_BINARY) s3 -port=$(S3_PORT) -filer=127.0.0.1:$(FILER_PORT) -config=/tmp/seaweedfs-sse-s3.json -ip.bind=127.0.0.1 > /tmp/seaweedfs-sse-s3.log 2>&1 &
  101. @sleep 5
  102. # Wait for S3 service to be ready
  103. @echo "$(YELLOW)Waiting for S3 service to be ready...$(NC)"
  104. @for i in $$(seq 1 30); do \
  105. if curl -s -f http://127.0.0.1:$(S3_PORT) > /dev/null 2>&1; then \
  106. echo "$(GREEN)S3 service is ready$(NC)"; \
  107. break; \
  108. fi; \
  109. echo "Waiting for S3 service... ($$i/30)"; \
  110. sleep 1; \
  111. done
  112. # Additional wait for filer gRPC to be ready
  113. @echo "$(YELLOW)Waiting for filer gRPC to be ready...$(NC)"
  114. @sleep 2
  115. @echo "$(GREEN)SeaweedFS server started successfully for SSE testing$(NC)"
  116. @echo "Master: http://localhost:$(MASTER_PORT)"
  117. @echo "Volume: http://localhost:$(VOLUME_PORT)"
  118. @echo "Filer: http://localhost:$(FILER_PORT)"
  119. @echo "S3: http://localhost:$(S3_PORT)"
  120. @echo "Volume Max Size: $(VOLUME_MAX_SIZE_MB)MB"
  121. @echo "SSE-KMS Support: Enabled"
  122. stop-seaweedfs:
  123. @echo "$(YELLOW)Stopping SeaweedFS server...$(NC)"
  124. @# Use port-based cleanup for consistency and safety
  125. @lsof -ti :$(MASTER_PORT) | xargs -r kill -TERM || true
  126. @lsof -ti :$(VOLUME_PORT) | xargs -r kill -TERM || true
  127. @lsof -ti :$(FILER_PORT) | xargs -r kill -TERM || true
  128. @lsof -ti :$(S3_PORT) | xargs -r kill -TERM || true
  129. @sleep 2
  130. @echo "$(GREEN)SeaweedFS server stopped$(NC)"
  131. # CI-safe server stop that's more conservative
  132. stop-seaweedfs-safe:
  133. @echo "$(YELLOW)Safely stopping SeaweedFS server...$(NC)"
  134. @# Use port-based cleanup which is safer in CI
  135. @if command -v lsof >/dev/null 2>&1; then \
  136. echo "Using lsof for port-based cleanup..."; \
  137. lsof -ti :$(MASTER_PORT) 2>/dev/null | head -5 | while read pid; do kill -TERM $$pid 2>/dev/null || true; done; \
  138. lsof -ti :$(VOLUME_PORT) 2>/dev/null | head -5 | while read pid; do kill -TERM $$pid 2>/dev/null || true; done; \
  139. lsof -ti :$(FILER_PORT) 2>/dev/null | head -5 | while read pid; do kill -TERM $$pid 2>/dev/null || true; done; \
  140. lsof -ti :$(S3_PORT) 2>/dev/null | head -5 | while read pid; do kill -TERM $$pid 2>/dev/null || true; done; \
  141. else \
  142. echo "lsof not available, using netstat approach..."; \
  143. netstat -tlnp 2>/dev/null | grep :$(MASTER_PORT) | awk '{print $$7}' | cut -d/ -f1 | head -5 | while read pid; do [ "$$pid" != "-" ] && kill -TERM $$pid 2>/dev/null || true; done; \
  144. netstat -tlnp 2>/dev/null | grep :$(VOLUME_PORT) | awk '{print $$7}' | cut -d/ -f1 | head -5 | while read pid; do [ "$$pid" != "-" ] && kill -TERM $$pid 2>/dev/null || true; done; \
  145. netstat -tlnp 2>/dev/null | grep :$(FILER_PORT) | awk '{print $$7}' | cut -d/ -f1 | head -5 | while read pid; do [ "$$pid" != "-" ] && kill -TERM $$pid 2>/dev/null || true; done; \
  146. netstat -tlnp 2>/dev/null | grep :$(S3_PORT) | awk '{print $$7}' | cut -d/ -f1 | head -5 | while read pid; do [ "$$pid" != "-" ] && kill -TERM $$pid 2>/dev/null || true; done; \
  147. fi
  148. @sleep 2
  149. @echo "$(GREEN)SeaweedFS server safely stopped$(NC)"
  150. clean:
  151. @echo "$(YELLOW)Cleaning up SSE test artifacts...$(NC)"
  152. @rm -rf /tmp/seaweedfs-test-sse-*
  153. @rm -f /tmp/seaweedfs-sse-*.log
  154. @rm -f /tmp/seaweedfs-sse-s3.json
  155. @echo "$(GREEN)SSE test cleanup completed$(NC)"
  156. test-basic: check-binary
  157. @echo "$(YELLOW)Running basic S3 SSE integration tests...$(NC)"
  158. @$(MAKE) start-seaweedfs-ci
  159. @sleep 5
  160. @echo "$(GREEN)Starting basic SSE tests...$(NC)"
  161. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSECIntegrationBasic|TestSSEKMSIntegrationBasic" ./test/s3/sse || (echo "$(RED)Basic SSE tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  162. @$(MAKE) stop-seaweedfs-safe
  163. @echo "$(GREEN)Basic SSE tests completed successfully!$(NC)"
  164. test: test-basic
  165. @echo "$(YELLOW)Running all S3 SSE integration tests...$(NC)"
  166. @$(MAKE) start-seaweedfs-ci
  167. @sleep 5
  168. @echo "$(GREEN)Starting comprehensive SSE tests...$(NC)"
  169. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSE.*Integration" ./test/s3/sse || (echo "$(RED)SSE tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  170. @$(MAKE) stop-seaweedfs-safe
  171. @echo "$(GREEN)All SSE integration tests completed successfully!$(NC)"
  172. test-ssec: check-binary
  173. @echo "$(YELLOW)Running SSE-C integration tests...$(NC)"
  174. @$(MAKE) start-seaweedfs-ci
  175. @sleep 5
  176. @echo "$(GREEN)Starting SSE-C tests...$(NC)"
  177. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSEC.*Integration" ./test/s3/sse || (echo "$(RED)SSE-C tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  178. @$(MAKE) stop-seaweedfs-safe
  179. @echo "$(GREEN)SSE-C tests completed successfully!$(NC)"
  180. test-ssekms: check-binary
  181. @echo "$(YELLOW)Running SSE-KMS integration tests...$(NC)"
  182. @$(MAKE) start-seaweedfs-ci
  183. @sleep 5
  184. @echo "$(GREEN)Starting SSE-KMS tests...$(NC)"
  185. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSEKMS.*Integration" ./test/s3/sse || (echo "$(RED)SSE-KMS tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  186. @$(MAKE) stop-seaweedfs-safe
  187. @echo "$(GREEN)SSE-KMS tests completed successfully!$(NC)"
  188. test-copy: check-binary
  189. @echo "$(YELLOW)Running SSE copy operation tests...$(NC)"
  190. @$(MAKE) start-seaweedfs-ci
  191. @sleep 5
  192. @echo "$(GREEN)Starting SSE copy tests...$(NC)"
  193. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run ".*CopyIntegration" ./test/s3/sse || (echo "$(RED)SSE copy tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  194. @$(MAKE) stop-seaweedfs-safe
  195. @echo "$(GREEN)SSE copy tests completed successfully!$(NC)"
  196. test-multipart: check-binary
  197. @echo "$(YELLOW)Running SSE multipart upload tests...$(NC)"
  198. @$(MAKE) start-seaweedfs-ci
  199. @sleep 5
  200. @echo "$(GREEN)Starting SSE multipart tests...$(NC)"
  201. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSEMultipartUploadIntegration" ./test/s3/sse || (echo "$(RED)SSE multipart tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  202. @$(MAKE) stop-seaweedfs-safe
  203. @echo "$(GREEN)SSE multipart tests completed successfully!$(NC)"
  204. test-errors: check-binary
  205. @echo "$(YELLOW)Running SSE error condition tests...$(NC)"
  206. @$(MAKE) start-seaweedfs-ci
  207. @sleep 5
  208. @echo "$(GREEN)Starting SSE error tests...$(NC)"
  209. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSEErrorConditions" ./test/s3/sse || (echo "$(RED)SSE error tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  210. @$(MAKE) stop-seaweedfs-safe
  211. @echo "$(GREEN)SSE error tests completed successfully!$(NC)"
  212. test-quick: check-binary
  213. @echo "$(YELLOW)Running quick SSE tests...$(NC)"
  214. @$(MAKE) start-seaweedfs-ci
  215. @sleep 5
  216. @echo "$(GREEN)Starting quick SSE tests...$(NC)"
  217. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=5m -run "TestSSECIntegrationBasic|TestSSEKMSIntegrationBasic" ./test/s3/sse || (echo "$(RED)Quick SSE tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  218. @$(MAKE) stop-seaweedfs-safe
  219. @echo "$(GREEN)Quick SSE tests completed successfully!$(NC)"
  220. benchmark: check-binary
  221. @echo "$(YELLOW)Running SSE performance benchmarks...$(NC)"
  222. @$(MAKE) start-seaweedfs-ci
  223. @sleep 5
  224. @echo "$(GREEN)Starting SSE benchmarks...$(NC)"
  225. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=30m -bench=. -run=Benchmark ./test/s3/sse || (echo "$(RED)SSE benchmarks failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  226. @$(MAKE) stop-seaweedfs-safe
  227. @echo "$(GREEN)SSE benchmarks completed!$(NC)"
  228. # Debug targets
  229. debug-logs:
  230. @echo "$(YELLOW)=== Master Log ===$(NC)"
  231. @tail -n 50 /tmp/seaweedfs-sse-master.log || echo "No master log found"
  232. @echo "$(YELLOW)=== Volume Log ===$(NC)"
  233. @tail -n 50 /tmp/seaweedfs-sse-volume.log || echo "No volume log found"
  234. @echo "$(YELLOW)=== Filer Log ===$(NC)"
  235. @tail -n 50 /tmp/seaweedfs-sse-filer.log || echo "No filer log found"
  236. @echo "$(YELLOW)=== S3 Log ===$(NC)"
  237. @tail -n 50 /tmp/seaweedfs-sse-s3.log || echo "No S3 log found"
  238. debug-status:
  239. @echo "$(YELLOW)=== Process Status ===$(NC)"
  240. @ps aux | grep -E "(weed|seaweedfs)" | grep -v grep || echo "No SeaweedFS processes found"
  241. @echo "$(YELLOW)=== Port Status ===$(NC)"
  242. @netstat -an | grep -E "($(MASTER_PORT)|$(VOLUME_PORT)|$(FILER_PORT)|$(S3_PORT))" || echo "No ports in use"
  243. # Manual test targets for development
  244. manual-start: start-seaweedfs
  245. @echo "$(GREEN)SeaweedFS with SSE support is now running for manual testing$(NC)"
  246. @echo "You can now run SSE tests manually or use S3 clients to test SSE functionality"
  247. @echo "Run 'make manual-stop' when finished"
  248. manual-stop: stop-seaweedfs clean
  249. # CI/CD targets
  250. ci-test: test-quick
  251. # Stress test
  252. stress: check-binary
  253. @echo "$(YELLOW)Running SSE stress tests...$(NC)"
  254. @$(MAKE) start-seaweedfs-ci
  255. @sleep 5
  256. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=60m -run="TestSSE.*Integration" -count=5 ./test/s3/sse || (echo "$(RED)SSE stress tests failed$(NC)" && $(MAKE) stop-seaweedfs-safe && exit 1)
  257. @$(MAKE) stop-seaweedfs-safe
  258. @echo "$(GREEN)SSE stress tests completed!$(NC)"
  259. # Performance test with various data sizes
  260. perf: check-binary
  261. @echo "$(YELLOW)Running SSE performance tests with various data sizes...$(NC)"
  262. @$(MAKE) start-seaweedfs-ci
  263. @sleep 5
  264. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=60m -run=".*VariousDataSizes" ./test/s3/sse || (echo "$(RED)SSE performance tests failed$(NC)" && $(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe && exit 1)
  265. @$(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe
  266. @echo "$(GREEN)SSE performance tests completed!$(NC)"
  267. # Test specific scenarios that would catch the metadata bug
  268. test-metadata-persistence: check-binary
  269. @echo "$(YELLOW)Running SSE metadata persistence tests (would catch filer metadata bugs)...$(NC)"
  270. @$(MAKE) start-seaweedfs-ci
  271. @sleep 5
  272. @echo "$(GREEN)Testing that SSE metadata survives full PUT/GET cycle...$(NC)"
  273. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSECIntegrationBasic" ./test/s3/sse || (echo "$(RED)SSE metadata persistence tests failed$(NC)" && $(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe && exit 1)
  274. @$(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe
  275. @echo "$(GREEN)SSE metadata persistence tests completed successfully!$(NC)"
  276. @echo "$(GREEN)✅ These tests would have caught the filer metadata storage bug!$(NC)"
  277. # GitHub Actions compatible test-with-server target that handles server lifecycle
  278. test-with-server: build-weed
  279. @echo "🚀 Starting SSE integration tests with automated server management..."
  280. @echo "Starting SeaweedFS cluster..."
  281. @# Use the CI-safe startup directly without aggressive cleanup
  282. @if $(MAKE) start-seaweedfs-ci > weed-test.log 2>&1; then \
  283. echo "✅ SeaweedFS cluster started successfully"; \
  284. echo "Running SSE integration tests..."; \
  285. trap '$(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe || true' EXIT; \
  286. if [ -n "$(TEST_PATTERN)" ]; then \
  287. echo "🔍 Running tests matching pattern: $(TEST_PATTERN)"; \
  288. cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "$(TEST_PATTERN)" ./test/s3/sse || exit 1; \
  289. else \
  290. echo "🔍 Running all SSE integration tests"; \
  291. cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSE.*Integration" ./test/s3/sse || exit 1; \
  292. fi; \
  293. echo "✅ All tests completed successfully"; \
  294. $(MAKE) -C $(TEST_DIR) stop-seaweedfs-safe || true; \
  295. else \
  296. echo "❌ Failed to start SeaweedFS cluster"; \
  297. echo "=== Server startup logs ==="; \
  298. tail -100 weed-test.log 2>/dev/null || echo "No startup log available"; \
  299. echo "=== System information ==="; \
  300. ps aux | grep -E "weed|make" | grep -v grep || echo "No relevant processes found"; \
  301. exit 1; \
  302. fi
  303. # CI-safe server startup that avoids process conflicts
  304. start-seaweedfs-ci: check-binary
  305. @echo "$(YELLOW)Starting SeaweedFS server for CI testing...$(NC)"
  306. # Create necessary directories
  307. @mkdir -p /tmp/seaweedfs-test-sse-master
  308. @mkdir -p /tmp/seaweedfs-test-sse-volume
  309. @mkdir -p /tmp/seaweedfs-test-sse-filer
  310. # Clean up any old server logs
  311. @rm -f /tmp/seaweedfs-sse-*.log || true
  312. # Start master server with volume size limit and explicit gRPC port
  313. @echo "Starting master server..."
  314. @nohup $(SEAWEEDFS_BINARY) master -port=$(MASTER_PORT) -port.grpc=$$(( $(MASTER_PORT) + 10000 )) -mdir=/tmp/seaweedfs-test-sse-master -volumeSizeLimitMB=$(VOLUME_MAX_SIZE_MB) -ip=127.0.0.1 > /tmp/seaweedfs-sse-master.log 2>&1 &
  315. @sleep 3
  316. # Start volume server with master HTTP port and increased capacity
  317. @echo "Starting volume server..."
  318. @nohup $(SEAWEEDFS_BINARY) volume -port=$(VOLUME_PORT) -mserver=127.0.0.1:$(MASTER_PORT) -dir=/tmp/seaweedfs-test-sse-volume -max=$(VOLUME_MAX_COUNT) -ip=127.0.0.1 > /tmp/seaweedfs-sse-volume.log 2>&1 &
  319. @sleep 5
  320. # Create S3 JSON configuration with KMS (Local provider) and basic identity for embedded S3
  321. @sed -e 's/ACCESS_KEY_PLACEHOLDER/$(ACCESS_KEY)/g' \
  322. -e 's/SECRET_KEY_PLACEHOLDER/$(SECRET_KEY)/g' \
  323. s3-config-template.json > /tmp/seaweedfs-s3.json
  324. # Start filer server with embedded S3 using the JSON config (with verbose logging)
  325. @echo "Starting filer server with embedded S3..."
  326. @AWS_ACCESS_KEY_ID=$(ACCESS_KEY) AWS_SECRET_ACCESS_KEY=$(SECRET_KEY) GLOG_v=4 nohup $(SEAWEEDFS_BINARY) filer -port=$(FILER_PORT) -port.grpc=$$(( $(FILER_PORT) + 10000 )) -master=127.0.0.1:$(MASTER_PORT) -dataCenter=defaultDataCenter -ip=127.0.0.1 -s3 -s3.port=$(S3_PORT) -s3.config=/tmp/seaweedfs-s3.json > /tmp/seaweedfs-sse-filer.log 2>&1 &
  327. @sleep 5
  328. # Wait for S3 service to be ready - use port-based checking for reliability
  329. @echo "$(YELLOW)Waiting for S3 service to be ready...$(NC)"
  330. @for i in $$(seq 1 20); do \
  331. if netstat -an 2>/dev/null | grep -q ":$(S3_PORT).*LISTEN" || \
  332. ss -an 2>/dev/null | grep -q ":$(S3_PORT).*LISTEN" || \
  333. lsof -i :$(S3_PORT) >/dev/null 2>&1; then \
  334. echo "$(GREEN)S3 service is listening on port $(S3_PORT)$(NC)"; \
  335. sleep 1; \
  336. break; \
  337. fi; \
  338. if [ $$i -eq 20 ]; then \
  339. echo "$(RED)S3 service failed to start within 20 seconds$(NC)"; \
  340. echo "=== Detailed Logs ==="; \
  341. echo "Master log:"; tail -30 /tmp/seaweedfs-sse-master.log || true; \
  342. echo "Volume log:"; tail -30 /tmp/seaweedfs-sse-volume.log || true; \
  343. echo "Filer log:"; tail -30 /tmp/seaweedfs-sse-filer.log || true; \
  344. echo "=== Port Status ==="; \
  345. netstat -an 2>/dev/null | grep ":$(S3_PORT)" || \
  346. ss -an 2>/dev/null | grep ":$(S3_PORT)" || \
  347. echo "No port listening on $(S3_PORT)"; \
  348. echo "=== Process Status ==="; \
  349. ps aux | grep -E "weed.*(filer|s3).*$(S3_PORT)" | grep -v grep || echo "No S3 process found"; \
  350. exit 1; \
  351. fi; \
  352. echo "Waiting for S3 service... ($$i/20)"; \
  353. sleep 1; \
  354. done
  355. # Additional wait for filer gRPC to be ready
  356. @echo "$(YELLOW)Waiting for filer gRPC to be ready...$(NC)"
  357. @sleep 2
  358. @echo "$(GREEN)SeaweedFS server started successfully for SSE testing$(NC)"
  359. @echo "Master: http://localhost:$(MASTER_PORT)"
  360. @echo "Volume: http://localhost:$(VOLUME_PORT)"
  361. @echo "Filer: http://localhost:$(FILER_PORT)"
  362. @echo "S3: http://localhost:$(S3_PORT)"
  363. @echo "Volume Max Size: $(VOLUME_MAX_SIZE_MB)MB"
  364. @echo "SSE-KMS Support: Enabled"
  365. # GitHub Actions compatible quick test subset
  366. test-quick-with-server: build-weed
  367. @echo "🚀 Starting quick SSE tests with automated server management..."
  368. @trap 'make stop-seaweedfs-safe || true' EXIT; \
  369. echo "Starting SeaweedFS cluster..."; \
  370. if make start-seaweedfs-ci > weed-test.log 2>&1; then \
  371. echo "✅ SeaweedFS cluster started successfully"; \
  372. echo "Running quick SSE integration tests..."; \
  373. cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) -run "TestSSECIntegrationBasic|TestSSEKMSIntegrationBasic|TestSimpleSSECIntegration" ./test/s3/sse || exit 1; \
  374. echo "✅ Quick tests completed successfully"; \
  375. make stop-seaweedfs-safe || true; \
  376. else \
  377. echo "❌ Failed to start SeaweedFS cluster"; \
  378. echo "=== Server startup logs ==="; \
  379. tail -50 weed-test.log; \
  380. exit 1; \
  381. fi
  382. # Help target - extended version
  383. help-extended:
  384. @echo "Available targets:"
  385. @echo " test - Run all SSE integration tests (requires running server)"
  386. @echo " test-with-server - Run all tests with automatic server management (GitHub Actions compatible)"
  387. @echo " test-quick-with-server - Run quick tests with automatic server management"
  388. @echo " test-ssec - Run only SSE-C tests"
  389. @echo " test-ssekms - Run only SSE-KMS tests"
  390. @echo " test-copy - Run only copy operation tests"
  391. @echo " test-multipart - Run only multipart upload tests"
  392. @echo " benchmark - Run performance benchmarks"
  393. @echo " perf - Run performance tests with various data sizes"
  394. @echo " test-metadata-persistence - Test metadata persistence (catches filer bugs)"
  395. @echo " build-weed - Build SeaweedFS binary"
  396. @echo " check-binary - Check if SeaweedFS binary exists"
  397. @echo " start-seaweedfs - Start SeaweedFS cluster"
  398. @echo " start-seaweedfs-ci - Start SeaweedFS cluster (CI-safe version)"
  399. @echo " stop-seaweedfs - Stop SeaweedFS cluster"
  400. @echo " stop-seaweedfs-safe - Stop SeaweedFS cluster (CI-safe version)"
  401. @echo " clean - Clean up test artifacts"
  402. @echo " debug-logs - Show recent logs from all services"
  403. @echo ""
  404. @echo "Environment Variables:"
  405. @echo " ACCESS_KEY - S3 access key (default: some_access_key1)"
  406. @echo " SECRET_KEY - S3 secret key (default: some_secret_key1)"
  407. @echo " KMS_KEY_ID - KMS key ID for SSE-KMS (default: test-key-123)"
  408. @echo " KMS_TYPE - KMS type (default: local)"
  409. @echo " VOLUME_MAX_SIZE_MB - Volume maximum size in MB (default: 50)"
  410. @echo " TEST_TIMEOUT - Test timeout (default: 15m)"
  411. ####################################################
  412. # KMS Integration Testing with OpenBao
  413. ####################################################
  414. setup-openbao:
  415. @echo "$(YELLOW)Setting up OpenBao for SSE-KMS testing...$(NC)"
  416. @$(DOCKER_COMPOSE) up -d openbao
  417. @sleep 10
  418. @echo "$(YELLOW)Configuring OpenBao...$(NC)"
  419. @OPENBAO_ADDR=$(OPENBAO_ADDR) OPENBAO_TOKEN=$(OPENBAO_TOKEN) ./setup_openbao_sse.sh
  420. @echo "$(GREEN)✅ OpenBao setup complete!$(NC)"
  421. start-full-stack: setup-openbao
  422. @echo "$(YELLOW)Starting full SeaweedFS + KMS stack...$(NC)"
  423. @$(DOCKER_COMPOSE) up -d
  424. @echo "$(YELLOW)Waiting for services to be ready...$(NC)"
  425. @sleep 15
  426. @echo "$(GREEN)✅ Full stack running!$(NC)"
  427. @echo "OpenBao: $(OPENBAO_ADDR)"
  428. @echo "S3 API: http://localhost:$(S3_PORT)"
  429. stop-full-stack:
  430. @echo "$(YELLOW)Stopping full stack...$(NC)"
  431. @$(DOCKER_COMPOSE) down
  432. @echo "$(GREEN)✅ Full stack stopped$(NC)"
  433. test-with-kms: start-full-stack
  434. @echo "$(YELLOW)Running SSE integration tests with real KMS...$(NC)"
  435. @sleep 5 # Extra time for KMS initialization
  436. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) ./test/s3/sse -run "SSE.*Integration" || (echo "$(RED)Tests failed$(NC)" && make stop-full-stack && exit 1)
  437. @echo "$(GREEN)✅ All KMS integration tests passed!$(NC)"
  438. @make stop-full-stack
  439. test-ssekms-integration: start-full-stack
  440. @echo "$(YELLOW)Running SSE-KMS integration tests with OpenBao...$(NC)"
  441. @sleep 5 # Extra time for KMS initialization
  442. @cd $(SEAWEEDFS_ROOT) && go test -v -timeout=$(TEST_TIMEOUT) ./test/s3/sse -run "TestSSEKMS.*Integration" || (echo "$(RED)SSE-KMS tests failed$(NC)" && make stop-full-stack && exit 1)
  443. @echo "$(GREEN)✅ SSE-KMS integration tests passed!$(NC)"
  444. @make stop-full-stack
  445. clean-kms:
  446. @echo "$(YELLOW)Cleaning up KMS test environment...$(NC)"
  447. @$(DOCKER_COMPOSE) down -v --remove-orphans || true
  448. @docker system prune -f || true
  449. @echo "$(GREEN)✅ KMS environment cleaned up!$(NC)"
  450. status-kms:
  451. @echo "$(YELLOW)KMS Environment Status:$(NC)"
  452. @$(DOCKER_COMPOSE) ps
  453. @echo ""
  454. @echo "$(YELLOW)OpenBao Health:$(NC)"
  455. @curl -s $(OPENBAO_ADDR)/v1/sys/health | jq '.' || echo "OpenBao not accessible"
  456. @echo ""
  457. @echo "$(YELLOW)S3 API Status:$(NC)"
  458. @curl -s http://localhost:$(S3_PORT) || echo "S3 API not accessible"
  459. # Quick test with just basic KMS functionality
  460. test-kms-quick: setup-openbao
  461. @echo "$(YELLOW)Running quick KMS functionality test...$(NC)"
  462. @cd ../../../test/kms && make dev-test
  463. @echo "$(GREEN)✅ Quick KMS test passed!$(NC)"
  464. # Development targets
  465. dev-kms: setup-openbao
  466. @echo "$(GREEN)Development environment ready$(NC)"
  467. @echo "OpenBao: $(OPENBAO_ADDR)"
  468. @echo "Token: $(OPENBAO_TOKEN)"
  469. @echo "Use 'make test-ssekms-integration' to run tests"