diff --git a/xCAT-test/bats/doxcat_xcatd_address.bats b/xCAT-test/bats/doxcat_xcatd_address.bats new file mode 100644 index 0000000000..c11b390444 --- /dev/null +++ b/xCAT-test/bats/doxcat_xcatd_address.bats @@ -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 "
:" 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" ] +} diff --git a/xCAT-test/unit/xcatd_cmdline_address.t b/xCAT-test/unit/xcatd_cmdline_address.t new file mode 100644 index 0000000000..c0804330ad --- /dev/null +++ b/xCAT-test/unit/xcatd_cmdline_address.t @@ -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 "
:" 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');