From 4d5ca9964e8c5648b640558cf62609ebfe804328 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:59:07 -0300 Subject: [PATCH] test(ipv6): shell under test is written in bats, not in a .t Seven of the ported unit files drive shell: they run bash -n on a product script, cut a function out of it with a regex and eval the copy, or write a fake executable into PATH. A .t runs Perl in process, so each one tested its own scaffolding as much as the product, and a reformat of the script would break it while a move of the code would not. The five bats files replace them and use the existing shell_source helper. ipv6_endpoint_helpers drives the four separate copies of xcat_endpoint_host from one table, because the scripts carry a copy each -- xcatroot runs in the dracut initrd, xcatpostinit1.netboot before /xcatpost exists, xcatinstallpost in the installer root -- and the copies must agree. ipv6_xcatdsklspost_endpoints uses XCATDSKLSPOST_SOURCE_ONLY to load the real parsehttpserver and format_host_port and asserts a bracketed authority survives a round trip. ipv6_syslog_forwarding covers the rsyslog bracket and the syslog-ng udp6 driver. ipv6_configeth_install_nic drives discover_install_nic_ipv6 against recorded "ip -6 addr show" output and pins that a temporary, tentative, deprecated or dadfailed address is never chosen. ipv6_updateflag_awk runs updateflag.awk against a loopback listener of each family and pins the bracket stripping. Each assertion was run against the unfixed script and fails there. Two gaps stay: allowcred.awk has no coverage, and the /inet6/ prefix updateflag.awk chooses cannot be covered, because gawk 5.3.0 reaches an IPv6 literal through /inet/ as well. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../bats/ipv6_configeth_install_nic.bats | 83 ++++++ xCAT-test/bats/ipv6_endpoint_helpers.bats | 132 ++++++++++ xCAT-test/bats/ipv6_syslog_forwarding.bats | 80 ++++++ xCAT-test/bats/ipv6_updateflag_awk.bats | 109 ++++++++ .../bats/ipv6_xcatdsklspost_endpoints.bats | 55 ++++ xCAT-test/unit/configeth_ipv6_installnic.t | 237 ------------------ xCAT-test/unit/el10_ipv6_runtime.t | 145 ----------- xCAT-test/unit/el10_stateless_xcatroot_ipv6.t | 182 -------------- xCAT-test/unit/initrd_syslog_ipv6.t | 67 ----- xCAT-test/unit/postboot_ipv6_endpoints.t | 92 ------- xCAT-test/unit/syslog_ipv6_forwarding.t | 92 ------- xCAT-test/unit/xcatdsklspost_ipv6.t | 81 ------ 12 files changed, 459 insertions(+), 896 deletions(-) create mode 100644 xCAT-test/bats/ipv6_configeth_install_nic.bats create mode 100644 xCAT-test/bats/ipv6_endpoint_helpers.bats create mode 100644 xCAT-test/bats/ipv6_syslog_forwarding.bats create mode 100644 xCAT-test/bats/ipv6_updateflag_awk.bats create mode 100644 xCAT-test/bats/ipv6_xcatdsklspost_endpoints.bats delete mode 100644 xCAT-test/unit/configeth_ipv6_installnic.t delete mode 100644 xCAT-test/unit/el10_ipv6_runtime.t delete mode 100644 xCAT-test/unit/el10_stateless_xcatroot_ipv6.t delete mode 100644 xCAT-test/unit/initrd_syslog_ipv6.t delete mode 100644 xCAT-test/unit/postboot_ipv6_endpoints.t delete mode 100644 xCAT-test/unit/syslog_ipv6_forwarding.t delete mode 100644 xCAT-test/unit/xcatdsklspost_ipv6.t diff --git a/xCAT-test/bats/ipv6_configeth_install_nic.bats b/xCAT-test/bats/ipv6_configeth_install_nic.bats new file mode 100644 index 0000000000..1baa8061a9 --- /dev/null +++ b/xCAT-test/bats/ipv6_configeth_install_nic.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats +# +# configeth replaces the connection the installer created for the install NIC. +# On an IPv6 install it has to read the live address back first, and a DHCPv6 +# lease is not written to the dhclient lease file the IPv4 path reads, so the +# address comes from "ip -6 addr show" instead. An address marked temporary, +# tentative, deprecated or dadfailed is not usable and must not be chosen. + +load 'helpers/shell_source' + +# run_discover -- returns the chosen CIDR +run_discover() +{ + local file lib bin + file="$(require_repo_file 'xCAT/postscripts/configeth')" + lib="${BATS_TEST_TMPDIR}/configeth.sh" + extract_shell_function "$file" 'discover_install_nic_ipv6' >"$lib" || return 1 + + bin="${BATS_TEST_TMPDIR}/bin" + mkdir -p "$bin" + printf '%s\n' "$2" >"${BATS_TEST_TMPDIR}/addr" + cat >"$bin/ip" <<'IPSTUB' +#!/bin/sh +case "$*" in +*"-6 -o addr show"*) + # The real ip(8) applies "scope global"; the stub has to as well, or a + # link-local address reaches a caller that asked for a global one. + case "$*" in + *"scope global"*) grep -v 'scope link' "${BATS_TEST_TMPDIR}/addr" || true ;; + *) cat "${BATS_TEST_TMPDIR}/addr" ;; + esac + ;; +*"-6 route show default"*) echo "default via 2001:db8::1 dev ens3 metric 100" ;; +*"-o link show"*) echo "2: ens3: mtu 9000 state UP" ;; +*) exit 1 ;; +esac +IPSTUB + # A test that reaches NetworkManager measures the host, not this function. + printf '#!/bin/sh\nexit 1\n' >"$bin/nmcli" + chmod 0755 "$bin"/* + + PATH="$bin:$PATH" BATS_TEST_TMPDIR="$BATS_TEST_TMPDIR" bash -c ' + . "$1" + discover_install_nic_ipv6 ens3 "$2" || exit $? + printf "%s/%s %s %s\n" "$str_inst_ipv6" "$str_inst_ipv6_prefix" \ + "$str_inst_ipv6_gateway" "$str_inst_mtu" + ' bash "$lib" "$1" +} + +@test "a single global address is chosen with its prefix, gateway and MTU" { + run run_discover '' '3: ens3 inet6 2001:db8::50/64 scope global \ valid_lifetime forever preferred_lft forever' + [ "$status" -eq 0 ] + [ "$output" = '2001:db8::50/64 2001:db8::1 9000' ] +} + +@test "a temporary privacy address is not chosen over a stable one" { + run run_discover '' '3: ens3 inet6 2001:db8::dead/64 scope global temporary dynamic +3: ens3 inet6 2001:db8::50/64 scope global dynamic' + [ "$status" -eq 0 ] + [ "${output% * *}" = '2001:db8::50/64' ] +} + +@test "a tentative, deprecated or dadfailed address is never chosen" { + local flag + for flag in tentative deprecated dadfailed; do + run run_discover '' "3: ens3 inet6 2001:db8::bad/64 scope global $flag +3: ens3 inet6 2001:db8::50/64 scope global dynamic" + [ "$status" -eq 0 ] + [ "${output% * *}" = '2001:db8::50/64' ] + done +} + +@test "the address xCAT asked for wins over the first usable one" { + run run_discover '2001:db8::99' '3: ens3 inet6 2001:db8::50/64 scope global dynamic +3: ens3 inet6 2001:db8::99/64 scope global dynamic' + [ "$status" -eq 0 ] + [ "${output% * *}" = '2001:db8::99/64' ] +} + +@test "no usable global address is a failure, not an empty answer" { + run run_discover '' '3: ens3 inet6 fe80::1/64 scope link' + [ "$status" -ne 0 ] +} diff --git a/xCAT-test/bats/ipv6_endpoint_helpers.bats b/xCAT-test/bats/ipv6_endpoint_helpers.bats new file mode 100644 index 0000000000..55fe57c89d --- /dev/null +++ b/xCAT-test/bats/ipv6_endpoint_helpers.bats @@ -0,0 +1,132 @@ +#!/usr/bin/env bats +# +# Every xCAT endpoint a node reads is "host:port", and an IPv6 literal already +# contains colons. Four scripts carry a helper that splits such a value and +# reassembles it with brackets. They are separate copies because a node has no +# shared shell library at the point each one runs: xcatroot runs inside the +# dracut initrd, xcatpostinit1.netboot before /xcatpost is populated, and +# xcatinstallpost in the installer root. The copies must agree, so each one is +# driven with the same table. + +load 'helpers/shell_source' + +ENDPOINT_SCRIPTS=( + 'xCAT/postscripts/xcatinstallpost' + 'xCAT/postscripts/xcatpostinit1.netboot' + 'xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot' +) + +# host_for