diff --git a/xCAT-test/bats/ipv6_configeth_install_nic.bats b/xCAT-test/bats/ipv6_configeth_install_nic.bats index 1baa8061a9..cd7de1df90 100644 --- a/xCAT-test/bats/ipv6_configeth_install_nic.bats +++ b/xCAT-test/bats/ipv6_configeth_install_nic.bats @@ -81,3 +81,77 @@ IPSTUB run run_discover '' '3: ens3 inet6 fe80::1/64 scope link' [ "$status" -ne 0 ] } + +# --------------------------------------------------------------------------- +# The keyfile configeth renders during Anaconda's chrooted %post. +# +# nmcli cannot persist a connection into the target root there, so the profile is rendered with +# "nmcli --offline" into a temporary file and moved into place. A node whose profile keeps IPv4 +# enabled waits for a DHCPv4 lease that never arrives, and a temporary file left behind in +# system-connections is read by NetworkManager as a second profile for the same interface. + +# render_keyfile -- run the real function with nmcli stubbed to +# echo the arguments it was given, so the profile shows what reached it. +render_keyfile() +{ + local file lib bin keyfile="$1" rc="$2" + file="$(require_repo_file 'xCAT/postscripts/configeth')" + lib="${BATS_TEST_TMPDIR}/keyfile.sh" + extract_shell_function "$file" 'configure_install_nic_ipv6_connection' >"$lib" || return 1 + extract_shell_function "$file" 'configure_install_nic_ipv6_keyfile' >>"$lib" || return 1 + + bin="${BATS_TEST_TMPDIR}/bin" + mkdir -p "$bin" + cat >"$bin/nmcli" <"$LIB" + + BIN="${BATS_TEST_TMPDIR}/bin" + mkdir -p "$BIN" + : >"${BATS_TEST_TMPDIR}/addr6" + : >"${BATS_TEST_TMPDIR}/addr4" + : >"${BATS_TEST_TMPDIR}/route6" + cat >"$BIN/ip" <<'IPSTUB' +#!/bin/sh +case "$*" in +*"-6 -o addr show"*) cat "${BATS_TEST_TMPDIR}/addr6" ;; +*"-4 -o addr show"*) cat "${BATS_TEST_TMPDIR}/addr4" ;; +*"-6 route show default"*) cat "${BATS_TEST_TMPDIR}/route6" ;; +*) exit 1 ;; +esac +IPSTUB + chmod 0755 "$BIN/ip" +} + +# is_ipv6_boot -- run the real decision +is_ipv6_boot() +{ + PATH="$BIN:$PATH" BATS_TEST_TMPDIR="$BATS_TEST_TMPDIR" bash -c ' + . "$1" + xcat_is_ipv6_boot "$2" "$3" + ' bash "$LIB" "$1" "$2" +} + +@test "the dracut dhcp6 forms are an IPv6 boot, whatever the interface holds" { + for arg in 'dhcp6' 'eth0:dhcp6' 'eth0:dhcp6:something'; do + run is_ipv6_boot "$arg" '' + [ "$status" -eq 0 ] + done +} + +@test "a global IPv6 address and no IPv4 address is an IPv6 boot" { + printf '3: eth0 inet6 2001:db8:149::20/64 scope global\n' >"${BATS_TEST_TMPDIR}/addr6" + run is_ipv6_boot 'ip=[2001:db8:149::20]::::::none' eth0 + [ "$status" -eq 0 ] +} + +@test "a dual-stack interface is not an IPv6 boot" { + printf '3: eth0 inet6 2001:db8:149::20/64 scope global\n' >"${BATS_TEST_TMPDIR}/addr6" + printf '3: eth0 inet 192.0.2.20/24 scope global\n' >"${BATS_TEST_TMPDIR}/addr4" + run is_ipv6_boot 'ip=dhcp' eth0 + [ "$status" -ne 0 ] +} + +@test "an interface with no global IPv6 address is not an IPv6 boot" { + run is_ipv6_boot 'ip=dhcp' eth0 + [ "$status" -ne 0 ] +} + +@test "an IPv4 form with no interface named is not an IPv6 boot" { + printf '3: eth0 inet6 2001:db8:149::20/64 scope global\n' >"${BATS_TEST_TMPDIR}/addr6" + run is_ipv6_boot 'ip=dhcp' '' + [ "$status" -ne 0 ] +} + +# persist [sources...] +persist() +{ + PATH="$BIN:$PATH" BATS_TEST_TMPDIR="$BATS_TEST_TMPDIR" bash -c ' + lib="$1"; shift + . "$lib" + persist_ipv6_nm_connection "$@" + ' bash "$LIB" "$@" +} + +@test "a profile the initrd already holds is copied into the new root" { + local root="${BATS_TEST_TMPDIR}/root" src="${BATS_TEST_TMPDIR}/run-nm" + mkdir -p "$root" "$src" + printf '[connection]\nid=live\n' >"$src/live.nmconnection" + run persist "$root" eth0 'aa:bb:cc:dd:ee:ff' "$src" + [ "$status" -eq 0 ] + [ -f "$root/etc/NetworkManager/system-connections/live.nmconnection" ] + grep -q '^id=live$' "$root/etc/NetworkManager/system-connections/live.nmconnection" + [ "$(stat -c '%a' "$root/etc/NetworkManager/system-connections/live.nmconnection")" = '600' ] +} + +@test "with no profile to copy one is written from the live address" { + local root="${BATS_TEST_TMPDIR}/root" profile + mkdir -p "$root" + printf '3: eth0 inet6 2001:db8:149::20/64 scope global\n' >"${BATS_TEST_TMPDIR}/addr6" + printf 'default via 2001:db8:149::1 dev eth0 metric 100\n' >"${BATS_TEST_TMPDIR}/route6" + run persist "$root" eth0 'aa:bb:cc:dd:ee:ff' "${BATS_TEST_TMPDIR}/absent" + [ "$status" -eq 0 ] + profile="$root/etc/NetworkManager/system-connections/xcat-eth0.nmconnection" + [ -f "$profile" ] + grep -q '^address1=2001:db8:149::20/64$' "$profile" + grep -q '^gateway=2001:db8:149::1$' "$profile" + grep -q '^mac-address=aa:bb:cc:dd:ee:ff$' "$profile" + [ "$(stat -c '%a' "$profile")" = '600' ] +} + +# A profile that leaves IPv4 on makes NetworkManager wait for a DHCPv4 lease that never comes, +# and systemd-networkd-wait-online fails the boot it was meant to complete. +@test "the written profile disables IPv4 and sets IPv6 manually" { + local root="${BATS_TEST_TMPDIR}/root" profile + mkdir -p "$root" + printf '3: eth0 inet6 2001:db8:149::20/64 scope global\n' >"${BATS_TEST_TMPDIR}/addr6" + run persist "$root" eth0 'aa:bb:cc:dd:ee:ff' "${BATS_TEST_TMPDIR}/absent" + [ "$status" -eq 0 ] + profile="$root/etc/NetworkManager/system-connections/xcat-eth0.nmconnection" + grep -q '^method=disabled$' "$profile" + grep -q '^method=manual$' "$profile" + refute_grep -q '^method=auto$' "$profile" +} + +# Writing a profile with an empty address1 is worse than writing none: NetworkManager refuses the +# file and the interface is left unmanaged, with no record of why. +@test "no live address and nothing to copy is a failure, not an empty profile" { + local root="${BATS_TEST_TMPDIR}/root" + mkdir -p "$root" + run persist "$root" eth0 'aa:bb:cc:dd:ee:ff' "${BATS_TEST_TMPDIR}/absent" + [ "$status" -ne 0 ] + refute_grep -q . <(ls "$root/etc/NetworkManager/system-connections") +}