Skip to content

Commit

Permalink
Merge pull request #19053 from edsantiago/pasta_test_cleanup
Browse files Browse the repository at this point in the history
pasta system tests: cleanup, fixes, sanity check
  • Loading branch information
openshift-merge-robot authored Jun 30, 2023
2 parents acaaf3d + 2393fe4 commit 5561390
Showing 1 changed file with 69 additions and 6 deletions.
75 changes: 69 additions & 6 deletions test/system/505-networking-pasta.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,68 @@ function pasta_test_do() {
local bind_type="${6}"
local bytes="${7}"

# DO NOT ADD ANY CODE ABOVE THIS LINE! Especially skips: that could
# lead to the crossreference check not running in CI.
#
# BATS has no table-driven test generation mechanism, so there's a
# disturbing but unavoidable amount of duplication in the test
# invocations. The code below is a desperate sanity check to confirm
# that the BATS test name agrees with the parameters we're invoked with.
# This test can never, ever fail in gating. It can only fail in CI
# when a new test is added, and should be trivial to fix & re-push.
#
# TODO: a better idea might be to go the other direction: eliminate
# the function args entirely, and determine them from $BATS_TEST_NAME.
# We would still need a way to get $range and $bytes.
local expected_test_name=
if [[ $bytes -eq 1 ]]; then
# The usual case: a single-byte transfer test. This has many
# variations depending on our input args
if [[ $range -eq 1 ]]; then
# e.g., Single TCP port forwarding, IPv4, loopback
if [[ $delta -ne 0 ]]; then
expected_test_name+="Translated"
elif [[ "${bind_type}" = "port" ]]; then
expected_test_name+="Single"
else
expected_test_name+="${bind_type^}-bound"
fi
expected_test_name+=" ${proto^^} port"
else
# e.g., TCP translated port range forwarding, IPv4, tap
expected_test_name+="${proto^^}"
if [[ $delta -ne 0 ]]; then
expected_test_name+=" translated"
fi
expected_test_name+=" port range"
fi
expected_test_name+=" forwarding, IPv${ip_ver}, ${iftype}"
else
# Multi-byte. 2k is the common size for small, all else is large
local size="large"
if [[ $bytes = "2k" ]]; then
size="small"
fi
expected_test_name="${proto^^}/IPv${ip_ver} $size transfer, ${iftype}"

# No other input args are variable.
assert "$range" = "1" "range must = 1 on multibyte transfers"
assert "$delta" = "0" "delta must = 0 on multibyte transfers"
assert "$bind_type" = "port" "bind_type must = 'port' on multibyte transfers"
fi

# Normalize test name back to human-readable form: strip common prefix,
# convert '-XX' to chr (dashes, commas) and underscore to space.
# Sorry this is so convoluted.
local actual_test_name=$(printf "$(sed \
-e 's/^test_podman_networking_with_pasta-281-29_-2d_//' \
-e 's/-\([0-9a-f]\{2\}\)/\\x\1/gI' \
-e 's/_/ /g' \
<<<"${BATS_TEST_NAME}")")

assert "$actual_test_name" = "$expected_test_name" \
"INTERNAL ERROR! Mismatch between BATS test name and test args!"

# Calculate and set addresses,
if [ ${ip_ver} -eq 4 ]; then
skip_if_no_ipv4 "IPv4 not routable on the host"
Expand All @@ -75,7 +137,7 @@ function pasta_test_do() {
local xseq="$(echo ${xport} | tr '-' ' ')"
else
local port=$(random_free_port "" ${address} ${proto})
local xport="$((port + port_delta))"
local xport="$((port + delta))"
local seq="${port} ${port}"
local xseq="${xport} ${xport}"
fi
Expand All @@ -99,9 +161,6 @@ function pasta_test_do() {
recv="EXEC:md5sum"
fi

# socat first address
send="OPEN:${XFER_FILE}"

# and port forwarding configuration for Podman and pasta.
#
# TODO: Use Podman options once/if
Expand Down Expand Up @@ -145,7 +204,7 @@ function pasta_test_do() {
local connect="${proto_upper}${ip_ver}:[${addr}]:${one_port}"
[ "${proto}" = "udp" ] && connect="${connect},shut-null"

(while sleep ${delay} && ! socat -u "${send}" "${connect}"; do :
(while sleep ${delay} && ! socat -u "OPEN:${XFER_FILE}" "${connect}"; do :
done) &
done

Expand Down Expand Up @@ -715,9 +774,13 @@ function teardown() {
mac="9a:dd:31:ea:92:98"
cat >$containersconf <<EOF
[network]
default_rootless_network_cmd = "pasta"
pasta_options = ["-I", "myname", "--ns-mac-addr", "$mac"]
EOF
CONTAINERS_CONF_OVERRIDE=$containersconf run_podman run --net=pasta $IMAGE ip link show myname

# 2023-06-29 DO NOT INCLUDE "--net=pasta" on this line!
# This tests containers.conf:default_rootless_network_cmd (pr #19032)
CONTAINERS_CONF_OVERRIDE=$containersconf run_podman run $IMAGE ip link show myname
assert "$output" =~ "$mac" "mac address is set on custom interface"

# now, again but this time overwrite a option on the cli.
Expand Down

0 comments on commit 5561390

Please sign in to comment.