2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-20 17:32:15 +00:00

Merge remote-tracking branch 'versatus/fix/ipv6-off-cluster-tests' into feat/ipv6

This commit is contained in:
Daniel Hilst
2026-11-05 10:15:44 -03:00
8 changed files with 794 additions and 39 deletions
+17 -3
View File
@@ -1,9 +1,23 @@
#!/usr/bin/awk -f
#
# The Genesis copy of xCAT/postscripts/allowcred.awk. A /inet/ listener on this gawk
# accepts no IPv6 connection, so an IPv6-only node got no credentials during discovery.
BEGIN {
listener = "/inet/tcp/300/0/0"
port = ("XCAT_CREDENTIAL_CALLBACK_PORT" in ENVIRON) ? ENVIRON["XCAT_CREDENTIAL_CALLBACK_PORT"] : 300
if (port !~ /^[0-9]+$/ || port < 1 || port > 65535) {
port = 300
}
master = ("MASTER_IP" in ENVIRON) ? ENVIRON["MASTER_IP"] : ""
if (master == "") {
master = ("MASTER" in ENVIRON) ? ENVIRON["MASTER"] : ""
}
if (master ~ /:/) {
listener = "/inet6/tcp/" port "/0/0"
} else {
listener = "/inet/tcp/" port "/0/0"
}
quit = "no"
while (match(quit,"no")) {
while ((listener |& getline) > 0) {
if (match($0,"CREDOKBYYOU?")) {
+27 -13
View File
@@ -1,32 +1,46 @@
#!/usr/bin/awk -f
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#
# The Genesis copy of xCAT/postscripts/updateflag.awk. It writes no file: Genesis has no
# /var/log/xcat directory, rsyslog sends everything to /var/log/xcat.genesis, and gawk is
# fatal when it cannot open a redirect.
BEGIN {
xcatdhost = ARGV[1]
xcatdport = ARGV[2]
flag = ARGV[3]
if (!flag) flag = "next"
if (!flag) flag = "next"
ns = "/inet/tcp/0/" ARGV[1] "/" xcatdport
if (xcatdhost ~ /^\[.*\]$/) {
sub(/^\[/, "", xcatdhost)
sub(/\]$/, "", xcatdhost)
}
netfamily = index(xcatdhost, ":") ? "inet6" : "inet"
ns = "/" netfamily "/tcp/0/" xcatdhost "/" xcatdport
while(1) {
if((ns |& getline) > 0)
print $0 | "logger -t xcat -p local4.info"
loop = 0
while(1) {
if((ns |& getline) > 0)
print $0 | "logger -t xcat -p local4.info"
else {
print "Retrying flag update" | "logger -t xcat -p local4.info"
close(ns)
system("sleep 10")
loop = loop + 1
}
if($0 == "ready")
print flag |& ns
if($0 == "done")
break
}
if($0 == "ready")
print flag |& ns
if($0 == "done")
break
if(loop > 10) {
print "flag update failed" | "logger -t xcat -p local4.info"
break
}
}
close(ns)
close(ns)
exit 0
exit 0
}
+144 -23
View File
@@ -693,11 +693,68 @@ sub listnode
}
}
#-------------------------------------------------------------------------------
=head3 delnode6_commands
Descriptions: The omshell commands that remove the DHCPv6 host of a node.
Arguments: $node
Returns: the commands, or the empty string when there is no node to remove.
The sequence is the one addnode6 uses to clear a name conflict before it
creates the host, so a removal and a replacement act on the same object.
=cut
#-------------------------------------------------------------------------------
sub delnode6_commands
{
my ($node) = @_;
return '' unless defined($node) && length($node);
my $commands = "new host\n";
$commands .= "set name = \"$node\"\n";
$commands .= "open\n";
$commands .= "remove\n";
$commands .= "close\n";
return $commands;
}
#-------------------------------------------------------------------------------
=head3 delnode6
Descriptions: Remove the DHCPv6 host of a node over an open omapi session.
Arguments: $node, $writer -- the omshell handle, or undef
Returns: 1 when the commands were written, 0 when there was nothing to do.
makedhcp -d removed the DHCPv4 host alone. addnode6 creates the DHCPv6 host
as a separate object on a separate omapi port, so the reservation survived
the delete and kept the address and the boot file of a node that makedhcp
reported as removed.
=cut
#-------------------------------------------------------------------------------
sub delnode6
{
my ($node, $writer) = @_;
return 0 unless defined($writer);
my $commands = delnode6_commands($node);
return 0 unless length($commands);
print {$writer} $commands;
return 1;
}
sub delnode
{
my $node = shift;
my $inetn = inet_aton($node);
delnode6($node, $omshell6) if $usingipv6;
if (_isc_static_host_fallback()) {
_delete_isc_static_host($node);
$restartdhcp = 1;
@@ -5524,6 +5581,77 @@ sub putmyselffirst {
#-------------------------------------------------------------------------------
=head3 net_config_for
Descriptions: The %netcfgs entry of a subnet.
Arguments: the subnet, with or without a prefix length
Returns: the configuration hash reference, or undef when there is none.
addrangedetection keys %netcfgs on networks.net, which a conf may write
with no prefix length, while addnet6 names a subnet "<net>/<prefix>" from
the "ip -6 route" output. A lookup under the long form alone found nothing,
so the subnet6 lost its domain-search list and its name servers, while
dynamic_range_for, which already falls back, still found the range.
=cut
#-------------------------------------------------------------------------------
sub net_config_for
{
my ($net) = @_;
return unless defined $net;
return $netcfgs{$net} if $netcfgs{$net};
(my $bare = $net) =~ s{/.*$}{};
return $netcfgs{$bare};
}
#-------------------------------------------------------------------------------
=head3 isc_dhcp6_subnet_statements
Descriptions: The domain and resolver statements of an ISC subnet6.
Arguments:
%args - net, config (the net_config_for entry), site_domain,
alldomains (arrayref), domain_search (0 on sles10 and rh5,
whose dhcpd does not know the option)
Returns: the statements, as a list. Empty when the subnet has nothing to say.
=cut
#-------------------------------------------------------------------------------
sub isc_dhcp6_subnet_statements
{
my (%args) = @_;
my $cfg = $args{config} || {};
my @lines;
my $netdomain = $cfg->{domain} || $args{site_domain};
$netdomain = '' unless defined $netdomain;
push @lines, " option domain-name \"" . $netdomain . "\";\n";
if ($args{domain_search} and $cfg->{domain}) {
# We want something like "option domain-search "foo.com", "bar.com";"
my $domainstring = qq~"$cfg->{domain}"~;
foreach my $dom (@{ $args{alldomains} || [] }) {
chomp $dom;
if ($dom ne $cfg->{domain}) {
$domainstring .= qq~, "$dom"~;
}
}
push @lines, " option domain-search $domainstring;\n";
}
my $nsstatement = isc_dhcp6_nameserver_statement($args{net}, $cfg->{nameservers});
push @lines, " $nsstatement\n" if $nsstatement;
return @lines;
}
#-------------------------------------------------------------------------------
=head3 dynamic_range_for
Descriptions: The dynamic range of a subnet, as ISC writes it.
@@ -5606,37 +5734,30 @@ sub addnet6
#posix timezone rfc 4833/tzdb timezone
#phase 3 will include whatever is required to do Netboot6. That might be in the october timeframe for lack of implementations to test
#boot url/param (rfc 59070)
my $netdomain = $netcfgs{$net}->{domain};
# The lookup falls back to the bare net, as dynamic_range_for does. See
# net_config_for: a conf may write networks.net with no prefix length,
# while $net names the subnet "<net>/<prefix>".
my $netcfg = net_config_for($net) || {};
my $netdomain = $netcfg->{domain};
unless ($netdomain) { $netdomain = $site_domain; }
push @netent, " option domain-name \"" . $netdomain . "\";\n";
# add domain-search if not sles10 or rh5
my $osv = xCAT::Utils->osver();
unless (($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/)) {
push @netent, isc_dhcp6_subnet_statements(
net => $net,
config => $netcfg,
site_domain => $site_domain,
alldomains => \@alldomains,
domain_search => (($osv =~ /^sle[sc]10/) || ($osv =~ /^rh.*5$/)) ? 0 : 1,
);
# We want something like "option domain-search "foo.com", "bar.com";"
my $domainstring = qq~"$netcfgs{$net}->{domain}"~;
foreach my $dom (@alldomains) {
chomp $dom;
if ($dom ne $netcfgs{$net}->{domain}) {
$domainstring .= qq~, "$dom"~;
}
}
if ($netcfgs{$net}->{domain}) {
push @netent, " option domain-search $domainstring;\n";
}
}
my $nameservers = $netcfgs{$net}->{nameservers};
my $nsstatement = isc_dhcp6_nameserver_statement( $net, $nameservers );
push @netent, " $nsstatement\n" if $nsstatement;
my $nameservers = $netcfg->{nameservers};
my $ddnserver = defined($nameservers) ? $nameservers : '';
$ddnserver =~ s/,.*//;
my $ddnsdomain;
if ($netcfgs{$net}->{ddnsdomain}) {
$ddnsdomain = $netcfgs{$net}->{ddnsdomain};
if ($netcfg->{ddnsdomain}) {
$ddnsdomain = $netcfg->{ddnsdomain};
}
my $ddns_on = $::XCATSITEVALS{dnshandler} =~ /ddns/ ? 1 : 0;
my $settings;
@@ -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 <keyfile> <nmcli exit status> -- 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" <<NMSTUB
#!/bin/sh
for a in "\$@"; do printf '%s\n' "\$a"; done
exit $rc
NMSTUB
chmod 0755 "$bin/nmcli"
PATH="$bin:$PATH" bash -c '
. "$1"
configure_install_nic_ipv6_keyfile xcat-ens3 ens3 \
2001:db8:149::20 64 2001:db8:149::1 \
"2001:db8:149::1 2001:db8:149::2" ipv6.cluster 9000 "$2"
' bash "$lib" "$keyfile"
}
@test "the rendered keyfile carries the address, gateway, DNS and search list" {
local keyfile="${BATS_TEST_TMPDIR}/nm/xcat-ens3.nmconnection"
run render_keyfile "$keyfile" 0
[ "$status" -eq 0 ]
[ -f "$keyfile" ]
grep -qx 'ipv6.addresses' "$keyfile"
grep -qx '2001:db8:149::20/64' "$keyfile"
grep -qx '2001:db8:149::1' "$keyfile"
grep -qx '2001:db8:149::1 2001:db8:149::2' "$keyfile"
grep -qx 'ipv6.cluster' "$keyfile"
}
# A profile that leaves IPv4 on makes the installed node wait for a lease that never comes.
@test "the rendered keyfile disables IPv4" {
local keyfile="${BATS_TEST_TMPDIR}/nm/xcat-ens3.nmconnection"
run render_keyfile "$keyfile" 0
[ "$status" -eq 0 ]
grep -qx 'ipv4.method' "$keyfile"
grep -qx 'disabled' "$keyfile"
grep -qx 'manual' "$keyfile"
}
@test "the rendered keyfile is readable only by root" {
local keyfile="${BATS_TEST_TMPDIR}/nm/xcat-ens3.nmconnection"
run render_keyfile "$keyfile" 0
[ "$status" -eq 0 ]
[ "$(stat -c '%a' "$keyfile")" = '600' ]
}
# NetworkManager reads every file in system-connections, so a leftover temporary file is a
# second profile for the same interface.
@test "a failed render leaves no temporary file beside the keyfile" {
local keyfile="${BATS_TEST_TMPDIR}/nm/xcat-ens3.nmconnection"
run render_keyfile "$keyfile" 1
[ "$status" -ne 0 ]
[ ! -f "$keyfile" ]
refute_grep -q . <(find "${BATS_TEST_TMPDIR}/nm" -name '*.xcat.*' -print)
}
+167
View File
@@ -0,0 +1,167 @@
#!/usr/bin/env bats
#
# The Genesis ramdisk carries its own copies of two awk helpers, because nothing
# of xCAT is installed in it. The copies under xCAT/postscripts choose the gawk
# network family from the management address; the copies under
# xCAT-genesis-scripts/usr/bin named /inet/ unconditionally, so on an IPv6-only
# cluster the credential listener accepted no connection and the state report
# reached no listener. A node discovered by Genesis then hung with no
# credentials and no state.
#
# Each test runs the real program and speaks to it over the loopback address of
# the family under test. Nothing here reaches the lab.
load 'helpers/shell_source'
setup()
{
command -v gawk >/dev/null || skip 'gawk is required'
command -v socat >/dev/null || skip 'socat is required'
command -v ss >/dev/null || skip 'ss is required'
SERVER_PID=
}
teardown()
{
[ -n "${SERVER_PID:-}" ] || return 0
kill -- "-${SERVER_PID}" 2>/dev/null
kill "$SERVER_PID" 2>/dev/null
return 0
}
# ---------------------------------------------------------------------------
# allowcred.awk -- the credential listener.
# listen_cred <script> <port> -- start the listener with the caller's exports,
# then wait for the port. Its stdio is detached, because a child holding the
# test's pipes open makes a failure hang instead of go red.
listen_cred()
{
local script="$1" port="$2" i
setsid gawk -f "$script" </dev/null >/dev/null 2>&1 &
SERVER_PID=$!
for i in $(seq 1 100); do
ss -Hltn "sport = :${port}" 2>/dev/null | grep -q . && return 0
sleep 0.1
done
return 1
}
ask()
{
printf 'CREDOKBYYOU\n' | socat -T2 - "$1" 2>/dev/null
}
@test "the Genesis credential listener answers an IPv6 master over IPv6" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/allowcred.awk')"
port=$(( 20000 + RANDOM % 20000 ))
export MASTER_IP='2001:db8::1'
export XCAT_CREDENTIAL_CALLBACK_PORT="$port"
listen_cred "$script" "$port"
run ask "TCP6:[::1]:${port}"
[ "$status" -eq 0 ]
[ "$output" = 'CREDOKBYME' ]
}
@test "the Genesis credential listener answers an IPv4 master over IPv4" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/allowcred.awk')"
port=$(( 20000 + RANDOM % 20000 ))
export MASTER_IP='192.0.2.1'
export XCAT_CREDENTIAL_CALLBACK_PORT="$port"
listen_cred "$script" "$port"
run ask "TCP4:127.0.0.1:${port}"
[ "$status" -eq 0 ]
[ "$output" = 'CREDOKBYME' ]
}
@test "the Genesis credential listener reads the master from MASTER too" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/allowcred.awk')"
port=$(( 20000 + RANDOM % 20000 ))
unset MASTER_IP
export MASTER='2001:db8::1'
export XCAT_CREDENTIAL_CALLBACK_PORT="$port"
listen_cred "$script" "$port"
run ask "TCP6:[::1]:${port}"
[ "$status" -eq 0 ]
[ "$output" = 'CREDOKBYME' ]
}
# ---------------------------------------------------------------------------
# updateflag.awk -- the state report.
# serve <family> <listen-address> -- speak the updateflag protocol once and
# record the flag the client sent. Prints the port it listened on.
#
# The protocol is three lines: the server sends "ready", the client sends the
# flag, the server sends "done". A server that stops after "ready" makes the
# client retry instead of failing, so all three are here.
serve()
{
local family="$1" addr="$2" port handler i
port=$(( 20000 + RANDOM % 20000 ))
handler="${BATS_TEST_TMPDIR}/handler.sh"
cat >"$handler" <<'HANDLER'
#!/bin/bash
printf 'ready\n'
IFS= read -r flag
printf '%s\n' "$flag" >"$RECEIVED"
printf 'done\n'
HANDLER
chmod 0755 "$handler"
RECEIVED="$RECEIVED" setsid socat "${family}-LISTEN:${port},bind=${addr},reuseaddr" \
"EXEC:$handler" </dev/null >/dev/null 2>&1 &
SERVER_PID=$!
for i in $(seq 1 100); do
ss -Hltn "sport = :${port}" 2>/dev/null | grep -q . && break
sleep 0.1
done
printf '%s\n' "$port"
}
# report <seconds> <script> <args...> -- run updateflag.awk with its stdio detached.
#
# The helper retries with "system(\"sleep 10\")", and such a child inherits gawk's stdout. A
# child holding bats's pipe open makes a failing case hang instead of go red, so gawk's output
# goes to a file and the kill after the timeout is unconditional.
report()
{
local seconds="$1"; shift
timeout -k 2 "$seconds" gawk -f "$@" </dev/null \
>"${BATS_TEST_TMPDIR}/gawk.out" 2>&1
}
@test "the Genesis state report reaches an IPv6 xcatd" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/updateflag.awk')"
RECEIVED="${BATS_TEST_TMPDIR}/received"
: >"$RECEIVED"
port="$(serve TCP6 ::1)"
run report 15 "$script" ::1 "$port" installing
[ "$status" -eq 0 ]
grep -qx 'installing' "$RECEIVED"
}
@test "the Genesis state report still reaches an IPv4 xcatd" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/updateflag.awk')"
RECEIVED="${BATS_TEST_TMPDIR}/received"
: >"$RECEIVED"
port="$(serve TCP4 127.0.0.1)"
run report 15 "$script" 127.0.0.1 "$port" installing
[ "$status" -eq 0 ]
grep -qx 'installing' "$RECEIVED"
}
@test "the Genesis state report strips the brackets of an IPv6 literal" {
local script port
script="$(require_repo_file 'xCAT-genesis-scripts/usr/bin/updateflag.awk')"
RECEIVED="${BATS_TEST_TMPDIR}/received"
: >"$RECEIVED"
port="$(serve TCP6 ::1)"
run report 15 "$script" '[::1]' "$port" netbooting
[ "$status" -eq 0 ]
grep -qx 'netbooting' "$RECEIVED"
}
@@ -0,0 +1,137 @@
#!/usr/bin/env bats
#
# The EL stateless initrd decides whether the node it is building is IPv6-only, and if it is it
# has to leave a NetworkManager profile behind in the new root. Nothing in the booted system
# repeats the DHCPv6 exchange the initrd made, so a node with no profile comes up with no
# address and answers no ssh.
#
# ip=dhcp6 is not the only form that means IPv6: a node given a static address on the kernel
# command line carries no "dhcp6" anywhere, so the live interface is what settles it. An
# interface that also holds an IPv4 address is a dual-stack node, which keeps the IPv4 path.
load 'helpers/shell_source'
setup()
{
XCATROOT_SCRIPT="$(require_repo_file \
'xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot')"
LIB="${BATS_TEST_TMPDIR}/xcatroot.sh"
{ extract_shell_function "$XCATROOT_SCRIPT" 'xcat_is_ipv6_boot'
extract_shell_function "$XCATROOT_SCRIPT" 'persist_ipv6_nm_connection'; } >"$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 <ip= argument> <interface> -- 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 <newroot> <interface> <mac> [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")
}
@@ -0,0 +1,145 @@
#!/usr/bin/env perl
#
# Two gaps in the ISC DHCPv6 path.
#
# A conf may write networks.net with no prefix length, and addrangedetection keys %netcfgs on
# that value, while addnet6 names a subnet "<net>/<prefix>" from the "ip -6 route" output. The
# range lookup already falls back to the bare net; the domain and the resolver lookups did not,
# so the subnet6 carried no domain-search list and no name servers.
#
# makedhcp -d removed the DHCPv4 host alone. The DHCPv6 host is a separate omapi object on a
# separate port, so the reservation outlived the node it belonged to.
use strict;
use warnings;
no warnings 'once';
use FindBin;
use lib "$FindBin::Bin/../../xCAT-server/lib";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../perl-xCAT";
use Test::More tests => 19;
$ENV{XCATCFG} ||= 'SQLite:/tmp';
my $source_dhcp_plugin = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/dhcp.pm";
if ( -f $source_dhcp_plugin ) {
require $source_dhcp_plugin;
} else {
require xCAT_plugin::dhcp;
}
my $LONG = '2001:db8:149::/64';
my $BARE = '2001:db8:149::';
# The resolver list reaches the statement through dhcp6_resolvers_for_network, which resolves
# names. The stub keeps the value it was handed, so the statement shows what the networks row
# carried rather than what this host can look up.
no warnings 'redefine';
*xCAT_plugin::dhcp::dhcp6_resolvers_for_network = sub {
my ( undef, $nameservers ) = @_;
return $nameservers;
};
use warnings 'redefine';
# ---------------------------------------------------------------------------
# The lookup, under the name the networks table uses and under the long name.
%xCAT_plugin::dhcp::netcfgs = (
$BARE => {
domain => 'ipv6.cluster',
nameservers => '2001:db8:149::1',
ddnsdomain => 'ddns.ipv6.cluster',
range => '2001:db8:149::1000 2001:db8:149::1fff',
},
);
my $cfg = xCAT_plugin::dhcp::net_config_for($LONG);
is( $cfg->{domain}, 'ipv6.cluster',
'the domain of a prefixless networks row is found under the subnet name' );
is( $cfg->{nameservers}, '2001:db8:149::1',
'the nameservers of a prefixless networks row are found under the subnet name' );
is( $cfg->{ddnsdomain}, 'ddns.ipv6.cluster',
'the ddnsdomain of a prefixless networks row is found under the subnet name' );
# dynamic_range_for already fell back, and is left alone. It is the control: a lookup that
# stops falling back takes the three assertions above with it and leaves this one standing.
is( xCAT_plugin::dhcp::dynamic_range_for($LONG),
'2001:db8:149::1000 2001:db8:149::1fff',
'the range lookup still answers for the same subnet' );
is( xCAT_plugin::dhcp::net_config_for('2001:db8:999::/64'), undef,
'a subnet with no networks row has no configuration' );
is( xCAT_plugin::dhcp::net_config_for(undef), undef,
'no subnet name yields no configuration' );
# A row written WITH the prefix still wins, so the fallback adds a name and replaces none.
%xCAT_plugin::dhcp::netcfgs = (
$LONG => { domain => 'long.cluster' },
$BARE => { domain => 'bare.cluster' },
);
is( xCAT_plugin::dhcp::net_config_for($LONG)->{domain}, 'long.cluster',
'the row written with a prefix length is preferred over the bare one' );
# ---------------------------------------------------------------------------
# The statements the subnet6 carries.
%xCAT_plugin::dhcp::netcfgs = ();
my @statements = xCAT_plugin::dhcp::isc_dhcp6_subnet_statements(
net => $LONG,
config => {
domain => 'ipv6.cluster',
nameservers => '2001:db8:149::1,2001:db8:149::2',
},
site_domain => 'site.cluster',
alldomains => [ 'ipv6.cluster', 'other.cluster' ],
domain_search => 1,
);
my $subnet = join( '', @statements );
like( $subnet, qr/^\s*option domain-search\s+"ipv6\.cluster", "other\.cluster";$/m,
'the subnet6 carries the domain-search list of its own network' );
like( $subnet, qr/^\s*option dhcp6\.name-servers 2001:db8:149::1,2001:db8:149::2;$/m,
'the subnet6 carries the nameservers the networks row configured' );
like( $subnet, qr/^\s*option domain-name "ipv6\.cluster";$/m,
'the network domain is the domain-name, not the site domain' );
unlike( $subnet, qr/"ipv6\.cluster", "ipv6\.cluster"/,
'the own domain is not repeated in the search list' );
# With no network domain the site domain names the subnet, and there is no search list to write.
my $sited = join( '', xCAT_plugin::dhcp::isc_dhcp6_subnet_statements(
net => $LONG, config => {}, site_domain => 'site.cluster',
alldomains => ['site.cluster'], domain_search => 1,
) );
like( $sited, qr/^\s*option domain-name "site\.cluster";$/m,
'a network with no domain falls back to the site domain' );
unlike( $sited, qr/domain-search/,
'a network with no domain gets no domain-search statement' );
# sles10 and rh5 dhcpd reject the option, and dhcpd refuses the whole file on one it does not know.
my $old = join( '', xCAT_plugin::dhcp::isc_dhcp6_subnet_statements(
net => $LONG, config => { domain => 'ipv6.cluster' },
alldomains => ['ipv6.cluster'], domain_search => 0,
) );
unlike( $old, qr/domain-search/,
'domain-search is withheld where dhcpd does not know the option' );
# ---------------------------------------------------------------------------
# makedhcp -d reaches the DHCPv6 host.
my $written = '';
open my $omshell6, '>', \$written or die "Cannot open an in-memory handle: $!";
is( xCAT_plugin::dhcp::delnode6( 'node01', $omshell6 ), 1,
'a delete with an open DHCPv6 session reports that it acted' );
close $omshell6;
like( $written, qr/^set name = "node01"\n/m,
'makedhcp -d names the node whose DHCPv6 host it removes' );
like( $written, qr/^open\nremove\nclose\n/m,
'and opens the host and removes it' );
# A node that holds no DHCPv6 address has no session, so nothing is written and nothing dies.
is( xCAT_plugin::dhcp::delnode6( 'node01', undef ), 0,
'a delete with no DHCPv6 session writes nothing' );
is( xCAT_plugin::dhcp::delnode6_commands(''), '',
'an empty node name yields no commands' );
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env perl
#
# mac.duid names the DHCPv6 client identifier that a node's reservations match. It is a new
# column on an old table: a cluster that upgrades carries a mac table with no duid, and nothing
# recreates it.
#
# xcatd adds it. At startup it walks every table in the schema and calls updateschema, which
# compares the declared columns against the database and issues the ALTER. Table->new does NOT
# do this, so the column arrives when xcatd restarts and not when a plugin first opens the table.
use strict;
use warnings;
no warnings 'once';
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use Cwd qw(realpath);
use DBI;
use File::Temp qw(tempdir);
use Test::More tests => 9;
my $cfg = realpath( tempdir( CLEANUP => 1 ) );
$ENV{XCATCFG} = "SQLite:$cfg";
require xCAT::Schema;
require xCAT::Table;
# The schema is the contract makedhcp, chdef and lsdef read.
my $mac_cols = $xCAT::Schema::tabspec{mac}->{cols};
ok( scalar( grep { $_ eq 'duid' } @{$mac_cols} ),
'the mac table declares a duid column' );
my ($duid_attr) =
grep { ( $_->{tabentry} || '' ) eq 'mac.duid' }
@{ $xCAT::Schema::defspec{node}->{attrs} };
ok( $duid_attr, 'a node attribute is mapped onto mac.duid, so chdef and lsdef reach it' );
is( $duid_attr->{attr_name}, 'duid',
'and the attribute chdef and lsdef take is named duid' );
# The mac table of a cluster that predates the column: every other column, and no duid.
my @old_cols = grep { $_ ne 'duid' } @{$mac_cols};
my $dbfile = "$cfg/mac.sqlite";
{
my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", '', '',
{ RaiseError => 1, PrintError => 0 } );
$dbh->do( 'CREATE TABLE mac (' . join( ', ', map { "$_ TEXT" } @old_cols ) . ')' );
$dbh->do( q{INSERT INTO mac (node, mac) VALUES ('node01', 'aa:bb:cc:dd:ee:ff')} );
$dbh->disconnect;
}
ok( !column_present($dbfile, 'duid'), 'the old table starts without the column' );
# What xcatd runs at startup, for every table in the schema.
my $tab = xCAT::Table->new( 'mac', -create => 1 );
ok( $tab, 'the old mac table opens' );
$tab->updateschema();
ok( column_present($dbfile, 'duid'),
'the schema update adds the duid column to a database that predates it' );
# Present is not the same as usable, and the row that was already there has to survive.
$tab->setAttribs( { node => 'node01' }, { duid => '00:04:0d:9e:4b:21' } );
my $row = $tab->getNodeAttribs( 'node01', [ 'mac', 'duid' ] );
is( $row->{duid}, '00:04:0d:9e:4b:21', 'a duid written to the upgraded table reads back' );
is( $row->{mac}, 'aa:bb:cc:dd:ee:ff',
'and the MAC address the table already held is unchanged' );
# A second startup must not alter the table again, or every restart would rewrite it.
$tab->updateschema();
is( $tab->getNodeAttribs( 'node01', ['duid'] )->{duid}, '00:04:0d:9e:4b:21',
'a second schema update leaves the duid alone' );
# column_present <dbfile> <column> -- read the columns from the database itself, not from the
# handle Table.pm holds, so the answer comes from what the ALTER did rather than from the schema.
sub column_present
{
my ( $file, $column ) = @_;
my $dbh = DBI->connect( "dbi:SQLite:dbname=$file", '', '',
{ RaiseError => 1, PrintError => 0 } );
my $found = grep { $_->{name} eq $column } @{ $dbh->selectall_arrayref(
'PRAGMA table_info(mac)', { Slice => {} } ) };
$dbh->disconnect;
return $found;
}