mirror of https://github.com/containers/podman.git
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 <pholzing@redhat.com>
This commit is contained in:
parent
abf0350529
commit
34ba26ec52
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue