mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-20 01:12:18 +00:00
test(xcat-core): Genesis cannot read an IPv6 xcatd= kernel argument
An IPv6-only node that boots Genesis never reaches xcatd. destiny.pm writes xcatd=<master>:<port> unbracketed, and doxcat splits the value on the colon, so an IPv6 master is read as the address 2001 and the port db8. Measured on a throwaway el10 cluster: the console logged "XCATMASTER is 2001, XCATPORT is db8", the node hung acquiring its credentials, and nodelist.status stayed empty. xcatd_cmdline_address.t drives the writer and doxcat_xcatd_address.bats drives doxcat's own parse loop, extracted by line range rather than re-implemented, so the test reads the shipped code. The bats file is in bats because the parser is shell. The graded evidence is the mutation pair recorded in the fix commit, not the red of this commit alone: without the fix the routine does not exist, and a test that dies on a missing subroutine only says it is missing. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# doxcat reads the management node address and port out of the xcatd= kernel argument. An IPv6
|
||||
# address holds colons, so splitting "<address>:<port>" on the colon gave address 2001 and port
|
||||
# db8, and the node never reached xcatd. destiny.pm now brackets an IPv6 address.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
setup()
|
||||
{
|
||||
DOXCAT="$(repo_path 'xCAT-genesis-scripts/usr/bin/doxcat')"
|
||||
[ -r "$DOXCAT" ] || skip "$DOXCAT is required"
|
||||
export DOXCAT
|
||||
}
|
||||
|
||||
# Run only doxcat's cmdline parse loop against a given /proc/cmdline, and print what it decided.
|
||||
# The loop is extracted by line range rather than re-implemented, so the test reads the shipped
|
||||
# code; a change to the loop that breaks parsing shows up here.
|
||||
parse_xcatd()
|
||||
{
|
||||
local cmdline="$1" dir="${BATS_TEST_TMPDIR}"
|
||||
printf '%s\n' "$cmdline" >"$dir/cmdline"
|
||||
sed -n '/^XCATPORT=3001$/,/^export XCATMASTER$/p' "$DOXCAT" >"$dir/loop.sh"
|
||||
[ -s "$dir/loop.sh" ] || { echo "could not extract the parse loop" >&2; return 1; }
|
||||
sed -i "s|cat /proc/cmdline|cat $dir/cmdline|" "$dir/loop.sh"
|
||||
printf 'printf "%%s %%s\\n" "$XCATMASTER" "$XCATPORT"\n' >>"$dir/loop.sh"
|
||||
bash "$dir/loop.sh"
|
||||
}
|
||||
|
||||
@test "an IPv4 master is read as before" {
|
||||
run parse_xcatd 'quiet xcatd=192.168.1.1:3001 destiny=install'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "192.168.1.1 3001" ]
|
||||
}
|
||||
|
||||
@test "a bracketed IPv6 master gives the address and the port" {
|
||||
run parse_xcatd 'quiet xcatd=[2001:db8:190::1]:3001 destiny=install'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "2001:db8:190::1 3001" ]
|
||||
}
|
||||
|
||||
@test "a bracketed link-local master gives the address and the port" {
|
||||
run parse_xcatd 'quiet xcatd=[fe80::1]:3001 destiny=shell'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "fe80::1 3001" ]
|
||||
}
|
||||
|
||||
@test "a non-default port is read from the bracketed form" {
|
||||
run parse_xcatd 'quiet xcatd=[2001:db8::1]:3002 destiny=install'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "2001:db8::1 3002" ]
|
||||
}
|
||||
|
||||
@test "the port defaults to 3001 when no xcatd argument is given" {
|
||||
run parse_xcatd 'quiet destiny=install'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = " 3001" ]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env perl
|
||||
#
|
||||
# The xcatd= kernel argument carries the management node address and the xcatd port. An IPv6
|
||||
# address holds colons, so an unbracketed "<address>:<port>" cannot be split on the colon.
|
||||
# Measured on an IPv6-only node: destiny.pm wrote xcatd=2001:db8:190::1:3001, doxcat split it on
|
||||
# the first colons and logged "XCATMASTER is 2001, XCATPORT is db8", then never reached xcatd and
|
||||
# the node stayed out of nodelist.status.
|
||||
#
|
||||
# xcatd_cmdline_address brackets an IPv6 address, as RFC 3986 does, and leaves everything else
|
||||
# alone. xCAT-test/bats/doxcat_xcatd_address.bats drives the reader that has to agree with it.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use Test::More tests => 8;
|
||||
|
||||
use xCAT::NetworkUtils;
|
||||
|
||||
is(xCAT::NetworkUtils::xcatd_cmdline_address('192.168.1.1', 3001), '192.168.1.1:3001',
|
||||
'an IPv4 address is unchanged, so an existing node keeps the argument it had');
|
||||
is(xCAT::NetworkUtils::xcatd_cmdline_address('2001:db8:190::1', 3001), '[2001:db8:190::1]:3001',
|
||||
'an IPv6 address is bracketed, so the port can be told from the address');
|
||||
is(xCAT::NetworkUtils::xcatd_cmdline_address('fe80::1', 3001), '[fe80::1]:3001',
|
||||
'a link-local address is bracketed too');
|
||||
is(xCAT::NetworkUtils::xcatd_cmdline_address('::1', 3001), '[::1]:3001',
|
||||
'a loopback address is bracketed');
|
||||
is(xCAT::NetworkUtils::xcatd_cmdline_address('mn.cluster', 3001), 'mn.cluster:3001',
|
||||
'a hostname carries no colon and is not bracketed');
|
||||
ok(!defined(xCAT::NetworkUtils::xcatd_cmdline_address('', 3001)),
|
||||
'an empty address gives no argument rather than a bare colon');
|
||||
ok(!defined(xCAT::NetworkUtils::xcatd_cmdline_address(undef, 3001)),
|
||||
'an undefined address gives no argument');
|
||||
|
||||
# The contract the reader depends on: bracketed address, then a colon, then the port.
|
||||
like(xCAT::NetworkUtils::xcatd_cmdline_address('2001:db8:190::1', 3001),
|
||||
qr/\A\[[0-9a-f:]+\]:\d+\z/,
|
||||
'the IPv6 form is exactly what doxcat parses: [address]:port');
|
||||
Reference in New Issue
Block a user