Skip to content

Commit

Permalink
test/system: Add support for multipath routes in pasta networking tests
Browse files Browse the repository at this point in the history
In some environments, such as the one described in
#20927, the default route
is given as nexthop gateways. That is, it's a multipath routes with
multiple gateways.

That means that pasta(1), after commit 6c7623d07bbd ("netlink: Add
support to fetch default gateway from multipath routes"), can start
and use a default gateway from that route.

Just like in pasta(1), in these tests, the default route indicates
which upstream interface we should pick. If we ignore multipath
routes, IPv6 addresses and gateway addresses themselves won't be
available, so, while pasta is now able to configure the container,
IPv6 tests will expect to find no address and no gateway, hence fail
due to the mismatch.

Try to get routes, including gateway addresses and interface names,
from nexthop objects, in case the selection of a regular default
route yields no results.

Link: #20927
Closes: #20927
Signed-off-by: Stefano Brivio <[email protected]>
  • Loading branch information
sbrivio-rh committed Mar 18, 2024
1 parent f5abca4 commit 23433ec
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions test/system/helpers.network.bash
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,31 @@ EOF
# ipv4_get_route_default() - Print first default IPv4 route reported by netlink
# $1: Optional output of 'ip -j -4 route show' from a different context
function ipv4_get_route_default() {
local jq_expr='[.[] | select(.dst == "default").gateway] | .[0]'
echo "${1:-$(ip -j -4 route show)}" | jq -rM "${jq_expr}"
local jq_gw='[.[] | select(.dst == "default").gateway] | .[0]'
local jq_nh='[.[] | select(.dst == "default").nexthops[0].gateway] | .[0]'
local out

out="$(echo "${1:-$(ip -j -4 route show)}" | jq -rM "${jq_gw}")"
if [ "${out}" = "null" ]; then
out="$(echo "${1:-$(ip -j -4 route show)}" | jq -rM "${jq_nh}")"
fi

echo "${out}"
}

# ipv6_get_route_default() - Print first default IPv6 route reported by netlink
# $1: Optional output of 'ip -j -6 route show' from a different context
function ipv6_get_route_default() {
local jq_expr='[.[] | select(.dst == "default").gateway] | .[0]'
echo "${1:-$(ip -j -6 route show)}" | jq -rM "${jq_expr}"
local jq_gw='[.[] | select(.dst == "default").gateway] | .[0]'
local jq_nh='[.[] | select(.dst == "default").nexthops[0].gateway] | .[0]'
local out

out="$(echo "${1:-$(ip -j -6 route show)}" | jq -rM "${jq_gw}")"
if [ "${out}" = "null" ]; then
out="$(echo "${1:-$(ip -j -6 route show)}" | jq -rM "${jq_nh}")"
fi

echo "${out}"
}

# ether_get_mtu() - Get MTU of first Ethernet-like link
Expand Down Expand Up @@ -373,10 +389,17 @@ function tcp_port_probe() {
### Pasta Helpers ##############################################################

function default_ifname() {
local jq_expr='[.[] | select(.dst == "default").dev] | .[0]'
local jq_expr_nh='[.[] | select(.dst == "default").nexthops[0].dev] | .[0]'
local ip_ver="${1}"
local out

out="$(ip -j -"${ip_ver}" route show | jq -rM "${jq_expr}")"
if [ "${out}" = "null" ]; then
out="$(ip -j -"${ip_ver}" route show | jq -rM "${jq_expr_nh}")"
fi

local expr='[.[] | select(.dst == "default").dev] | .[0]'
ip -j -"${ip_ver}" route show | jq -rM "${expr}"
echo "${out}"
}

function default_addr() {
Expand Down

0 comments on commit 23433ec

Please sign in to comment.