run-integration-tests.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/usr/bin/env bash
  2. set -e
  3. export INTEGRATION_ROOT=./integration-tmp
  4. export TMPC_ROOT=./integration-tmp/tmpc
  5. declare -A cmap
  6. trap "cleanup_containers" EXIT SIGINT
  7. function cleanup_containers() {
  8. for c in "${!cmap[@]}";
  9. do
  10. docker stop $c 1>>${INTEGRATION_ROOT}/test.log 2>&1 || true
  11. if [ -z "$CIRCLECI" ]; then
  12. docker rm -f $c 1>>${INTEGRATION_ROOT}/test.log 2>&1 || true
  13. fi
  14. done
  15. unset cmap
  16. }
  17. function run_bridge_tests() {
  18. ## Setup
  19. start_dnet 1 bridge 1>>${INTEGRATION_ROOT}/test.log 2>&1
  20. cmap[dnet-1-bridge]=dnet-1-bridge
  21. ## Run the test cases
  22. ./integration-tmp/bin/bats ./test/integration/dnet/bridge.bats
  23. ## Teardown
  24. stop_dnet 1 bridge 1>>${INTEGRATION_ROOT}/test.log 2>&1
  25. unset cmap[dnet-1-bridge]
  26. }
  27. function run_overlay_local_tests() {
  28. ## Test overlay network in local scope
  29. ## Setup
  30. start_dnet 1 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
  31. cmap[dnet-1-local]=dnet-1-local
  32. start_dnet 2 local:$(dnet_container_ip 1 local) 1>>${INTEGRATION_ROOT}/test.log 2>&1
  33. cmap[dnet-2-local]=dnet-2-local
  34. start_dnet 3 local:$(dnet_container_ip 1 local) 1>>${INTEGRATION_ROOT}/test.log 2>&1
  35. cmap[dnet-3-local]=dnet-3-local
  36. ## Run the test cases
  37. ./integration-tmp/bin/bats ./test/integration/dnet/overlay-local.bats
  38. ## Teardown
  39. stop_dnet 1 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
  40. unset cmap[dnet-1-local]
  41. stop_dnet 2 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
  42. unset cmap[dnet-2-local]
  43. stop_dnet 3 local 1>>${INTEGRATION_ROOT}/test.log 2>&1
  44. unset cmap[dnet-3-local]
  45. }
  46. function run_overlay_consul_tests() {
  47. ## Test overlay network with consul
  48. ## Setup
  49. start_dnet 1 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  50. cmap[dnet-1-consul]=dnet-1-consul
  51. start_dnet 2 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  52. cmap[dnet-2-consul]=dnet-2-consul
  53. start_dnet 3 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  54. cmap[dnet-3-consul]=dnet-3-consul
  55. ## Run the test cases
  56. ./integration-tmp/bin/bats ./test/integration/dnet/overlay-consul.bats
  57. ## Teardown
  58. stop_dnet 1 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  59. unset cmap[dnet-1-consul]
  60. stop_dnet 2 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  61. unset cmap[dnet-2-consul]
  62. stop_dnet 3 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  63. unset cmap[dnet-3-consul]
  64. }
  65. function run_overlay_consul_host_tests() {
  66. export _OVERLAY_HOST_MODE="true"
  67. ## Setup
  68. start_dnet 1 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  69. cmap[dnet-1-consul]=dnet-1-consul
  70. ## Run the test cases
  71. ./integration-tmp/bin/bats ./test/integration/dnet/overlay-consul-host.bats
  72. ## Teardown
  73. stop_dnet 1 consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  74. unset cmap[dnet-1-consul]
  75. unset _OVERLAY_HOST_MODE
  76. }
  77. function run_overlay_zk_tests() {
  78. ## Test overlay network with zookeeper
  79. start_dnet 1 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  80. cmap[dnet-1-zookeeper]=dnet-1-zookeeper
  81. start_dnet 2 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  82. cmap[dnet-2-zookeeper]=dnet-2-zookeeper
  83. start_dnet 3 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  84. cmap[dnet-3-zookeeper]=dnet-3-zookeeper
  85. ./integration-tmp/bin/bats ./test/integration/dnet/overlay-zookeeper.bats
  86. stop_dnet 1 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  87. unset cmap[dnet-1-zookeeper]
  88. stop_dnet 2 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  89. unset cmap[dnet-2-zookeeper]
  90. stop_dnet 3 zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  91. unset cmap[dnet-3-zookeeper]
  92. }
  93. function run_overlay_etcd_tests() {
  94. ## Test overlay network with etcd
  95. start_dnet 1 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  96. cmap[dnet-1-etcd]=dnet-1-etcd
  97. start_dnet 2 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  98. cmap[dnet-2-etcd]=dnet-2-etcd
  99. start_dnet 3 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  100. cmap[dnet-3-etcd]=dnet-3-etcd
  101. ./integration-tmp/bin/bats ./test/integration/dnet/overlay-etcd.bats
  102. stop_dnet 1 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  103. unset cmap[dnet-1-etcd]
  104. stop_dnet 2 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  105. unset cmap[dnet-2-etcd]
  106. stop_dnet 3 etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  107. unset cmap[dnet-3-etcd]
  108. }
  109. function run_dnet_tests() {
  110. # Test dnet configuration options
  111. ./integration-tmp/bin/bats ./test/integration/dnet/dnet.bats
  112. }
  113. function run_multi_consul_tests() {
  114. # Test multi node configuration with a global scope test driver backed by consul
  115. ## Setup
  116. start_dnet 1 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  117. cmap[dnet-1-multi_consul]=dnet-1-multi_consul
  118. start_dnet 2 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  119. cmap[dnet-2-multi_consul]=dnet-2-multi_consul
  120. start_dnet 3 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  121. cmap[dnet-3-multi_consul]=dnet-3-multi_consul
  122. ## Run the test cases
  123. ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
  124. ## Teardown
  125. stop_dnet 1 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  126. unset cmap[dnet-1-multi_consul]
  127. stop_dnet 2 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  128. unset cmap[dnet-2-multi_consul]
  129. stop_dnet 3 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  130. unset cmap[dnet-3-multi_consul]
  131. }
  132. function run_multi_zk_tests() {
  133. # Test multi node configuration with a global scope test driver backed by zookeeper
  134. ## Setup
  135. start_dnet 1 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  136. cmap[dnet-1-multi_zk]=dnet-1-multi_zk
  137. start_dnet 2 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  138. cmap[dnet-2-multi_zk]=dnet-2-multi_zk
  139. start_dnet 3 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  140. cmap[dnet-3-multi_zk]=dnet-3-multi_zk
  141. ## Run the test cases
  142. ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
  143. ## Teardown
  144. stop_dnet 1 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
  145. unset cmap[dnet-1-multi_zk]
  146. stop_dnet 2 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
  147. unset cmap[dnet-2-multi_zk]
  148. stop_dnet 3 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
  149. unset cmap[dnet-3-multi_zk]
  150. }
  151. function run_multi_etcd_tests() {
  152. # Test multi node configuration with a global scope test driver backed by etcd
  153. ## Setup
  154. start_dnet 1 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  155. cmap[dnet-1-multi_etcd]=dnet-1-multi_etcd
  156. start_dnet 2 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  157. cmap[dnet-2-multi_etcd]=dnet-2-multi_etcd
  158. start_dnet 3 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  159. cmap[dnet-3-multi_etcd]=dnet-3-multi_etcd
  160. ## Run the test cases
  161. ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
  162. ## Teardown
  163. stop_dnet 1 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  164. unset cmap[dnet-1-multi_etcd]
  165. stop_dnet 2 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  166. unset cmap[dnet-2-multi_etcd]
  167. stop_dnet 3 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  168. unset cmap[dnet-3-multi_etcd]
  169. }
  170. source ./test/integration/dnet/helpers.bash
  171. if [ ! -d ${INTEGRATION_ROOT} ]; then
  172. mkdir -p ${INTEGRATION_ROOT}
  173. git clone https://github.com/sstephenson/bats.git ${INTEGRATION_ROOT}/bats
  174. ./integration-tmp/bats/install.sh ./integration-tmp
  175. fi
  176. if [ ! -d ${TMPC_ROOT} ]; then
  177. mkdir -p ${TMPC_ROOT}
  178. docker pull busybox:ubuntu
  179. docker export $(docker create busybox:ubuntu) > ${TMPC_ROOT}/busybox.tar
  180. mkdir -p ${TMPC_ROOT}/rootfs
  181. tar -C ${TMPC_ROOT}/rootfs -xf ${TMPC_ROOT}/busybox.tar
  182. fi
  183. # Suite setup
  184. if [ -z "$SUITES" ]; then
  185. if [ -n "$CIRCLECI" ]
  186. then
  187. # We can only run a limited list of suites in circleci because of the
  188. # old kernel and limited docker environment.
  189. suites="dnet multi_consul multi_zk multi_etcd"
  190. else
  191. suites="dnet multi_consul multi_zk multi_etcd bridge overlay_consul overlay_consul_host overlay_zk overlay_etcd"
  192. fi
  193. else
  194. suites="$SUITES"
  195. fi
  196. if [[ ( "$suites" =~ .*consul.* ) || ( "$suites" =~ .*bridge.* ) ]]; then
  197. echo "Starting consul ..."
  198. start_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
  199. cmap[pr_consul]=pr_consul
  200. fi
  201. if [[ "$suites" =~ .*zk.* ]]; then
  202. echo "Starting zookeeper ..."
  203. start_zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
  204. cmap[zookeeper_server]=zookeeper_server
  205. fi
  206. if [[ "$suites" =~ .*etcd.* ]]; then
  207. echo "Starting etcd ..."
  208. start_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
  209. cmap[dn_etcd]=dn_etcd
  210. fi
  211. echo ""
  212. for suite in ${suites};
  213. do
  214. suite_func=run_${suite}_tests
  215. echo "Running ${suite}_tests ..."
  216. declare -F $suite_func >/dev/null && $suite_func
  217. echo ""
  218. done