From 92f7f2e1a0a74b20c990423ac8646256d0ef2b86 Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Sat, 24 Oct 2015 17:45:34 -0700 Subject: [PATCH] Add IT case for proper /etc/hosts handling Added an IT case for checking proper /etc/hosts handling in the overlay network. This also to see if there are any stale entries in the /etc/hosts Signed-off-by: Jana Radhakrishnan --- libnetwork/test/integration/dnet/helpers.bash | 104 ++++++++++++++++++ .../test/integration/dnet/overlay-consul.bats | 5 + 2 files changed, 109 insertions(+) diff --git a/libnetwork/test/integration/dnet/helpers.bash b/libnetwork/test/integration/dnet/helpers.bash index d66ac38f6d..3c19116925 100644 --- a/libnetwork/test/integration/dnet/helpers.bash +++ b/libnetwork/test/integration/dnet/helpers.bash @@ -292,6 +292,110 @@ function test_overlay() { dnet_cmd $(inst_id2port 2) network rm multihost } +function check_etchosts() { + local dnet sbid retval + dnet=${1} + shift + sbid=${1} + shift + + retval="true" + + for i in $*; + do + run runc ${dnet} ${sbid} "cat /etc/hosts" + if [ "$status" -ne 0 ]; then + retval="${output}" + break + fi + + line=$(echo ${output} | grep ${i}) + if [ "${line}" == "" ]; then + retval="false" + fi + done + + echo ${retval} +} + +function test_overlay_etchosts() { + local clist dnet_suffix + + dnet_suffix=$1 + shift + + echo $(docker ps) + + start=1 + end=3 + # Setup overlay network and connect containers ot it + dnet_cmd $(inst_id2port 1) network create -d overlay multihost + + for iter in `seq 1 2`; + do + for i in `seq ${start} ${end}`; + do + dnet_cmd $(inst_id2port $i) container create container_${iter}_${i} + net_connect ${i} container_${iter}_${i} multihost + done + + # Now test the /etc/hosts content of all the containers + for i in `seq ${start} ${end}`; + do + clist="" + oldclist="" + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + clist="$clist container_${iter}_$j" + oldclist="$oldclist container_1_$j" + done + rv=$(check_etchosts $(dnet_container_name $i $dnet_suffix) \ + $(get_sbox_id ${i} container_${iter}_${i}) \ + ${clist}) + [ "$rv" = "true" ] + + # check to see the containers don't have stale entries from previous iteration + if [ "$iter" -eq 2 ]; then + rv=$(check_etchosts $(dnet_container_name $i $dnet_suffix) \ + $(get_sbox_id ${i} container_${iter}_${i}) \ + ${oldclist}) + [ "$rv" = "false" ] + fi + done + + # Teardown the container connections and the network + clist="" + for i in `seq ${start} ${end}`; + do + net_disconnect ${i} container_${iter}_${i} multihost + dnet_cmd $(inst_id2port $i) container rm container_${iter}_${i} + + #check if the /etc/hosts of other containers does not contain this container + for j in `seq ${start} ${end}`; + do + if [ "$i" -eq "$j" ]; then + continue + fi + + if [[ "${clist}" =~ .*container_${iter}_${j}.* ]]; then + continue + fi + + rv=$(check_etchosts $(dnet_container_name $j $dnet_suffix) \ + $(get_sbox_id ${j} container_${iter}_${j}) \ + container_${iter}_${i}) + [ "$rv" = "false" ] + done + clist="${clist} container_${iter}_${i}" + done + done + + dnet_cmd $(inst_id2port 2) network rm multihost +} + function test_overlay_singlehost() { dnet_suffix=$1 shift diff --git a/libnetwork/test/integration/dnet/overlay-consul.bats b/libnetwork/test/integration/dnet/overlay-consul.bats index 856aab07c3..23d3ab0ca3 100644 --- a/libnetwork/test/integration/dnet/overlay-consul.bats +++ b/libnetwork/test/integration/dnet/overlay-consul.bats @@ -12,3 +12,8 @@ load helpers skip_for_circleci test_overlay_singlehost consul } + +@test "test overlay network etc hosts with consul" { + skip_for_circleci + test_overlay_etchosts consul +}