Make ConfigureIPTables idempotent and poll it

- Instead of EnsureBridge
- Adds ipset.ExistEntry method
- Refactor ipset method names Exist <-> EntryExists
- Turn on iptable-refresh by default (10s)
- Adds a test that checks iptables are refreshed, check EXPOSE recovers
This commit is contained in:
Simon Howe committed 2020-07-15 11:35:41 +02:00
1 parent 1ff09fd4d1
commit 94e75e45af
8 files changed
+228 -74

No files matched your search

+20 -1
View File
@@ -27,6 +27,10 @@ exec_on1() {
assert_raises "exec_on $HOST1 $@"
}
wait_for_iptable_refresh() {
sleep 2
}
# Containers in the same subnet should be able to talk; different subnet not.
check_container_connectivity() {
exec_on1 "c1 $PING $C2"
@@ -39,7 +43,7 @@ check_container_connectivity() {
start_suite "exposing weave network to host"
weave_on $HOST1 launch --ipalloc-range $UNIVERSE
weave_on $HOST1 launch --ipalloc-range $UNIVERSE --iptables-refresh-interval=1s
start_container $HOST1 $C1/24 --name=c1
start_container $HOST1 $C2/24 --name=c2
@@ -61,11 +65,20 @@ weave_on1 "expose $EXP/24"
run_on1 "! $PING $C1"
run_on1 " $PING $C3"
run_on1 "! $PING $C5"
wait_for_iptable_refresh
run_on1 "! $PING $C1"
run_on1 " $PING $C3"
run_on1 "! $PING $C5"
weave_on1 "expose"
weave_on1 "expose"
run_on1 "! $PING $C1"
run_on1 " $PING $C3"
run_on1 " $PING $C5"
wait_for_iptable_refresh
run_on1 "! $PING $C1"
run_on1 " $PING $C3"
run_on1 " $PING $C5"
check_container_connectivity
# no host connectivity after 'hide', and idempotence of 'hide'
@@ -73,9 +86,15 @@ weave_on1 "hide $EXP/24"
weave_on1 "hide $EXP/24"
run_on1 "! $PING $C3"
run_on1 " $PING $C5"
wait_for_iptable_refresh
run_on1 "! $PING $C3"
run_on1 " $PING $C5"
weave_on1 "hide"
weave_on1 "hide"
run_on1 "! $PING $C5"
wait_for_iptable_refresh
run_on1 "! $PING $C5"
# remote host connectivity after 'expose'
docker_on $HOST1 exec -d c3 nc -l -p $PORT
+69
View File
@@ -0,0 +1,69 @@
#!/bin/bash
. "$(dirname "$0")/config.sh"
run_on1() {
assert_raises "run_on $HOST1 $@"
}
weave_on1() {
assert_raises "weave_on $HOST1 $@"
}
stop_weave_on1() {
assert_raises "stop_weave_on $HOST1 $@"
}
get_weave_iptable_rules() {
get_command_output_on $HOST1 "sudo iptables-save | grep -i weave"
}
wait_for_iptable_refresh() {
sleep 2
}
start_suite "exposing weave network to host"
# Launch
## Check no refreshing
weave_on1 "launch --iptables-refresh-interval=0s"
IPT_BEFORE=$(get_weave_iptable_rules)
run_on1 "sudo iptables -t nat -D POSTROUTING -j WEAVE"
wait_for_iptable_refresh
IPT_AFTER=$(get_weave_iptable_rules)
assert_raises "diff <(echo $IPT_BEFORE) <(echo $IPT_AFTER)" 1
stop_weave_on1
## Check refreshing
weave_on1 "launch --iptables-refresh-interval=1s"
IPT_BEFORE=$(get_weave_iptable_rules)
run_on1 "sudo iptables -t nat -D POSTROUTING -j WEAVE"
wait_for_iptable_refresh
IPT_AFTER=$(get_weave_iptable_rules)
assert_raises "diff <(echo $IPT_BEFORE) <(echo $IPT_AFTER)" 0
stop_weave_on1
# Expose
## Check no refreshing
weave_on1 "launch --iptables-refresh-interval=0s"
weave_on1 "expose"
IPT_BEFORE=$(get_weave_iptable_rules)
run_on1 "sudo iptables -D FORWARD -o weave -j WEAVE-EXPOSE"
wait_for_iptable_refresh
IPT_AFTER=$(get_weave_iptable_rules)
assert_raises "diff <(echo $IPT_BEFORE) <(echo $IPT_AFTER)" 1
stop_weave_on1
## Check refreshing
weave_on1 "launch --iptables-refresh-interval=1s"
weave_on1 "expose"
IPT_BEFORE=$(get_weave_iptable_rules)
run_on1 "sudo iptables -D FORWARD -o weave -j WEAVE-EXPOSE"
wait_for_iptable_refresh
IPT_AFTER=$(get_weave_iptable_rules)
assert_raises "diff <(echo $IPT_BEFORE) <(echo $IPT_AFTER)" 0
stop_weave_on1
end_suite