Skip to content

Commit 7e7fa9d

Browse files
committed
Merge pull request #710 from mrjana/bugs
Cleanup service db for the network on last container leave
2 parents c4c0c0b + 59c05f4 commit 7e7fa9d

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoi
367367
c.Lock()
368368
if len(nw.localEps) == 0 {
369369
close(nw.stopCh)
370+
371+
// This is the last container going away for the network. Destroy
372+
// this network's svc db entry
373+
delete(c.svcDb, ep.getNetwork().ID())
374+
370375
delete(nmap, ep.getNetwork().ID())
371376
}
372377
}

test/integration/dnet/helpers.bash

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,110 @@ function test_overlay() {
292292
dnet_cmd $(inst_id2port 2) network rm multihost
293293
}
294294

295+
function check_etchosts() {
296+
local dnet sbid retval
297+
dnet=${1}
298+
shift
299+
sbid=${1}
300+
shift
301+
302+
retval="true"
303+
304+
for i in $*;
305+
do
306+
run runc ${dnet} ${sbid} "cat /etc/hosts"
307+
if [ "$status" -ne 0 ]; then
308+
retval="${output}"
309+
break
310+
fi
311+
312+
line=$(echo ${output} | grep ${i})
313+
if [ "${line}" == "" ]; then
314+
retval="false"
315+
fi
316+
done
317+
318+
echo ${retval}
319+
}
320+
321+
function test_overlay_etchosts() {
322+
local clist dnet_suffix
323+
324+
dnet_suffix=$1
325+
shift
326+
327+
echo $(docker ps)
328+
329+
start=1
330+
end=3
331+
# Setup overlay network and connect containers ot it
332+
dnet_cmd $(inst_id2port 1) network create -d overlay multihost
333+
334+
for iter in `seq 1 2`;
335+
do
336+
for i in `seq ${start} ${end}`;
337+
do
338+
dnet_cmd $(inst_id2port $i) container create container_${iter}_${i}
339+
net_connect ${i} container_${iter}_${i} multihost
340+
done
341+
342+
# Now test the /etc/hosts content of all the containers
343+
for i in `seq ${start} ${end}`;
344+
do
345+
clist=""
346+
oldclist=""
347+
for j in `seq ${start} ${end}`;
348+
do
349+
if [ "$i" -eq "$j" ]; then
350+
continue
351+
fi
352+
clist="$clist container_${iter}_$j"
353+
oldclist="$oldclist container_1_$j"
354+
done
355+
rv=$(check_etchosts $(dnet_container_name $i $dnet_suffix) \
356+
$(get_sbox_id ${i} container_${iter}_${i}) \
357+
${clist})
358+
[ "$rv" = "true" ]
359+
360+
# check to see the containers don't have stale entries from previous iteration
361+
if [ "$iter" -eq 2 ]; then
362+
rv=$(check_etchosts $(dnet_container_name $i $dnet_suffix) \
363+
$(get_sbox_id ${i} container_${iter}_${i}) \
364+
${oldclist})
365+
[ "$rv" = "false" ]
366+
fi
367+
done
368+
369+
# Teardown the container connections and the network
370+
clist=""
371+
for i in `seq ${start} ${end}`;
372+
do
373+
net_disconnect ${i} container_${iter}_${i} multihost
374+
dnet_cmd $(inst_id2port $i) container rm container_${iter}_${i}
375+
376+
#check if the /etc/hosts of other containers does not contain this container
377+
for j in `seq ${start} ${end}`;
378+
do
379+
if [ "$i" -eq "$j" ]; then
380+
continue
381+
fi
382+
383+
if [[ "${clist}" =~ .*container_${iter}_${j}.* ]]; then
384+
continue
385+
fi
386+
387+
rv=$(check_etchosts $(dnet_container_name $j $dnet_suffix) \
388+
$(get_sbox_id ${j} container_${iter}_${j}) \
389+
container_${iter}_${i})
390+
[ "$rv" = "false" ]
391+
done
392+
clist="${clist} container_${iter}_${i}"
393+
done
394+
done
395+
396+
dnet_cmd $(inst_id2port 2) network rm multihost
397+
}
398+
295399
function test_overlay_singlehost() {
296400
dnet_suffix=$1
297401
shift

test/integration/dnet/overlay-consul.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ load helpers
1212
skip_for_circleci
1313
test_overlay_singlehost consul
1414
}
15+
16+
@test "test overlay network etc hosts with consul" {
17+
skip_for_circleci
18+
test_overlay_etchosts consul
19+
}

0 commit comments

Comments
 (0)