run-integration-tests.sh 7.9 KB

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