Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Move firewalld tests into one file #994

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions test/100-bridge-iptables.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1021,43 +1021,6 @@ EOF
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
}

@test "$fw_driver - test firewalld reload" {
setup_firewalld

run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)

check_simple_bridge_iptables
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "iptables" "firewall-driver file content"

run_in_host_netns firewall-cmd --reload

# After a firewalld reload we expect rules to be deleted
# expected_rc=1 run_in_host_netns iptables -S NETAVARK_FORWARD
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
# we are added to trusted.
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "" "no trusted sources"

# start reload service on start it should restore the rules
run_netavark_firewalld_reload

# this run in the background so give it some time to add the rules
sleep 1
check_simple_bridge_iptables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"

run_in_host_netns firewall-cmd --reload
sleep 1
check_simple_bridge_iptables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
}

@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
test_port_fw firewalld_reload=true
}

function check_simple_bridge_iptables() {
# check iptables POSTROUTING chain
run_in_host_netns iptables -S POSTROUTING -t nat
Expand Down
64 changes: 64 additions & 0 deletions test/200-bridge-firewalld.bats
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,67 @@ function setup() {
expected_rc=1 run_netavark -f ${TESTSDIR}/testfiles/invalid-port.json setup $(get_container_netns_path)
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
}

@test "$fw_driver - test firewalld reload" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to fix the test name to use the real driver and make the test use NETAVARK_FW=iptables run_netavark ... to set the correct driver.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The change is in the latest PR now.

NETAVARK_FW=iptables run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)

check_simple_bridge_iptables
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "iptables" "firewall-driver file content"

run_in_host_netns firewall-cmd --reload

# After a firewalld reload we expect rules to be deleted
# expected_rc=1 run_in_host_netns iptables -S NETAVARK_FORWARD
# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
# we are added to trusted.
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "" "no trusted sources"

# start reload service on start it should restore the rules
run_netavark_firewalld_reload

# this run in the background so give it some time to add the rules
sleep 1
check_simple_bridge_iptables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"

run_in_host_netns firewall-cmd --reload
sleep 1
check_simple_bridge_iptables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
}

@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
test_port_fw firewalld_reload=true
}

@test "$fw_driver - test firewalld reload" {
NETAVARK_FW=nftables run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)

check_simple_bridge_nftables
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "nftables" "firewall-driver file content"

run_in_host_netns firewall-cmd --reload

# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
# we are added to trusted.
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "" "no trusted sources"

# start reload service on start it should restore the rules
run_netavark_firewalld_reload

# this run in the background so give it some time to add the rules
sleep 1
check_simple_bridge_nftables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"

run_in_host_netns firewall-cmd --reload
sleep 1
check_simple_bridge_nftables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
}
35 changes: 0 additions & 35 deletions test/250-bridge-nftables.bats
Original file line number Diff line number Diff line change
Expand Up @@ -914,41 +914,6 @@ EOF
assert_json ".error" "invalid host ip \"abcd\" provided for port 8080" "host ip error"
}

@test "$fw_driver - test firewalld reload" {
setup_firewalld

run_netavark --file ${TESTSDIR}/testfiles/simplebridge.json setup $(get_container_netns_path)

check_simple_bridge_nftables
assert "$(<$NETAVARK_TMPDIR/config/firewall/firewall-driver)" "==" "nftables" "firewall-driver file content"

run_in_host_netns firewall-cmd --reload

# There was a firewalld change in 3.0 that it no longer flushes all rules, howver we can still check if
# we are added to trusted.
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "" "no trusted sources"

# start reload service on start it should restore the rules
run_netavark_firewalld_reload

# this run in the background so give it some time to add the rules
sleep 1
check_simple_bridge_nftables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after start"

run_in_host_netns firewall-cmd --reload
sleep 1
check_simple_bridge_nftables
run_in_host_netns firewall-cmd --zone=trusted --list-sources
assert "$output" == "10.88.0.0/16" "container subnet is trusted after reload"
}

@test "$fw_driver - port forwarding ipv4 - tcp with firewalld reload" {
test_port_fw firewalld_reload=true
}

function check_simple_bridge_nftables() {
# check nftables POSTROUTING chain
run_in_host_netns nft list chain inet netavark POSTROUTING
Expand Down