github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/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_multi_consul_tests() {
   140      # Test multi node configuration with a global scope test driver backed by consul
   141  
   142      ## Setup
   143      start_dnet 1 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   144      cmap[dnet-1-multi_consul]=dnet-1-multi_consul
   145      start_dnet 2 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   146      cmap[dnet-2-multi_consul]=dnet-2-multi_consul
   147      start_dnet 3 multi_consul consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   148      cmap[dnet-3-multi_consul]=dnet-3-multi_consul
   149  
   150      ## Run the test cases
   151      ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
   152  
   153      ## Teardown
   154      stop_dnet 1 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   155      unset cmap[dnet-1-multi_consul]
   156      stop_dnet 2 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   157      unset cmap[dnet-2-multi_consul]
   158      stop_dnet 3 multi_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   159      unset cmap[dnet-3-multi_consul]
   160  }
   161  
   162  function run_multi_zk_tests() {
   163      # Test multi node configuration with a global scope test driver backed by zookeeper
   164  
   165      ## Setup
   166      start_dnet 1 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
   167      cmap[dnet-1-multi_zk]=dnet-1-multi_zk
   168      start_dnet 2 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
   169      cmap[dnet-2-multi_zk]=dnet-2-multi_zk
   170      start_dnet 3 multi_zk zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
   171      cmap[dnet-3-multi_zk]=dnet-3-multi_zk
   172  
   173      ## Run the test cases
   174      ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
   175  
   176      ## Teardown
   177      stop_dnet 1 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
   178      unset cmap[dnet-1-multi_zk]
   179      stop_dnet 2 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
   180      unset cmap[dnet-2-multi_zk]
   181      stop_dnet 3 multi_zk 1>>${INTEGRATION_ROOT}/test.log 2>&1
   182      unset cmap[dnet-3-multi_zk]
   183  }
   184  
   185  function run_multi_etcd_tests() {
   186      # Test multi node configuration with a global scope test driver backed by etcd
   187  
   188      ## Setup
   189      start_dnet 1 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   190      cmap[dnet-1-multi_etcd]=dnet-1-multi_etcd
   191      start_dnet 2 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   192      cmap[dnet-2-multi_etcd]=dnet-2-multi_etcd
   193      start_dnet 3 multi_etcd etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   194      cmap[dnet-3-multi_etcd]=dnet-3-multi_etcd
   195  
   196      ## Run the test cases
   197      ./integration-tmp/bin/bats ./test/integration/dnet/multi.bats
   198  
   199      ## Teardown
   200      stop_dnet 1 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   201      unset cmap[dnet-1-multi_etcd]
   202      stop_dnet 2 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   203      unset cmap[dnet-2-multi_etcd]
   204      stop_dnet 3 multi_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   205      unset cmap[dnet-3-multi_etcd]
   206  }
   207  
   208  source ./test/integration/dnet/helpers.bash
   209  
   210  if [ ! -d ${INTEGRATION_ROOT} ]; then
   211      mkdir -p ${INTEGRATION_ROOT}
   212      git clone https://github.com/sstephenson/bats.git ${INTEGRATION_ROOT}/bats
   213      ./integration-tmp/bats/install.sh ./integration-tmp
   214  fi
   215  
   216  if [ ! -d ${TMPC_ROOT} ]; then
   217      mkdir -p ${TMPC_ROOT}
   218      docker pull busybox:ubuntu
   219      docker export $(docker create busybox:ubuntu) > ${TMPC_ROOT}/busybox.tar
   220      mkdir -p ${TMPC_ROOT}/rootfs
   221      tar -C ${TMPC_ROOT}/rootfs -xf ${TMPC_ROOT}/busybox.tar
   222  fi
   223  
   224  # Suite setup
   225  
   226  if [ -z "$SUITES" ]; then
   227      if [ -n "$CIRCLECI" ]
   228      then
   229  	# We can only run a limited list of suites in circleci because of the
   230  	# old kernel and limited docker environment.
   231  	suites="dnet multi_consul multi_zk multi_etcd"
   232      else
   233  	suites="dnet multi_consul multi_zk multi_etcd  bridge overlay_consul overlay_consul_host overlay_zk overlay_etcd"
   234      fi
   235  else
   236      suites="$SUITES"
   237  fi
   238  
   239  if [[ ( "$suites" =~ .*consul.* ) ||  ( "$suites" =~ .*bridge.* ) ]]; then
   240      echo "Starting consul ..."
   241      start_consul 1>>${INTEGRATION_ROOT}/test.log 2>&1
   242      cmap[pr_consul]=pr_consul
   243  fi
   244  
   245  if [[ "$suites" =~ .*zk.* ]]; then
   246      echo "Starting zookeeper ..."
   247      start_zookeeper 1>>${INTEGRATION_ROOT}/test.log 2>&1
   248      cmap[zookeeper_server]=zookeeper_server
   249  fi
   250  
   251  if [[ "$suites" =~ .*etcd.* ]]; then
   252      echo "Starting etcd ..."
   253      start_etcd 1>>${INTEGRATION_ROOT}/test.log 2>&1
   254      cmap[dn_etcd]=dn_etcd
   255  fi
   256  
   257  echo ""
   258  
   259  for suite in ${suites};
   260  do
   261      suite_func=run_${suite}_tests
   262      echo "Running ${suite}_tests ..."
   263      declare -F $suite_func >/dev/null && $suite_func
   264      echo ""
   265  done