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