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