Skip to content

Commit 54c80de

Browse files
author
Mingli Yu
committed
test: Move firewalld tests into one file
Moving firewalld related tests into one file should be convenient for the user who doesn't care firewalld. Signed-off-by: Mingli Yu <[email protected]>
1 parent 967304f commit 54c80de

File tree

3 files changed

+64
-72
lines changed

3 files changed

+64
-72
lines changed

test/100-bridge-iptables.bats

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,43 +1021,6 @@ EOF
10211021
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
10221022
}
10231023

1024-
@test "$fw_driver - test firewalld reload" {
1025-
setup_firewalld
1026-
1027-
run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)
1028-
1029-
check_simple_bridge_iptables
1030-
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "iptables" "firewall-driver file content"
1031-
1032-
run_in_host_netns firewall-cmd --reload
1033-
1034-
# After a firewalld reload we expect rules to be deleted
1035-
# expected_rc=1 run_in_host_netns iptables -S NETAVARK_FORWARD
1036-
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
1037-
# we are added to trusted.
1038-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
1039-
assert "$output" == "" "no trusted sources"
1040-
1041-
# start reload service on start it should restore the rules
1042-
run_netavark_firewalld_reload
1043-
1044-
# this run in the background so give it some time to add the rules
1045-
sleep 1
1046-
check_simple_bridge_iptables
1047-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
1048-
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"
1049-
1050-
run_in_host_netns firewall-cmd --reload
1051-
sleep 1
1052-
check_simple_bridge_iptables
1053-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
1054-
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
1055-
}
1056-
1057-
@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
1058-
test_port_fw firewalld_reload=true
1059-
}
1060-
10611024
function check_simple_bridge_iptables() {
10621025
# check iptables POSTROUTING chain
10631026
run_in_host_netns iptables -S POSTROUTING -t nat

test/200-bridge-firewalld.bats

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,67 @@ function setup() {
329329
expected_rc=1 run_netavark -f ${TESTSDIR}/testfiles/invalid-port.json setup $(get_container_netns_path)
330330
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
331331
}
332+
333+
@test "$fw_driver - test firewalld reload" {
334+
NETAVARK_FW=iptables run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)
335+
336+
check_simple_bridge_iptables
337+
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "iptables" "firewall-driver file content"
338+
339+
run_in_host_netns firewall-cmd --reload
340+
341+
# After a firewalld reload we expect rules to be deleted
342+
# expected_rc=1 run_in_host_netns iptables -S NETAVARK_FORWARD
343+
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
344+
# we are added to trusted.
345+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
346+
assert "$output" == "" "no trusted sources"
347+
348+
# start reload service on start it should restore the rules
349+
run_netavark_firewalld_reload
350+
351+
# this run in the background so give it some time to add the rules
352+
sleep 1
353+
check_simple_bridge_iptables
354+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
355+
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"
356+
357+
run_in_host_netns firewall-cmd --reload
358+
sleep 1
359+
check_simple_bridge_iptables
360+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
361+
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
362+
}
363+
364+
@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
365+
test_port_fw firewalld_reload=true
366+
}
367+
368+
@test "$fw_driver - test firewalld reload" {
369+
NETAVARK_FW=nftables run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)
370+
371+
check_simple_bridge_nftables
372+
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "nftables" "firewall-driver file content"
373+
374+
run_in_host_netns firewall-cmd --reload
375+
376+
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
377+
# we are added to trusted.
378+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
379+
assert "$output" == "" "no trusted sources"
380+
381+
# start reload service on start it should restore the rules
382+
run_netavark_firewalld_reload
383+
384+
# this run in the background so give it some time to add the rules
385+
sleep 1
386+
check_simple_bridge_nftables
387+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
388+
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"
389+
390+
run_in_host_netns firewall-cmd --reload
391+
sleep 1
392+
check_simple_bridge_nftables
393+
run_in_host_netns firewall-cmd --zone=trusted --list-sources
394+
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
395+
}

test/250-bridge-nftables.bats

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -914,41 +914,6 @@ EOF
914914
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
915915
}
916916

917-
@test "$fw_driver - test firewalld reload" {
918-
setup_firewalld
919-
920-
run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)
921-
922-
check_simple_bridge_nftables
923-
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "nftables" "firewall-driver file content"
924-
925-
run_in_host_netns firewall-cmd --reload
926-
927-
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
928-
# we are added to trusted.
929-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
930-
assert "$output" == "" "no trusted sources"
931-
932-
# start reload service on start it should restore the rules
933-
run_netavark_firewalld_reload
934-
935-
# this run in the background so give it some time to add the rules
936-
sleep 1
937-
check_simple_bridge_nftables
938-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
939-
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"
940-
941-
run_in_host_netns firewall-cmd --reload
942-
sleep 1
943-
check_simple_bridge_nftables
944-
run_in_host_netns firewall-cmd --zone=trusted --list-sources
945-
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
946-
}
947-
948-
@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
949-
test_port_fw firewalld_reload=true
950-
}
951-
952917
function check_simple_bridge_nftables() {
953918
# check nftables POSTROUTING chain
954919
run_in_host_netns nft list chain inet netavark POSTROUTING

0 commit comments

Comments
 (0)