Skip to content

Commit aef1169

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 aef1169

File tree

3 files changed

+68
-72
lines changed

3 files changed

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

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)