From d74285f4a2cf9301245e7a28901d667ba1860266 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:31:41 -0300 Subject: [PATCH 1/2] fix(xcat-core): an EL 8 or EL 9 IPv6-only node installs with a DHCPv6 address that holds no reservation An IPv6-only EL 8 or EL 9 node presents a different DHCPv6 DUID at each boot stage: the UEFI firmware, then iPXE, then anaconda. makedhcp reserves the first two, so the installer takes an address from the dynamic range and every step that reads the reserved address or its PTR record fails. xCAT::SvrUtils::uses_static_ipv6_boot accepted the rh family only at major 10, so Template.pm rendered "dhcp --noipv4 --ipv6=dhcp" for EL 8 and EL 9. The floor is now 8, by operator decision of 2026-11-05. pre.rhels8 was IPv4 only in two places. The install monitor opened an AF_INET socket, so the node reported no status. The install server was cut out of its URL at the first colon, which splits an IPv6 literal. Both forms come from pre.rhels10. pre.openeuler includes pre.rhels8 whole, so this also fixes the reported openEuler defect. ipv6_pre_rhels8.bats and the EL 8 and EL 9 cases of template_ipv6_rendering.t capture it. With AF_UNSPEC back to AF_INET the three IPv6 monitor cases fail and the IPv4 one passes. Without the bracket branch the three IPv6 URL cases fail and the four IPv4 ones pass. With the floor back at 10 the EL 8 and EL 9 rendering cases fail and the EL 10 ones pass. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- .../advanced/networks/ipv6_provisioning.rst | 3 +- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 11 +- .../share/xcat/install/scripts/pre.rhels8 | 68 +++++-- xCAT-test/bats/ipv6_pre_rhels8.bats | 187 ++++++++++++++++++ xCAT-test/unit/anaconda_ipv6_rendering.t | 6 +- xCAT-test/unit/template_ipv6_rendering.t | 22 ++- 6 files changed, 273 insertions(+), 24 deletions(-) create mode 100644 xCAT-test/bats/ipv6_pre_rhels8.bats diff --git a/docs/source/advanced/networks/ipv6_provisioning.rst b/docs/source/advanced/networks/ipv6_provisioning.rst index 19c19766d8..dd99122b7c 100644 --- a/docs/source/advanced/networks/ipv6_provisioning.rst +++ b/docs/source/advanced/networks/ipv6_provisioning.rst @@ -65,9 +65,8 @@ range, so the range is required. ================ ========================================================================= Family Handoff to the installer ================ ========================================================================= -EL 10 ``ip=`` with the address, from ``uses_static_ipv6_boot`` +EL 8 and later ``ip=`` with the address, from ``uses_static_ipv6_boot`` openEuler ``ip=`` with the address, from ``uses_static_ipv6_boot`` -EL 8, EL 9 DHCPv6 in the install initrd, which solicits as a third client Ubuntu, diskless ``ip=`` with the address, from ``dracut_static_ip6`` Ubuntu, diskful ``ip6=dhcp``, and casper runs ``dhcpcd -6`` as a third client SLES, openSUSE ``ipv6only=1 hostip=
/``, from ``static_ipv6_boot_args`` diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index 7417f4c653..cd8aedb08e 100644 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -2289,14 +2289,15 @@ sub uses_static_ipv6_boot # openEuler reaches the same kickstart and dracut code as EL through #KICKSTARTNET#. return 1 if $basename =~ /^openeuler$/i; - # EL 10 is where xCAT implemented and tested this, not where the installer gained the - # option: EL 9 already takes "--noipv4 --ipv6=dhcp" from the same template. Extending it - # downwards is untested rather than impossible. The comparison is not an equality so that - # a later release keeps it; is_el10_os tested for 10 exactly and left EL 11 on DHCPv6. + # The static form is the one xCAT tests, on EL 10. EL 8 and EL 9 take it by operator + # decision of 2026-11-05: their anaconda reads the same "network --noipv4 --ipv6=" + # options from the same template, and their dracut reads the same "ip=" argument. + # The comparison is not an equality so that a later release keeps it; is_el10_os + # tested for 10 exactly and left EL 11 on DHCPv6. return 1 if $basename =~ /^(?:rh\w*|centos|alma|rocky|ol)$/i && $majorversion =~ /^\d+$/ - && $majorversion >= 10; + && $majorversion >= 8; return 0; } diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels8 b/xCAT-server/share/xcat/install/scripts/pre.rhels8 index b9900825b7..144f85564b 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels8 @@ -32,8 +32,9 @@ cat >/tmp/baz.py <<'EOF' import socket import sys -sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) +# create_connection resolves the master and connects in whichever family it +# answers in. socket(AF_INET) could only reach an IPv4 management node. +sock = socket.create_connection(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) print(sys.argv[1]) response = sock.recv(100) @@ -52,8 +53,37 @@ import os import linecache import re -sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -sock.connect(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) +# The install monitor must listen in the family the management node reaches it +# in. An AF_INET listener gave an IPv6-only node a socket xcatd cannot open, so +# the node reported no status for the whole installation. +def create_listen_socket(port, master): + last_error = None + master_addresses = socket.getaddrinfo(master, None, socket.AF_UNSPEC, + socket.SOCK_STREAM) + seen_families = set() + for master_family, socktype, proto, canonname, master_sockaddr in master_addresses: + if master_family in seen_families: + continue + seen_families.add(master_family) + listen_addresses = socket.getaddrinfo( + None, port, master_family, socket.SOCK_STREAM, 0, socket.AI_PASSIVE) + for family, socktype, proto, canonname, sockaddr in listen_addresses: + listen_sock = socket.socket(family, socktype, proto) + listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + if family == socket.AF_INET6 and hasattr(socket, 'IPV6_V6ONLY'): + listen_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1) + try: + listen_sock.bind(sockaddr) + listen_sock.listen(5) + return listen_sock + except OSError as error: + last_error = error + listen_sock.close() + if last_error: + raise last_error + raise OSError('no usable address for install monitor') + +sock = socket.create_connection(('#XCATVAR:XCATMASTER#',#TABLE:site:key=xcatiport:value#)) response = sock.recv(100) if(response == b"ready\n"): @@ -62,13 +92,8 @@ if(response == b"ready\n"): sock.close() -sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - port = 3054 -sock.bind(('', port)) - -sock.listen(5) +sock = create_listen_socket(port, '#XCATVAR:XCATMASTER#') try: while 1: @@ -316,9 +341,26 @@ msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/v # The following code is to generate the repository for the installation cat /proc/cmdline -NEXTSERVER="$(grep -m 1 http /proc/cmdline)" -NEXTSERVER="${NEXTSERVER#*http://}" -NEXTSERVER="${NEXTSERVER%%:*}" +# The host of a URL. An IPv6 literal is bracketed and holds colons, so cutting +# the authority at the first colon returned a fragment of the address. +extract_url_host() +{ + local authority="${1#*://}" + + authority="${authority%%/*}" + case "$authority" in + \[*\]*) + authority="${authority#\[}" + printf '%s\n' "${authority%%\]*}" + ;; + *) + printf '%s\n' "${authority%%:*}" + ;; + esac +} + +NEXTSERVER_URL="$(grep -oE 'https?://(\[[^]]+\]|[^[:space:]/:]+)(:[0-9]+)?' /proc/cmdline | head -n 1)" +NEXTSERVER="$(extract_url_host "$NEXTSERVER_URL")" export nextserver="$NEXTSERVER" #INSTALL_SOURCES_IN_PRE# diff --git a/xCAT-test/bats/ipv6_pre_rhels8.bats b/xCAT-test/bats/ipv6_pre_rhels8.bats new file mode 100644 index 0000000000..03f4cecf83 --- /dev/null +++ b/xCAT-test/bats/ipv6_pre_rhels8.bats @@ -0,0 +1,187 @@ +#!/usr/bin/env bats +# +# pre.rhels8 runs in the EL8 and EL9 installers, and pre.openeuler includes it +# whole. It embeds the install monitor xCAT asks for node status, and it reads +# the install server out of the kernel command line. Both were IPv4 only: the +# monitor opened an AF_INET socket, and the server was cut out of the URL at +# the first colon, which splits an IPv6 literal. +# +# The monitor tests render the embedded program the way xCAT renders it, run +# it, and speak its protocol. Everything is on the loopback addresses of this +# host; nothing reaches the lab. + +load 'helpers/shell_source' + +# The port the embedded install monitor listens on. It is fixed in the script. +MONITOR_PORT=3054 + +setup() +{ + SCRIPT="$(require_repo_file 'xCAT-server/share/xcat/install/scripts/pre.rhels8')" + command -v socat >/dev/null || skip 'socat is required' + command -v ss >/dev/null || skip 'ss is required' + MONITOR="${BATS_TEST_TMPDIR}/install-monitor.py" + XCATD_PORT=$(( 20000 + RANDOM % 20000 )) + XCATD_PID= + MONITOR_PID= +} + +teardown() +{ + [ -n "$MONITOR_PID" ] && kill "$MONITOR_PID" 2>/dev/null + [ -n "$XCATD_PID" ] && kill "$XCATD_PID" 2>/dev/null + return 0 +} + +# wait_for_port -- the listener is read from ss rather than by +# connecting, because a probe connection is a peer the monitor would answer. +wait_for_port() +{ + local i + for i in $(seq 1 100); do + ss -Hltn "sport = :$1" 2>/dev/null | grep -q . && return 0 + sleep 0.1 + done + return 1 +} + +# start_monitor -- render the install monitor pre.rhels8 embeds, fill +# its two substitution tokens the way xCAT fills them, serve the one handshake +# it makes to xcatd, then start it. +start_monitor() +{ + local master="$1" family listen handler + command -v python3 >/dev/null || skip 'python3 is required' + + awk "/^cat >\\/tmp\\/foo.py <<'EOF'\$/ { copy = 1; next } + copy && /^EOF\$/ { exit } + copy { print }" "$SCRIPT" \ + | sed -e "s|#XCATVAR:XCATMASTER#|${master}|g" \ + -e "s|#TABLE:site:key=xcatiport:value#|${XCATD_PORT}|g" >"$MONITOR" + [ -s "$MONITOR" ] || return 1 + ! grep -q '#XCATVAR:\|#ENV:\|#TABLE:' "$MONITOR" || return 1 + + case "$master" in + *:*) family='TCP6' ;; + *) family='TCP4' ;; + esac + listen="bind=${master}" + + # The handshake is two lines: xcatd sends "ready", the monitor sends the + # name it registers under, xcatd answers anything. + handler="${BATS_TEST_TMPDIR}/xcatd.sh" + cat >"$handler" <<'HANDLER' +#!/bin/bash +printf 'ready\n' +IFS= read -r registered +printf '%s\n' "$registered" >"$REGISTERED" +printf 'ok\n' +HANDLER + chmod 0755 "$handler" + REGISTERED="${BATS_TEST_TMPDIR}/registered" + : >"$REGISTERED" + # Detach the stdio of both children: one holding the test's pipes open + # makes a failure hang instead of go red. + REGISTERED="$REGISTERED" setsid socat \ + "${family}-LISTEN:${XCATD_PORT},${listen},reuseaddr" "EXEC:$handler" \ + /dev/null 2>&1 & + XCATD_PID=$! + wait_for_port "$XCATD_PORT" || return 1 + + setsid python3 "$MONITOR" /dev/null 2>&1 & + MONITOR_PID=$! + wait_for_port "$MONITOR_PORT" +} + +# ask -- send one monitor command, print the answer. +ask() +{ + printf '%s\n' "$2" | socat -T3 - "$1" 2>/dev/null +} + +@test "an IPv6 master address makes the EL8 install monitor listen on IPv6" { + start_monitor '::1' + run ask "TCP6:[::1]:${MONITOR_PORT}" 'stat' + [ "$status" -eq 0 ] + [ "$output" = 'installing prep' ] +} + +@test "an IPv6 master address makes the EL8 install monitor refuse IPv4" { + start_monitor '::1' + run ask "TCP4:127.0.0.1:${MONITOR_PORT}" 'stat' + [ "$output" != 'installing prep' ] +} + +@test "an IPv4 master address makes the EL8 install monitor listen on IPv4" { + start_monitor '127.0.0.2' + run ask "TCP4:127.0.0.2:${MONITOR_PORT},bind=127.0.0.2" 'stat' + [ "$status" -eq 0 ] + [ "$output" = 'installing prep' ] +} + +@test "the EL8 install monitor registers itself with xcatd over IPv6" { + start_monitor '::1' + run cat "${BATS_TEST_TMPDIR}/registered" + [ "$output" = 'installmonitor' ] +} + +# extract_url_host and the expression that feeds it. The install server is read +# out of /proc/cmdline, where an IPv6-only install writes a bracketed authority. +url_host() +{ + local lib="${BATS_TEST_TMPDIR}/url.sh" + extract_shell_function "$SCRIPT" 'extract_url_host' >"$lib" || return 1 + # shellcheck disable=SC1090 + . "$lib" + extract_url_host "$1" +} + +@test "an IPv4 EL8 install URL yields its address" { + run url_host 'http://192.0.2.1/install/rhels8.10/x86_64' + [ "$status" -eq 0 ] + [ "$output" = '192.0.2.1' ] +} + +@test "an IPv4 EL8 install URL with a port yields the address without the port" { + run url_host 'http://192.0.2.1:8080/install/rhels8.10/x86_64' + [ "$output" = '192.0.2.1' ] +} + +@test "a bracketed IPv6 EL8 install URL yields the address without the brackets" { + run url_host 'http://[2001:db8::1]/install/rhels8.10/x86_64' + [ "$output" = '2001:db8::1' ] +} + +@test "a bracketed IPv6 EL8 install URL with a port yields only the address" { + run url_host 'http://[2001:db8::1]:8080/install/rhels8.10/x86_64' + [ "$output" = '2001:db8::1' ] +} + +@test "a hostname EL8 install URL yields the hostname" { + run url_host 'https://mn01.cluster.example/install/rhels9.6/x86_64' + [ "$output" = 'mn01.cluster.example' ] +} + +# The expression that finds the install URL in the kernel command line, taken +# from the script rather than retyped, so a change to it is measured here. +cmdline_host() +{ + local expression url + expression="$(sed -n "s/^NEXTSERVER_URL=\"\$(grep -oE '\(.*\)' \/proc\/cmdline.*\$/\1/p" \ + "$SCRIPT")" + [ -n "$expression" ] || return 1 + url="$(printf '%s\n' "$1" | grep -oE "$expression" | head -n 1)" + url_host "$url" +} + +@test "the install server is found in an IPv6 EL9 kernel command line" { + run cmdline_host 'ro inst.repo=http://[2001:db8::1]:8080/install/rhels9.6/x86_64 inst.ks=http://[2001:db8::1]:8080/install/autoinst/node01' + [ "$status" -eq 0 ] + [ "$output" = '2001:db8::1' ] +} + +@test "the install server is found in an IPv4 EL8 kernel command line" { + run cmdline_host 'ro inst.repo=http://192.0.2.1:8080/install/rhels8.10/x86_64' + [ "$status" -eq 0 ] + [ "$output" = '192.0.2.1' ] +} diff --git a/xCAT-test/unit/anaconda_ipv6_rendering.t b/xCAT-test/unit/anaconda_ipv6_rendering.t index bc850268ed..b553787180 100644 --- a/xCAT-test/unit/anaconda_ipv6_rendering.t +++ b/xCAT-test/unit/anaconda_ipv6_rendering.t @@ -66,7 +66,11 @@ ok(xCAT::SvrUtils->uses_static_ipv6_boot('rhels10.0'), 'EL10 takes the static IP ok(xCAT::SvrUtils->uses_static_ipv6_boot('rhels11.0'), 'and so does a later EL, which an equality test missed'); ok(xCAT::SvrUtils->uses_static_ipv6_boot('openeuler24.03sp4'), 'openEuler takes it as well'); ok(xCAT::SvrUtils->uses_static_ipv6_boot('openeuler20.03sp4'), 'every openEuler release, not just the newest'); -ok(!xCAT::SvrUtils->uses_static_ipv6_boot('rhels9.6'), 'EL9 does not, so it keeps the DHCPv6 path'); +# EL 8 and EL 9 take the static address too, by operator decision of 2026-11-05. Their +# installer reads the same kickstart network options and their dracut the same "ip=". +ok(xCAT::SvrUtils->uses_static_ipv6_boot('rhels9.6'), 'EL9 takes it as well'); +ok(xCAT::SvrUtils->uses_static_ipv6_boot('alma8.10'), 'and EL8, whatever the EL brand name'); +ok(!xCAT::SvrUtils->uses_static_ipv6_boot('rhels7.9'), 'EL7 does not, so the floor still holds'); ok(!xCAT::SvrUtils->uses_static_ipv6_boot('sles12'), 'SUSE does not'); ok(!xCAT::SvrUtils->uses_static_ipv6_boot('ubuntu24.04'), 'Ubuntu does not'); ok(!xCAT::SvrUtils->uses_static_ipv6_boot(undef), 'and an undefined osver is not a capability'); diff --git a/xCAT-test/unit/template_ipv6_rendering.t b/xCAT-test/unit/template_ipv6_rendering.t index ca255d655b..39c2544bbe 100644 --- a/xCAT-test/unit/template_ipv6_rendering.t +++ b/xCAT-test/unit/template_ipv6_rendering.t @@ -117,8 +117,9 @@ local $::XCATSITEVALS{managedaddressmode} = 'dhcp'; local $::XCATSITEVALS{xcatdebugmode} = '0'; sub render_minimal_template { - my ($node, $master, $body) = @_; + my ($node, $master, $body, $os) = @_; $body //= "#KICKSTARTNET#\n#INSTALL_SOURCES_IN_PRE#\n"; + $os //= 'alma10.1'; my $tmpdir = tempdir(CLEANUP => 1); my $input = "$tmpdir/input.tmpl"; my $output = "$tmpdir/output"; @@ -135,9 +136,9 @@ sub render_minimal_template { 'rh', undef, { xcatmaster => $master }, - os => 'alma10.1', + os => $os, ); - is($error, 0, "$node minimal EL10 template renders without error"); + is($error, 0, "$node minimal $os template renders without error"); open(my $rendered, '<', $output) or die "Unable to read rendered template: $!"; local $/; @@ -180,6 +181,21 @@ is($ENV{MASTER_IP}, '2001:db8::1', 'IPv6-only template resolves the explicit mas ); } +# EL 8 and EL 9 render the same static network line as EL 10, by operator decision of +# 2026-11-05. They rendered "dhcp --noipv4 --ipv6=dhcp" before, and anaconda then solicited +# DHCPv6 with an identifier that no makedhcp reservation holds. +foreach my $el_os (qw(alma8.10 rhels9.6)) { + my $el_rendered = + render_minimal_template('nodev6', 'master6.example.test', undef, $el_os); + like( + $el_rendered, + qr/^network --onboot=yes --bootproto=static --device=02:00:00:00:00:61 --activate --noipv4 --ipv6=2001:db8:1::50\/64 --ipv6gateway=2001:db8::1 --hostname=nodev6 --nameserver=2001:db8::53$/m, + "$el_os renders the static IPv6 network line" + ); + unlike($el_rendered, qr/--ipv6=dhcp/, + "$el_os does not ask DHCPv6 from the installer"); +} + my $v4_rendered = render_minimal_template('nodev4', 'master4.example.test'); like( $v4_rendered, From 657ff339e194d896fb1ab7129fefccd293361665 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:31:56 -0300 Subject: [PATCH 2/2] fix(xcat-core): a static IPv6 kickstart install leaves the node with no resolv.conf site.nameservers holds one list for the whole cluster, and on a normal lab it names IPv4 resolvers. _static_kickstart_network6 in Template.pm kept only the entries that resolve to an IPv6 address, so it rendered no --nameserver at all and the installed node had no /etc/resolv.conf. Measured on a riscv64 openEuler install. EL 10 takes the same path, and EL 8 and EL 9 now take it too, so the number of nodes exposed grows. _autoyast_network6 in the same file already answered this: it maps '' through ipv6_server_for_node and falls back to the management node when the cluster configures no IPv6 resolver. The chooser is now one sub, _ipv6_nameservers_for_node, and both callers use it. The fallback is the management node and not the gateway, because a gateway can be a router that serves no DNS. A management node with no address on the network of the node yields no resolver, rather than a guess. template_ipv6_rendering.t asserts the rendered network line for all three cases. Without the fallback the IPv4-resolver case fails while the configured IPv6 resolver case and the no-address control keep passing, and autoyast_ipv6_network.t goes red with it, which shows both callers read the same chooser. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-server/lib/perl/xCAT/Template.pm | 55 ++++++++++++++---------- xCAT-test/unit/template_ipv6_rendering.t | 44 ++++++++++++++++++- 2 files changed, 74 insertions(+), 25 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 1c4be9b64a..9756289720 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -97,6 +97,36 @@ sub _dynamic_kickstart_network return $network; } +# The IPv6 resolvers of a node. site.nameservers holds one list for the whole cluster, so an +# IPv6-only node can be given the IPv4 resolver of another network. It cannot reach that +# resolver, and an unreachable server in resolv.conf makes every lookup wait for its timeout. +# +# '' is the management node, which runs named. It stands in when the cluster +# configures no IPv6 resolver, because a node with none writes no resolv.conf at all. It is not +# the gateway: a cluster whose gateway is a separate router would be given a resolver that +# answers nothing, and a cluster with no gateway would be given none at all. +# +# A management node with no address on the network of the node yields no resolver, rather than +# a guess. +sub _ipv6_nameservers_for_node +{ + my ($candidate) = @_; + + my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$candidate]) }; + my @resolvers; + foreach my $nameserver (split(/,/, $nameservers{$candidate} // '')) { + next unless length($nameserver); + my $resolved = xCAT::NetworkUtils->ipv6_server_for_node($candidate, $nameserver); + push @resolvers, $resolved + if defined($resolved) && index($resolved, ':') >= 0; + } + return @resolvers if @resolvers; + + my $master6 = xCAT::NetworkUtils->ipv6_server_for_node($candidate, ''); + return ($master6) if defined($master6) && index($master6, ':') >= 0; + return (); +} + sub _static_kickstart_network6 { my ($candidate, $suffix) = @_; @@ -120,13 +150,7 @@ sub _static_kickstart_network6 $network .= " --ipv6gateway=$gateway" if defined($gateway) && length($gateway); $network .= " --hostname=$hostname" if defined($hostname) && length($hostname); - my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$candidate]) }; - my @nameserver_ips; - foreach my $nameserver (split(/,/, $nameservers{$candidate} || '')) { - next unless length($nameserver); - my $resolved = xCAT::NetworkUtils->ipv6_server_for_node($candidate, $nameserver); - push @nameserver_ips, $resolved if $resolved; - } + my @nameserver_ips = _ipv6_nameservers_for_node($candidate); $network .= " --nameserver=" . join(',', @nameserver_ips) if @nameserver_ips; return $network; @@ -1370,22 +1394,7 @@ sub _autoyast_network6 { my $nd = xCAT::NetworkUtils->getNodeDomains([$node]); my $domain = $nd->{$node}; - my %nameservers = %{ xCAT::NetworkUtils->getNodeNameservers([$node]) }; - # site.nameservers holds one list for the cluster, so the node can be given the IPv4 - # resolver of another network. An IPv6-only node cannot reach it, and an unreachable - # server in resolv.conf makes every lookup wait for its timeout. - # - # '' is the management node, which runs named. It is not the gateway: a - # cluster whose gateway is a separate router would be given a resolver that answers - # nothing, and a cluster with no gateway would be given none at all. - my $master6 = xCAT::NetworkUtils->ipv6_server_for_node($node, ''); - my @nameserversIP = grep { index($_, ':') >= 0 } - grep { defined && length } - map { $_ eq '' ? $master6 : $_ } split(/,/, $nameservers{$node} // ''); - @nameserversIP = ($master6) - if !@nameserversIP - && defined($master6) - && index($master6, ':') >= 0; + my @nameserversIP = _ipv6_nameservers_for_node($node); my $interface = { 'bootproto' => ['static'], diff --git a/xCAT-test/unit/template_ipv6_rendering.t b/xCAT-test/unit/template_ipv6_rendering.t index 39c2544bbe..f961866568 100644 --- a/xCAT-test/unit/template_ipv6_rendering.t +++ b/xCAT-test/unit/template_ipv6_rendering.t @@ -18,6 +18,9 @@ use xCAT::Template; my %addresses = ( nodev4 => { 4 => '192.0.2.50' }, nodev6 => { 6 => '2001:db8:1::50' }, + # A node whose gateway is a literal router address, not the management node. The two must + # differ, or a resolver test cannot tell the management node from the gateway. + nodev6lit => { 6 => '2001:db8:1::51' }, nodedual => { 4 => '192.0.2.60', 6 => '2001:db8:1::60' }, 'master4.example.test' => { 4 => '192.0.2.1' }, 'master6.example.test' => { 6 => '2001:db8::1' }, @@ -35,22 +38,31 @@ local *xCAT::NetworkUtils::getipaddr = sub { return $entry->{4} if $opts{OnlyV4}; return $entry->{4} || $entry->{6}; }; +# The address of the management node on the network of the node. An MN with none is the +# control of the resolver fallback below: it must yield no resolver rather than a guess. +our $master_facing6 = '2001:db8::1'; local *xCAT::NetworkUtils::my_ip_facing_family = sub { my $node = shift; $node = shift if defined($node) && $node eq 'xCAT::NetworkUtils'; my $family = shift; push @facing_calls, [$node, $family]; - return (0, '2001:db8::1'); + return (1, undef) unless defined($master_facing6); + return (0, $master_facing6); }; local *xCAT::NetworkUtils::getNodeNetworkCfg6 = sub { my $candidate = shift; $candidate = shift if defined($candidate) && $candidate eq 'xCAT::NetworkUtils'; + return ('2001:db8:1::51', $candidate, '2001:db8:1::fe', 64) + if $candidate eq 'nodev6lit'; return ('2001:db8:1::50', $candidate, '', 64); }; +# site.nameservers holds one list for the whole cluster, so it can name resolvers the node +# cannot reach. +our $site_nameservers = 'dns6.example.test,192.0.2.53'; local *xCAT::NetworkUtils::getNodeNameservers = sub { my $nodes = shift; $nodes = shift if defined($nodes) && $nodes eq 'xCAT::NetworkUtils'; - return { $nodes->[0] => 'dns6.example.test,192.0.2.53' }; + return { $nodes->[0] => $site_nameservers }; }; is( @@ -196,6 +208,34 @@ foreach my $el_os (qw(alma8.10 rhels9.6)) { "$el_os does not ask DHCPv6 from the installer"); } +# The resolver of a statically configured IPv6-only node. site.nameservers names the IPv4 +# resolver of the cluster on a normal lab, so no resolver reached the node and it installed +# with no /etc/resolv.conf. +{ + local $site_nameservers = '192.168.177.1'; + my $v4ns = render_minimal_template('nodev6lit', 'master6.example.test', undef, 'alma9.6'); + like($v4ns, qr/^network .* --nameserver=2001:db8::1$/m, + 'an IPv4 site resolver is replaced by the IPv6 address of the management node'); + unlike($v4ns, qr/--nameserver=[^ ]*192\.168\.177\.1/, + 'and the IPv4 resolver itself does not reach the node'); + unlike($v4ns, qr/--nameserver=[^ ]*2001:db8:1::fe/, + 'and not by the gateway, which can be a router that serves no DNS'); +} +{ + local $site_nameservers = '2001:db8:aa::53'; + my $v6ns = render_minimal_template('nodev6lit', 'master6.example.test', undef, 'alma9.6'); + like($v6ns, qr/^network .* --nameserver=2001:db8:aa::53$/m, + 'a configured IPv6 resolver is kept as it stands'); +} +{ + # The control: an MN with no address on the network of the node has no resolver to offer. + local $site_nameservers = '192.168.177.1'; + local $master_facing6 = undef; + my $none = render_minimal_template('nodev6lit', 'master6.example.test', undef, 'alma9.6'); + unlike($none, qr/--nameserver/, + 'a management node with no address on the network yields no resolver at all'); +} + my $v4_rendered = render_minimal_template('nodev4', 'master4.example.test'); like( $v4_rendered,