summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2024-07-26 14:08:09 +0200
committerPaul Holzinger <pholzing@redhat.com>2024-07-26 17:35:40 +0200
commitaa4ee013e599ae85a1fca8da181bab966f4ee360 (patch)
tree940797a60a920632d149ff11da2857a47886b00c
parent8575b7e97bb0e80d05546e069ad1e082ab256271 (diff)
test: add new test to check for startup error
Make sure the bind error is reported as expected. We have to use sleep as nc might take a moment before the port is bound. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r--test/600-errors.bats31
-rw-r--r--test/helpers.bash24
2 files changed, 43 insertions, 12 deletions
diff --git a/test/600-errors.bats b/test/600-errors.bats
new file mode 100644
index 0000000..1dcafb3
--- /dev/null
+++ b/test/600-errors.bats
@@ -0,0 +1,31 @@
+#!/usr/bin/env bats -*- bats -*-
+#
+# basic netavark tests
+#
+
+load helpers
+
+
+NCPID=
+
+function teardown() {
+ kill -9 $NCPID
+ basic_teardown
+}
+
+# check bind error on startup
+@test "aardvark-dns should fail when port is already bound" {
+ # bind the port to force a failure for aardvark-dns
+ # we cannot use run_is_host_netns to run in the background
+ nsenter -m -n -t $HOST_NS_PID nc -u -l 0.0.0.0 53 </dev/null 3> /dev/null &
+ NCPID=$!
+
+ # ensure nc has time to bind the port
+ sleep 1
+
+ subnet_a=$(random_subnet 5)
+ create_config network_name="podman1" container_id=$(random_string 64) container_name="aone" subnet="$subnet_a"
+ gw=$(echo "$config" | jq -r .network_info.podman1.subnets[0].gateway)
+ expected_rc=1 create_container "$config"
+ assert "$output" =~ "failed to bind udp listener on $gw:53" "bind error message"
+}
diff --git a/test/helpers.bash b/test/helpers.bash
index 9537af8..bd8faaf 100644
--- a/test/helpers.bash
+++ b/test/helpers.bash
@@ -501,8 +501,8 @@ EOF
function create_container() {
CONTAINER_NS_PID=$(create_netns)
CONTAINER_NS_PIDS+=("$CONTAINER_NS_PID")
- create_container_backend "$CONTAINER_NS_PID" "$1"
CONTAINER_CONFIGS+=("$1")
+ create_container_backend "$CONTAINER_NS_PID" "$1"
}
# arg1 is pid
@@ -559,17 +559,6 @@ function setup_slirp4netns() {
}
function basic_teardown() {
- rm -fr "$AARDVARK_TMPDIR"
-}
-
-################
-# netavark_teardown# tears down a network
-################
-function netavark_teardown() {
- run_netavark teardown $1 <<<"$2"
-}
-
-function teardown() {
# Now call netavark with all the configs and then kill the netns associated with it
for i in "${!CONTAINER_CONFIGS[@]}"; do
netavark_teardown $(get_container_netns_path "${CONTAINER_NS_PIDS[$i]}") "${CONTAINER_CONFIGS[$i]}"
@@ -587,6 +576,17 @@ function teardown() {
kill -9 "$HOST_NS_PID"
fi
+ rm -fr "$AARDVARK_TMPDIR"
+}
+
+################
+# netavark_teardown# tears down a network
+################
+function netavark_teardown() {
+ run_netavark teardown $1 <<<"$2"
+}
+
+function teardown() {
basic_teardown
}