From 34ba26ec5263bff8061794e0657d7656837e9664 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 9 Jul 2024 11:08:52 +0200 Subject: [PATCH] test/system: fix pasta host.containers.internal test When a system has one ipv4 and one ipv6 address hostname -I will show both causing a failure in the case where this is only one address. To fix this stop using hostname -I and use ip -4 to only list v4 addresses and the use jq to filter the output accordingly. Fixes #23227 Signed-off-by: Paul Holzinger --- test/system/505-networking-pasta.bats | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/system/505-networking-pasta.bats b/test/system/505-networking-pasta.bats index fb9c517bf8..0f5da11636 100644 --- a/test/system/505-networking-pasta.bats +++ b/test/system/505-networking-pasta.bats @@ -800,6 +800,7 @@ EOF @test "pasta/bridge and host.containers.internal" { skip_if_no_ipv4 "IPv4 not routable on the host" pasta_ip="$(default_addr 4)" + host_ips=$(ip -4 -j addr | jq -r '.[] | select(.ifname != "lo") | .addr_info[].local') for network in "pasta" "bridge"; do # special exit code logic needed here, it is possible that there is no host.containers.internal @@ -808,17 +809,17 @@ EOF run_podman '?' run --rm --network=$network $IMAGE grep host.containers.internal /etc/hosts if [ "$status" -eq 0 ]; then assert "$output" !~ "$pasta_ip" "pasta host ip must not be assigned ($network)" - assert "$(hostname -I)" =~ "$(cut -f1 <<<$output)" "ip is one of the host ips ($network)" + assert "$host_ips" =~ "$(cut -f1 <<<$output)" "ip is one of the host ips ($network)" elif [ "$status" -eq 1 ]; then # if only pasta ip then we cannot have a host.containers.internal entry # make sure this fact is actually the case - assert "$pasta_ip" == "$(hostname -I | tr -d '[:space:]')" "pasta ip must the only one one the host ($network)" + assert "$pasta_ip" == "$host_ips" "pasta ip must the only one one the host ($network)" else die "unexpected exit code '$status' from grep or podman ($network)" fi done - host_ip=$(hostname -I | cut -f 1 -d " ") + first_host_ip=$(head -n 1 <<<"$host_ips") run_podman run --rm --network=pasta:-a,169.254.0.2,-g,169.254.0.1,-n,24 $IMAGE grep host.containers.internal /etc/hosts - assert "$output" =~ "^$host_ip" "uses host first ip" + assert "$output" =~ "^$first_host_ip" "uses host first ip" }