pasta: Fix pasta tests to work on hosts with multiple interfaces

At various points the pasta bats tests need to know the name of the
interface that pasta will use by default, and the host addresses it will
use by default.  Currently we use the pre-existing helper functions
ether_get_name and ipv[46]_get_addr_global to retreive that.

However, those just pick the first non-loopback interface or address, which
may not be the one that pasta uses if there are multiple connected host
interfaces.

Replace those helpers with local ones which examine the routing table to
more closely match pasta's internal logic about which interface to select.
This allows the tests to run successfully on a host with multiple
interfaces.

Closes: https://github.com/containers/podman/issues/19007

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson
2023-06-28 12:48:29 +10:00
parent 4dc2e08618
commit fe8355be7f

View File

@ -18,6 +18,21 @@ function setup() {
XFER_FILE="${PODMAN_TMPDIR}/pasta.bin" XFER_FILE="${PODMAN_TMPDIR}/pasta.bin"
} }
function default_ifname() {
local ip_ver="${1}"
local expr='[.[] | select(.dst == "default").dev] | .[0]'
ip -j -"${ip_ver}" route show | jq -rM "${expr}"
}
function default_addr() {
local ip_ver="${1}"
local ifname="${2:-$(default_ifname "${ip_ver}")}"
local expr='.[0] | .addr_info[0].local'
ip -j -"${ip_ver}" addr show "${ifname}" | jq -rM "${expr}"
}
# pasta_test_do() - Run tests involving clients and servers # pasta_test_do() - Run tests involving clients and servers
# $1: IP version: 4 or 6 # $1: IP version: 4 or 6
# $2: Interface type: "tap" or "loopback" # $2: Interface type: "tap" or "loopback"
@ -38,29 +53,26 @@ function pasta_test_do() {
# Calculate and set addresses, # Calculate and set addresses,
if [ ${ip_ver} -eq 4 ]; then if [ ${ip_ver} -eq 4 ]; then
skip_if_no_ipv4 "IPv4 not routable on the host" skip_if_no_ipv4 "IPv4 not routable on the host"
if [ ${iftype} = "loopback" ]; then
local addr="127.0.0.1"
else
local addr="$(ipv4_get_addr_global)"
fi
elif [ ${ip_ver} -eq 6 ]; then elif [ ${ip_ver} -eq 6 ]; then
skip_if_no_ipv6 "IPv6 not routable on the host" skip_if_no_ipv6 "IPv6 not routable on the host"
if [ ${iftype} = "loopback" ]; then if [ ${iftype} = "loopback" ]; then
local ifname="lo"
local addr="::1" local addr="::1"
else else
local addr="$(ipv6_get_addr_global)" local addr="$(ipv6_get_addr_default)"
fi fi
else else
skip "Unsupported IP version" skip "Unsupported IP version"
fi fi
# interface names,
if [ ${iftype} = "loopback" ]; then if [ ${iftype} = "loopback" ]; then
local ifname="lo" local ifname="lo"
else else
local ifname="$(ether_get_name)" local ifname="$(default_ifname "${ip_ver}")"
fi fi
local addr="$(default_addr "${ip_ver}" "${ifname}")"
# ports, # ports,
if [ ${range} -gt 1 ]; then if [ ${range} -gt 1 ]; then
local port="$(random_free_port_range ${range} ${addr} ${proto})" local port="$(random_free_port_range ${range} ${addr} ${proto})"
@ -168,7 +180,7 @@ function teardown() {
run_podman run --net=pasta $IMAGE ip -j -4 address show run_podman run --net=pasta $IMAGE ip -j -4 address show
local container_address="$(ipv4_get_addr_global "${output}")" local container_address="$(ipv4_get_addr_global "${output}")"
local host_address="$(ipv4_get_addr_global)" local host_address="$(default_addr 4)"
assert "${container_address}" = "${host_address}" \ assert "${container_address}" = "${host_address}" \
"Container address not matching host" "Container address not matching host"
@ -203,7 +215,7 @@ function teardown() {
run_podman run --net=pasta $IMAGE ip -j -6 address show run_podman run --net=pasta $IMAGE ip -j -6 address show
local container_address="$(ipv6_get_addr_global "${output}")" local container_address="$(ipv6_get_addr_global "${output}")"
local host_address="$(ipv6_get_addr_global)" local host_address="$(default_addr 6)"
assert "${container_address}" = "${host_address}" \ assert "${container_address}" = "${host_address}" \
"Container address not matching host" "Container address not matching host"