2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-22 10:22:18 +00:00

test(ipv6): shell under test is written in bats, not in a .t

Seven of the ported unit files drive shell: they run bash -n on a product
script, cut a function out of it with a regex and eval the copy, or write a
fake executable into PATH. A .t runs Perl in process, so each one tested its
own scaffolding as much as the product, and a reformat of the script would
break it while a move of the code would not.

The five bats files replace them and use the existing shell_source helper.
ipv6_endpoint_helpers drives the four separate copies of xcat_endpoint_host
from one table, because the scripts carry a copy each -- xcatroot runs in the
dracut initrd, xcatpostinit1.netboot before /xcatpost exists, xcatinstallpost
in the installer root -- and the copies must agree.
ipv6_xcatdsklspost_endpoints uses XCATDSKLSPOST_SOURCE_ONLY to load the real
parsehttpserver and format_host_port and asserts a bracketed authority
survives a round trip. ipv6_syslog_forwarding covers the rsyslog bracket and
the syslog-ng udp6 driver. ipv6_configeth_install_nic drives
discover_install_nic_ipv6 against recorded "ip -6 addr show" output and pins
that a temporary, tentative, deprecated or dadfailed address is never chosen.
ipv6_updateflag_awk runs updateflag.awk against a loopback listener of each
family and pins the bracket stripping.

Each assertion was run against the unfixed script and fails there. Two gaps
stay: allowcred.awk has no coverage, and the /inet6/ prefix updateflag.awk
chooses cannot be covered, because gawk 5.3.0 reaches an IPv6 literal through
/inet/ as well.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-21 18:59:07 -03:00
parent 82b00278bc
commit 4d5ca9964e
12 changed files with 459 additions and 896 deletions
@@ -0,0 +1,83 @@
#!/usr/bin/env bats
#
# configeth replaces the connection the installer created for the install NIC.
# On an IPv6 install it has to read the live address back first, and a DHCPv6
# lease is not written to the dhclient lease file the IPv4 path reads, so the
# address comes from "ip -6 addr show" instead. An address marked temporary,
# tentative, deprecated or dadfailed is not usable and must not be chosen.
load 'helpers/shell_source'
# run_discover <preferred> <ip -6 addr output> -- returns the chosen CIDR
run_discover()
{
local file lib bin
file="$(require_repo_file 'xCAT/postscripts/configeth')"
lib="${BATS_TEST_TMPDIR}/configeth.sh"
extract_shell_function "$file" 'discover_install_nic_ipv6' >"$lib" || return 1
bin="${BATS_TEST_TMPDIR}/bin"
mkdir -p "$bin"
printf '%s\n' "$2" >"${BATS_TEST_TMPDIR}/addr"
cat >"$bin/ip" <<'IPSTUB'
#!/bin/sh
case "$*" in
*"-6 -o addr show"*)
# The real ip(8) applies "scope global"; the stub has to as well, or a
# link-local address reaches a caller that asked for a global one.
case "$*" in
*"scope global"*) grep -v 'scope link' "${BATS_TEST_TMPDIR}/addr" || true ;;
*) cat "${BATS_TEST_TMPDIR}/addr" ;;
esac
;;
*"-6 route show default"*) echo "default via 2001:db8::1 dev ens3 metric 100" ;;
*"-o link show"*) echo "2: ens3: <UP> mtu 9000 state UP" ;;
*) exit 1 ;;
esac
IPSTUB
# A test that reaches NetworkManager measures the host, not this function.
printf '#!/bin/sh\nexit 1\n' >"$bin/nmcli"
chmod 0755 "$bin"/*
PATH="$bin:$PATH" BATS_TEST_TMPDIR="$BATS_TEST_TMPDIR" bash -c '
. "$1"
discover_install_nic_ipv6 ens3 "$2" || exit $?
printf "%s/%s %s %s\n" "$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_mtu"
' bash "$lib" "$1"
}
@test "a single global address is chosen with its prefix, gateway and MTU" {
run run_discover '' '3: ens3 inet6 2001:db8::50/64 scope global \ valid_lifetime forever preferred_lft forever'
[ "$status" -eq 0 ]
[ "$output" = '2001:db8::50/64 2001:db8::1 9000' ]
}
@test "a temporary privacy address is not chosen over a stable one" {
run run_discover '' '3: ens3 inet6 2001:db8::dead/64 scope global temporary dynamic
3: ens3 inet6 2001:db8::50/64 scope global dynamic'
[ "$status" -eq 0 ]
[ "${output% * *}" = '2001:db8::50/64' ]
}
@test "a tentative, deprecated or dadfailed address is never chosen" {
local flag
for flag in tentative deprecated dadfailed; do
run run_discover '' "3: ens3 inet6 2001:db8::bad/64 scope global $flag
3: ens3 inet6 2001:db8::50/64 scope global dynamic"
[ "$status" -eq 0 ]
[ "${output% * *}" = '2001:db8::50/64' ]
done
}
@test "the address xCAT asked for wins over the first usable one" {
run run_discover '2001:db8::99' '3: ens3 inet6 2001:db8::50/64 scope global dynamic
3: ens3 inet6 2001:db8::99/64 scope global dynamic'
[ "$status" -eq 0 ]
[ "${output% * *}" = '2001:db8::99/64' ]
}
@test "no usable global address is a failure, not an empty answer" {
run run_discover '' '3: ens3 inet6 fe80::1/64 scope link'
[ "$status" -ne 0 ]
}
+132
View File
@@ -0,0 +1,132 @@
#!/usr/bin/env bats
#
# Every xCAT endpoint a node reads is "host:port", and an IPv6 literal already
# contains colons. Four scripts carry a helper that splits such a value and
# reassembles it with brackets. They are separate copies because a node has no
# shared shell library at the point each one runs: xcatroot runs inside the
# dracut initrd, xcatpostinit1.netboot before /xcatpost is populated, and
# xcatinstallpost in the installer root. The copies must agree, so each one is
# driven with the same table.
load 'helpers/shell_source'
ENDPOINT_SCRIPTS=(
'xCAT/postscripts/xcatinstallpost'
'xCAT/postscripts/xcatpostinit1.netboot'
'xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot'
)
# host_for <script> <endpoint> -- run that script's xcat_endpoint_host
host_for()
{
local file lib
file="$(require_repo_file "$1")"
lib="${BATS_TEST_TMPDIR}/endpoint.sh"
extract_shell_function "$file" 'xcat_endpoint_host' >"$lib" || return 1
# shellcheck disable=SC1090
. "$lib"
xcat_endpoint_host "$2"
}
@test "an IPv4 endpoint keeps its address and loses the port" {
for script in "${ENDPOINT_SCRIPTS[@]}"; do
run host_for "$script" '192.0.2.10:3001'
[ "$status" -eq 0 ]
[ "$output" = '192.0.2.10' ]
done
}
@test "a bracketed IPv6 endpoint yields the address without brackets or port" {
for script in "${ENDPOINT_SCRIPTS[@]}"; do
run host_for "$script" '[2001:db8::1]:3001'
[ "$status" -eq 0 ]
[ "$output" = '2001:db8::1' ]
done
}
@test "an unbracketed IPv6 literal is returned whole, not split at a colon" {
for script in "${ENDPOINT_SCRIPTS[@]}"; do
run host_for "$script" '2001:db8::1'
[ "$status" -eq 0 ]
[ "$output" = '2001:db8::1' ]
done
}
@test "a hostname with no port is returned unchanged" {
for script in "${ENDPOINT_SCRIPTS[@]}"; do
run host_for "$script" 'mn01.cluster.example'
[ "$status" -eq 0 ]
[ "$output" = 'mn01.cluster.example' ]
done
}
@test "xcatinstallpost strips the quotes mypostscript writes around a value" {
run host_for 'xCAT/postscripts/xcatinstallpost' "'[2001:db8::1]:3001'"
[ "$status" -eq 0 ]
[ "$output" = '2001:db8::1' ]
}
# authority_for <script> <host> <port> -- run that script's format_host_port
authority_for()
{
local file lib
file="$(require_repo_file "$1")"
lib="${BATS_TEST_TMPDIR}/authority.sh"
{ extract_shell_function "$file" 'xcat_endpoint_host'
extract_shell_function "$file" 'format_host_port'; } >"$lib" || return 1
# shellcheck disable=SC1090
. "$lib"
format_host_port "$2" "$3"
}
@test "format_host_port brackets an IPv6 host and leaves an IPv4 host bare" {
run authority_for 'xCAT/postscripts/xcatinstallpost' '2001:db8::1' 3001
[ "$status" -eq 0 ]
[ "$output" = '[2001:db8::1]:3001' ]
run authority_for 'xCAT/postscripts/xcatinstallpost' '192.0.2.10' 3001
[ "$status" -eq 0 ]
[ "$output" = '192.0.2.10:3001' ]
}
@test "format_host_port does not bracket an address that already carries them" {
run authority_for 'xCAT/postscripts/xcatinstallpost' '[2001:db8::1]:80' 3001
[ "$status" -eq 0 ]
[ "$output" = '[2001:db8::1]:3001' ]
}
# The EL10 install post-script builds its endpoints from a bare address rather
# than from an endpoint string, so it carries format_uri_host instead.
el10_authority()
{
local file lib
file="$(require_repo_file 'xCAT-server/share/xcat/install/scripts/post.xcat.rhels10')"
lib="${BATS_TEST_TMPDIR}/el10.sh"
{ extract_shell_function "$file" 'format_uri_host'
extract_shell_function "$file" 'format_host_port'; } >"$lib" || return 1
# shellcheck disable=SC1090
. "$lib"
format_host_port "$1" "$2"
}
@test "the EL10 install post-script brackets an IPv6 management address" {
run el10_authority '2001:db8::1' 3001
[ "$status" -eq 0 ]
[ "$output" = '[2001:db8::1]:3001' ]
}
@test "the EL10 install post-script leaves an IPv4 address and a name bare" {
run el10_authority '192.0.2.10' 3001
[ "$status" -eq 0 ]
[ "$output" = '192.0.2.10:3001' ]
run el10_authority 'mn01' 3001
[ "$status" -eq 0 ]
[ "$output" = 'mn01:3001' ]
}
@test "the EL10 install post-script does not double-bracket" {
run el10_authority '[2001:db8::1]' 3001
[ "$status" -eq 0 ]
[ "$output" = '[2001:db8::1]:3001' ]
}
@@ -0,0 +1,80 @@
#!/usr/bin/env bats
#
# rsyslog and syslog-ng both take a forwarding target after "@", and neither
# parses a bare IPv6 literal there: rsyslog needs the address in brackets, and
# syslog-ng needs the udp6() driver instead of udp(). The syslog postscript and
# the initrd rsyslog launcher each carry a formatter for this.
load 'helpers/shell_source'
load_syslog_helpers()
{
local file lib
file="$(require_repo_file 'xCAT/postscripts/syslog')"
lib="${BATS_TEST_TMPDIR}/syslog.sh"
{ extract_shell_function "$file" 'format_syslog_forward_target'
extract_shell_function "$file" 'syslog_ng_udp_driver'; } >"$lib" || return 1
# shellcheck disable=SC1090
. "$lib"
}
@test "an IPv6 forwarding target is bracketed for rsyslog" {
load_syslog_helpers
[ "$(format_syslog_forward_target '2001:db8::1')" = '[2001:db8::1]' ]
}
@test "an IPv4 target and a hostname are passed through unchanged" {
load_syslog_helpers
[ "$(format_syslog_forward_target '192.0.2.10')" = '192.0.2.10' ]
[ "$(format_syslog_forward_target 'mn01')" = 'mn01' ]
}
@test "an already-bracketed target is not bracketed twice" {
load_syslog_helpers
[ "$(format_syslog_forward_target '[2001:db8::1]')" = '[2001:db8::1]' ]
}
@test "syslog-ng selects udp6 for an IPv6 target and udp otherwise" {
load_syslog_helpers
[ "$(syslog_ng_udp_driver '2001:db8::1')" = 'udp6' ]
[ "$(syslog_ng_udp_driver '192.0.2.10')" = 'udp' ]
[ "$(syslog_ng_udp_driver 'mn01')" = 'udp' ]
}
@test "the initrd rsyslog launcher writes a bracketed forwarding line" {
local file lib template
file="$(require_repo_file 'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh')"
lib="${BATS_TEST_TMPDIR}/rsyslogd.sh"
{ extract_shell_function "$file" 'format_syslog_server'
extract_shell_function "$file" 'rsyslog_config'; } >"$lib"
# shellcheck disable=SC1090
. "$lib"
template="${BATS_TEST_TMPDIR}/rsyslog.conf"
printf '# template\n' >"$template"
run rsyslog_config '2001:db8::1' "$template" 'kern.*'
[ "$status" -eq 0 ]
[ "${lines[${#lines[@]}-1]}" = 'kern.* @[2001:db8::1]' ]
run rsyslog_config '192.0.2.10' "$template" 'kern.*'
[ "$status" -eq 0 ]
[ "${lines[${#lines[@]}-1]}" = 'kern.* @192.0.2.10' ]
}
@test "the initrd launcher logs locally when no server is given" {
local file lib template
file="$(require_repo_file 'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh')"
lib="${BATS_TEST_TMPDIR}/rsyslogd.sh"
{ extract_shell_function "$file" 'format_syslog_server'
extract_shell_function "$file" 'rsyslog_config'; } >"$lib"
# shellcheck disable=SC1090
. "$lib"
template="${BATS_TEST_TMPDIR}/rsyslog.conf"
printf '# template\n' >"$template"
run rsyslog_config '' "$template" 'kern.*'
[ "$status" -eq 0 ]
[ "${lines[${#lines[@]}-1]}" = 'kern.* /var/log/messages' ]
}
+109
View File
@@ -0,0 +1,109 @@
#!/usr/bin/env bats
#
# updateflag.awk reports the install state back to xcatd over a gawk network
# special file, built from the address xCAT passes it. An IPv6 management
# address arrives bracketed, and gawk resolves nothing unless the brackets come
# off, so the node never reports its state.
#
# These tests do not cover the /inet/ to /inet6/ prefix the same routine
# chooses. Measured on gawk 5.3.0: /inet/ reaches an IPv6 literal and only
# /inet4/ refuses it, so removing that choice breaks nothing a test could see.
# The prefix stays because it is explicit, not because it is load-bearing.
#
# Each test runs the real program against a listener on the loopback address of
# the family under test. Nothing here reaches the lab.
load 'helpers/shell_source'
setup()
{
SCRIPT="$(require_repo_file 'xCAT/postscripts/updateflag.awk')"
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'
RECEIVED="${BATS_TEST_TMPDIR}/received"
: >"$RECEIVED"
}
# 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 for a hundred seconds instead of failing, so all three are here.
#
# The listener serves one connection and exits, so readiness is read from ss
# rather than by connecting: a probe connection would consume it.
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"
# Detach the server's stdio: a child holding the test's pipes open makes a
# failure hang instead of going red.
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"
}
teardown()
{
# The listener serves one connection and exits, so this only matters when a
# test failed before connecting. Signal the session setsid created, then
# confirm the port is gone rather than assuming the signal landed.
[ -n "${SERVER_PID:-}" ] || return 0
kill -- "-${SERVER_PID}" 2>/dev/null
kill "$SERVER_PID" 2>/dev/null
local i
for i in $(seq 1 50); do
kill -0 "$SERVER_PID" 2>/dev/null || return 0
sleep 0.1
done
kill -9 -- "-${SERVER_PID}" 2>/dev/null
return 0
}
@test "an IPv4 xcatd address still reaches the listener" {
local port
port="$(serve TCP4 127.0.0.1)"
run timeout 30 gawk -f "$SCRIPT" 127.0.0.1 "$port" installing
[ "$status" -eq 0 ]
grep -qx 'installing' "$RECEIVED"
}
@test "an IPv6 xcatd address reaches the listener" {
local port
port="$(serve TCP6 ::1)"
run timeout 30 gawk -f "$SCRIPT" ::1 "$port" installing
[ "$status" -eq 0 ]
grep -qx 'installing' "$RECEIVED"
}
@test "a bracketed IPv6 address has its brackets stripped before gawk resolves it" {
local port
port="$(serve TCP6 ::1)"
run timeout 30 gawk -f "$SCRIPT" '[::1]' "$port" netbooting
[ "$status" -eq 0 ]
grep -qx 'netbooting' "$RECEIVED"
}
@test "the default flag is sent when none is given" {
local port
port="$(serve TCP6 ::1)"
run timeout 30 gawk -f "$SCRIPT" ::1 "$port"
[ "$status" -eq 0 ]
grep -qx 'next' "$RECEIVED"
}
@@ -0,0 +1,55 @@
#!/usr/bin/env bats
#
# xcatdsklspost downloads the postscripts and the generated mypostscript over
# HTTP from the management or service node. The server value it is given is a
# "host:port" string, so an IPv6 management node has to be split and rebuilt
# with brackets before it goes into a URL. XCATDSKLSPOST_SOURCE_ONLY makes the
# script define its helpers and return without running its main body.
load 'helpers/shell_source'
setup()
{
SCRIPT="$(require_repo_file 'xCAT/postscripts/xcatdsklspost')"
XCATDSKLSPOST_SOURCE_ONLY=1
export XCATDSKLSPOST_SOURCE_ONLY
# shellcheck disable=SC1090
. "$SCRIPT"
}
@test "parsehttpserver splits a bracketed IPv6 authority into host and port" {
[ "$(parsehttpserver '[2001:db8::1]:8080' 'server')" = '2001:db8::1' ]
[ "$(parsehttpserver '[2001:db8::1]:8080' 'port')" = '8080' ]
}
@test "a bracketed IPv6 authority with no port gets the default port" {
[ "$(parsehttpserver '[2001:db8::1]' 'server')" = '2001:db8::1' ]
[ "$(parsehttpserver '[2001:db8::1]' 'port')" = '80' ]
}
@test "an unbracketed IPv6 literal is not split at its last colon" {
[ "$(parsehttpserver '2001:db8::1' 'server')" = '2001:db8::1' ]
[ "$(parsehttpserver '2001:db8::1' 'port')" = '80' ]
}
@test "IPv4 and hostname authorities keep their existing behaviour" {
[ "$(parsehttpserver '192.0.2.10:8080' 'server')" = '192.0.2.10' ]
[ "$(parsehttpserver '192.0.2.10:8080' 'port')" = '8080' ]
[ "$(parsehttpserver '192.0.2.10' 'port')" = '80' ]
[ "$(parsehttpserver 'mn01' 'server')" = 'mn01' ]
[ "$(parsehttpserver 'mn01' 'port')" = '80' ]
}
@test "format_host_port rebuilds an authority a URL can carry" {
[ "$(format_host_port '2001:db8::1' '80')" = '[2001:db8::1]:80' ]
[ "$(format_host_port '192.0.2.10' '80')" = '192.0.2.10:80' ]
}
@test "the two helpers compose, so an authority survives a round trip" {
local raw host port
for raw in '[2001:db8::1]:8080' '192.0.2.10:8080' 'mn01:80'; do
host="$(parsehttpserver "$raw" 'server')"
port="$(parsehttpserver "$raw" 'port')"
[ "$(format_host_port "$host" "$port")" = "$raw" ]
done
}
-237
View File
@@ -1,237 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $source = "$FindBin::Bin/../../xCAT/postscripts/configeth";
open( my $source_fh, '<', $source ) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($function) = $content =~ /^(function \Q$name\E\(\)\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($function);
return $function;
}
is( system( 'bash', '-n', $source ), 0, 'configeth has valid bash syntax' );
my ( $harness_fh, $harness ) = tempfile();
print {$harness_fh} shell_function('discover_install_nic_ipv6'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_connection'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_nm'), "\n";
print {$harness_fh} shell_function('configure_install_nic_ipv6_keyfile'), "\n";
print {$harness_fh} <<'SHELL';
set -eu
NMCLI_LOG=$1
KEYFILE=$2
fail() {
echo "$*" >&2
exit 1
}
ip() {
case "$*" in
'-6 -o addr show dev eth0 scope global')
printf '%s\n' \
'2: eth0 inet6 2001:db8:1::88/56 scope global dynamic noprefixroute' \
'2: eth0 inet6 2001:db8:1::99/64 scope global temporary dynamic' \
'2: eth0 inet6 2001:db8:1::21/64 scope global dynamic noprefixroute'
;;
'-6 route show default dev eth0')
printf '%s\n' 'default via fe80::1 dev eth0 proto ra metric 100'
;;
'-o link show dev eth0')
printf '%s\n' '2: eth0: <BROADCAST,MULTICAST,UP> mtu 9000 state UP'
;;
'-6 -o addr show dev eth1 scope global')
printf '%s\n' '3: eth1 inet6 2001:db8:2::21/64 scope global dynamic noprefixroute'
;;
'-6 route show default dev eth1')
return 0
;;
'-o link show dev eth1')
printf '%s\n' '3: eth1: <BROADCAST,MULTICAST,UP> mtu 1500 state UP'
;;
*)
return 1
;;
esac
}
nmcli() {
case "$*" in
'--escape no -g IP6.DNS device show eth0')
printf '%s\n' '2001:db8::53' '2001:db8::54'
;;
'--escape no -g IP6.SEARCHES device show eth0')
printf '%s\n' 'cluster.example' 'lab.example'
;;
'--escape no -g IP6.GATEWAY device show eth0')
printf '%s\n' 'fe80::2'
;;
'--escape no -g IP6.GATEWAY device show eth1')
printf '%s\n' 'fe80::2'
;;
'--escape no -g IP6.DNS device show eth1'|'--escape no -g IP6.SEARCHES device show eth1')
printf '%s\n' '--'
;;
'--offline con add type ethernet con-name xcat-eth0 ifname eth0 ipv4.method disabled ipv6.method manual ipv6.addresses 2001:db8:1::21/64 connection.autoconnect yes connection.autoconnect-priority 9 ipv6.gateway fe80::1 ipv6.dns 2001:db8::53,2001:db8::54 ipv6.dns-search cluster.example,lab.example 802-3-ethernet.mtu 9000')
printf '%s\n' \
'[connection]' \
'id=xcat-eth0' \
'uuid=01234567-89ab-cdef-0123-456789abcdef' \
'type=ethernet' \
'autoconnect-priority=9' \
'interface-name=eth0' \
'' \
'[ethernet]' \
'mtu=9000' \
'' \
'[ipv4]' \
'method=disabled' \
'' \
'[ipv6]' \
'addr-gen-mode=default' \
'address1=2001:db8:1::21/64' \
'dns=2001:db8::53;2001:db8::54;' \
'dns-search=cluster.example;lab.example;' \
'gateway=fe80::1' \
'method=manual' \
'' \
'[proxy]'
;;
*)
printf '%s\n' "$*" >> "$NMCLI_LOG"
;;
esac
}
discover_install_nic_ipv6 eth0 2001:db8:1::21 || fail 'IPv6 discovery failed'
[ "$str_inst_ipv6" = '2001:db8:1::21' ] || fail "unexpected address: $str_inst_ipv6"
[ "$str_inst_ipv6_prefix" = '64' ] || fail "unexpected prefix: $str_inst_ipv6_prefix"
[ "$str_inst_ipv6_gateway" = 'fe80::1' ] || fail "unexpected gateway: $str_inst_ipv6_gateway"
[ "$str_inst_ipv6_dns" = '2001:db8::53,2001:db8::54' ] || fail "unexpected DNS: $str_inst_ipv6_dns"
[ "$str_inst_ipv6_dns_search" = 'cluster.example,lab.example' ] || fail "unexpected DNS search: $str_inst_ipv6_dns_search"
[ "$str_inst_mtu" = '9000' ] || fail "unexpected MTU: $str_inst_mtu"
configure_install_nic_ipv6_nm \
xcat-eth0 eth0 "$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu"
configure_install_nic_ipv6_keyfile \
xcat-eth0 eth0 "$str_inst_ipv6" "$str_inst_ipv6_prefix" \
"$str_inst_ipv6_gateway" "$str_inst_ipv6_dns" \
"$str_inst_ipv6_dns_search" "$str_inst_mtu" "$KEYFILE"
discover_install_nic_ipv6 eth1 || fail 'IPv6 discovery with NetworkManager gateway fallback failed'
[ "$str_inst_ipv6_gateway" = 'fe80::2' ] || fail "unexpected fallback gateway: $str_inst_ipv6_gateway"
if discover_install_nic_ipv6 eth2; then
fail 'IPv6 discovery accepted an interface without a global address'
fi
SHELL
close($harness_fh);
my ( $log_fh, $log ) = tempfile();
close($log_fh);
my ( $keyfile_fh, $keyfile ) = tempfile();
close($keyfile_fh);
unlink($keyfile) or die "Unable to prepare $keyfile: $!";
is( system( 'bash', $harness, $log, $keyfile ), 0, 'IPv6 install-NIC discovery and persistence helpers execute successfully' );
open( my $log_fh_read, '<', $log ) or die "Unable to read $log: $!";
my @nmcli = <$log_fh_read>;
close($log_fh_read);
chomp(@nmcli);
is_deeply(
\@nmcli,
[
'con add type ethernet con-name xcat-eth0 ifname eth0 ipv4.method disabled ipv6.method manual ipv6.addresses 2001:db8:1::21/64 connection.autoconnect yes connection.autoconnect-priority 9 ipv6.gateway fe80::1 ipv6.dns 2001:db8::53,2001:db8::54 ipv6.dns-search cluster.example,lab.example 802-3-ethernet.mtu 9000',
],
'NetworkManager connection is IPv6-only and persists address, route, DNS, search domains, and MTU'
);
unlike(
join( "\n", @nmcli ),
qr/ipv4\.(?:addresses|dns)|ipv4\.method (?:auto|manual)/,
'IPv6-only persistence never configures or enables IPv4'
);
open( my $keyfile_fh_read, '<', $keyfile ) or die "Unable to read $keyfile: $!";
my $keyfile_content = do { local $/; <$keyfile_fh_read> };
close($keyfile_fh_read);
is(
$keyfile_content,
<<'KEYFILE',
[connection]
id=xcat-eth0
uuid=01234567-89ab-cdef-0123-456789abcdef
type=ethernet
autoconnect-priority=9
interface-name=eth0
[ethernet]
mtu=9000
[ipv4]
method=disabled
[ipv6]
addr-gen-mode=default
address1=2001:db8:1::21/64
dns=2001:db8::53;2001:db8::54;
dns-search=cluster.example;lab.example;
gateway=fe80::1
method=manual
[proxy]
KEYFILE
'Anaconda-stage fallback writes the equivalent native NetworkManager keyfile'
);
is(
( stat($keyfile) )[2] & oct('07777'),
oct('0600'),
'NetworkManager keyfile is private'
);
unlike( $keyfile_content, qr/^address1=\d+\.\d+\.\d+\.\d+/m, 'keyfile does not configure an IPv4 address' );
like(
$content,
qr/if \[ \$install_nic_is_ipv6 -ne 1 \]; then\n\s+str_inst_net=\$\(v4calcnet/,
'legacy IPv4 network calculation remains on the IPv4 path'
);
like(
$content,
qr/\[ \$install_nic_is_ipv6 -eq 1 \] && \[ \$networkmanager_active -eq 2 \].*?configure_install_nic_ipv6_keyfile/s,
'chrooted Anaconda path persists a keyfile instead of an obsolete ifcfg file'
);
like(
$content,
qr/Do not tear down the\n\s+# Anaconda-owned live connection from inside the chroot/,
'Anaconda-stage keyfile persistence leaves the live installer connection up'
);
like(
$content,
qr/nmcli con add type ethernet con-name \$con_name ifname \$\{str_inst_nic\} ipv4\.method manual ipv4\.addresses/,
'legacy IPv4 NetworkManager persistence remains available'
);
like(
$content,
qr/discover_install_nic_ipv6 "\$str_inst_nic" "\$str_requested_ipv6"/,
'configeth -s asks live discovery for the xCAT-defined IPv6 address when IPv4 lease data is absent'
);
like(
$content,
qr/\[ -n "\$NAMESERVERS" \] && nmcli con modify "\$con_name" ipv6\.dns "\$NAMESERVERS"/,
'restart path updates IPv6 DNS without writing IPv4 DNS properties'
);
done_testing();
-145
View File
@@ -1,145 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $repo_root = File::Spec->rel2abs( File::Spec->catdir( $FindBin::Bin, '..', '..' ) );
sub read_file {
my ($relative_path) = @_;
my $path = File::Spec->catfile( $repo_root, split( '/', $relative_path ) );
open( my $fh, '<', $path ) or die "Unable to read $path: $!";
my $contents = do { local $/; <$fh> };
close($fh);
return ( $path, $contents );
}
sub shell_function {
my ( $script, $name ) = @_;
my ($definition) = $script =~ /((?:function\s+)?\Q$name\E\(\)\s*\n\{.*?^\})/ms;
return $definition;
}
sub run_shell_function {
my ( $definitions, $invocation, @args ) = @_;
my $program = "$definitions\n$invocation";
open( my $pipe, '-|', 'bash', '-c', $program, 'bash', @args )
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is( $?, 0, "$invocation exits successfully" );
chomp($output);
return $output;
}
my ( $pre_path, $pre ) = read_file('xCAT-server/share/xcat/install/scripts/pre.rhels10');
my ( $post_path, $post ) = read_file('xCAT-server/share/xcat/install/scripts/post.xcat.rhels10');
my ( $updateflag_path, $updateflag ) = read_file('xCAT/postscripts/updateflag.awk');
is( system( 'bash', '-n', $pre_path ), 0, 'EL10 pre-install script has valid bash syntax' );
is( system( 'bash', '-n', $post_path ), 0, 'EL10 post-install script has valid bash syntax' );
unlike(
$pre,
qr/socket\.socket\(socket\.AF_INET,\s*socket\.SOCK_STREAM\)/,
'EL10 installer callbacks do not hard-code IPv4 sockets'
);
is(
scalar( () = $pre =~ /socket\.create_connection\(\('#ENV:MASTER_IP#'/g ),
2,
'both EL10 installer callback clients use family-neutral connections to the facing master address'
);
like( $pre, qr/socket\.getaddrinfo\(master, None, socket\.AF_UNSPEC,/, 'install monitor selects the listener family from the master address' );
like( $pre, qr/None, port, master_family, socket\.SOCK_STREAM, 0, socket\.AI_PASSIVE/, 'install monitor requests a passive listener only in the provisioning family' );
like( $pre, qr/socket\.IPV6_V6ONLY, 1/, 'IPv6 monitor listener rejects IPv4-mapped clients' );
like( $pre, qr/if address\[0\] not in allowed_peers:/, 'install monitor rejects callback clients other than the configured master' );
unlike( $pre, qr/os\.popen\(newcommand\)/, 'screen capture does not construct a shell command from network input' );
like( $pre, qr/screen and not screen\.isdigit\(\)/, 'screen capture accepts only a numeric virtual-console suffix' );
my $extract_url_host = shell_function( $pre, 'extract_url_host' );
ok( defined($extract_url_host), 'pre-install URL host helper is present' );
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'http://192.0.2.10:8080/install/repo' ),
'192.0.2.10',
'pre-install repository discovery preserves an IPv4 host'
);
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'http://[2001:db8::10]:8080/install/repo' ),
'2001:db8::10',
'pre-install repository discovery extracts a complete bracketed IPv6 literal'
);
is(
run_shell_function( $extract_url_host, 'extract_url_host "$1"', 'https://provision.example.test/install/repo' ),
'provision.example.test',
'pre-install repository discovery preserves a hostname'
);
like(
$pre,
qr/grep -oE 'https\?:\/\/\(\\\[\[\^\]\]\+\\\]\|\[\^\[:space:\]\/?:\]\+\)\(:\[0-9\]\+\)\?'/,
'kernel command-line URL discovery recognizes bracketed IPv6 authorities'
);
my $python = `command -v python3 2>/dev/null`;
chomp($python);
SKIP: {
skip 'python3 is unavailable', 4 unless $python;
foreach my $name (qw(baz foo)) {
my ($source) = $pre =~ /cat >\/tmp\/\Q$name\E\.py <<'EOF'\n(.*?)\nEOF/ms;
ok( defined($source), "$name.py installer helper is embedded" ) or next;
$source =~ s/#ENV:MASTER_IP#/2001:db8::1/g;
$source =~ s/#TABLE:site:key=xcatiport:value#/3002/g;
my ( $fh, $path ) = tempfile();
print {$fh} $source;
close($fh);
is(
system( $python, '-c', 'import sys; compile(open(sys.argv[1]).read(), sys.argv[1], "exec")', $path ),
0,
"$name.py remains valid Python after template expansion"
);
}
}
my $format_uri_host = shell_function( $post, 'format_uri_host' );
my $format_host_port = shell_function( $post, 'format_host_port' );
ok( defined($format_uri_host), 'post-install URI host helper is present' );
ok( defined($format_host_port), 'post-install host-port helper is present' );
my $post_helpers = "$format_uri_host\n$format_host_port";
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '192.0.2.10' ),
'192.0.2.10',
'IPv4 URL hosts remain byte-for-byte unchanged'
);
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '2001:db8::10' ),
'[2001:db8::10]',
'IPv6 URL hosts are bracketed'
);
is(
run_shell_function( $post_helpers, 'format_uri_host "$1"', '[2001:db8::10]' ),
'[2001:db8::10]',
'an already-bracketed IPv6 URL host is not double-bracketed'
);
is(
run_shell_function( $post_helpers, 'format_host_port "$1" "$2"', '2001:db8::10', '3001' ),
'[2001:db8::10]:3001',
'OpenSSL receives an unambiguous IPv6 host-port endpoint'
);
like( $post, qr{http://\$\{MASTER_HTTP_HOST\}:\$\{HTTPPORT\}\$INSTALLDIR/postscripts/}, 'postscript tree URL uses the formatted master host' );
like( $post, qr{http://\$\{MASTER_HTTP_HOST\}:\$\{HTTPPORT\}\$TFTPDIR/mypostscripts/}, 'node postscript URL uses the formatted master host' );
unlike( $post, qr{http://\$MASTER_IP:}, 'post-install HTTP URLs never append a port to a raw master address' );
unlike( $post, qr/updateflag(?:\.awk)?\s+"\$MASTER"\s/, 'status callbacks do not depend on a possibly unresolved master hostname' );
is(
scalar( () = $post =~ /updateflag(?:\.awk)?\s+"\$MASTER_IP"\s/g ),
6,
'every EL10 status callback uses the facing master address'
);
like( $updateflag, qr/netfamily = index\(xcatdhost, ":"\) \? "inet6" : "inet"/, 'updateflag selects the gawk IPv6 socket namespace for IPv6 literals' );
like( $updateflag, qr{ns = "/" netfamily "/tcp/0/" xcatdhost "/" xcatdport}, 'updateflag constructs the socket path from the selected family' );
like( $updateflag, qr/xcatdhost ~ \/\^\\\[\.\*\\\]\$\//, 'updateflag accepts a bracketed IPv6 host as input' );
done_testing();
@@ -1,182 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(make_path);
use File::Spec;
use File::Temp qw(tempdir tempfile);
use FindBin;
use Test::More;
my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' );
my $xcatroot = File::Spec->catfile(
$repo_root,
'xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot'
);
open( my $source_fh, '<', $xcatroot ) or die "Unable to read $xcatroot: $!";
my $source = do { local $/; <$source_fh> };
close($source_fh);
is( system( 'bash', '-n', $xcatroot ), 0, 'EL10 stateless xcatroot passes bash syntax validation' );
my ($helpers) = $source =~ m{\A\#!/bin/bash\n(.*?)^log_label=}ms;
ok( defined($helpers), 'test harness extracts the production helper functions' );
my ( $helper_fh, $helper_path ) = tempfile( SUFFIX => '.sh', UNLINK => 1 );
print {$helper_fh} <<'HEADER';
#!/bin/bash
set -u
ip() {
case "$*" in
"-6 -o addr show dev eth1 scope global")
echo "3: eth1 inet6 2001:db8:2::21/64 scope global"
;;
"-6 route show default dev eth1")
echo "default via fe80::1 dev eth1 metric 1024"
;;
*)
return 1
;;
esac
}
HEADER
print {$helper_fh} $helpers;
print {$helper_fh} <<'DISPATCH';
case "$1" in
endpoint)
shift
xcat_endpoint_host "$@"
;;
is-ipv6)
shift
xcat_is_ipv6_boot "$@"
;;
persist)
shift
persist_ipv6_nm_connection "$@"
;;
*)
exit 64
;;
esac
DISPATCH
close($helper_fh);
sub run_helper {
my @args = @_;
open( my $fh, '-|', 'bash', $helper_path, @args )
or die "Unable to run helper harness: $!";
my $output = do { local $/; <$fh> };
close($fh);
return ( $output // '', $? >> 8 );
}
my @endpoint_cases = (
[ '192.0.2.10:3001', '192.0.2.10', 'IPv4 endpoint keeps the legacy host value' ],
[ 'head.example.test:3001', 'head.example.test', 'hostname endpoint keeps the legacy host value' ],
[ '[2001:db8::10]:3001', '2001:db8::10', 'bracketed IPv6 endpoint yields the raw server address' ],
[ '[2001:db8::10]', '2001:db8::10', 'bracketed IPv6 host without a port is accepted' ],
[ '2001:db8::10', '2001:db8::10', 'unbracketed IPv6 host is not truncated at a colon' ],
);
foreach my $case (@endpoint_cases) {
my ( $output, $rc ) = run_helper( 'endpoint', $case->[0] );
is( $rc, 0, "$case->[2] succeeds" );
chomp($output);
is( $output, $case->[1], $case->[2] );
}
for my $iparg ( 'dhcp6', 'eth0:dhcp6', 'eth0:dhcp6:1500' ) {
my ( undef, $rc ) = run_helper( 'is-ipv6', $iparg, 'eth0' );
is( $rc, 0, "ip=$iparg is recognized as an IPv6 boot" );
}
my ( undef, $ipv4_rc ) = run_helper( 'is-ipv6', 'dhcp', '' );
isnt( $ipv4_rc, 0, 'the legacy ip=dhcp argument is not treated as IPv6' );
my $tmpdir = tempdir( CLEANUP => 1 );
my $runtime_connections = File::Spec->catdir( $tmpdir, 'runtime-connections' );
my $copied_root = File::Spec->catdir( $tmpdir, 'copied-root' );
make_path($runtime_connections);
my $runtime_profile = File::Spec->catfile( $runtime_connections, 'initrd.nmconnection' );
open( my $profile_fh, '>', $runtime_profile ) or die "Unable to write $runtime_profile: $!";
print {$profile_fh} "[connection]\nid=initrd\n[ipv6]\nmethod=dhcp\n";
close($profile_fh);
my ( undef, $copy_rc ) = run_helper(
'persist', $copied_root, 'eth0', '02:00:00:00:00:10', $runtime_connections
);
is( $copy_rc, 0, 'runtime NetworkManager profile persistence succeeds' );
my $copied_profile = File::Spec->catfile(
$copied_root, 'etc', 'NetworkManager', 'system-connections', 'initrd.nmconnection'
);
ok( -f $copied_profile, 'the initrd NetworkManager profile is copied into the stateless root' );
is(
( stat($copied_profile) )[2] & oct('07777'),
oct('0600'),
'the persisted NetworkManager profile has private permissions'
);
my $fallback_root = File::Spec->catdir( $tmpdir, 'fallback-root' );
my $empty_source = File::Spec->catdir( $tmpdir, 'empty-connections' );
make_path($empty_source);
my ( undef, $fallback_rc ) = run_helper(
'persist', $fallback_root, 'eth1', '02:00:00:00:00:11', $empty_source
);
is( $fallback_rc, 0, 'IPv6 NetworkManager fallback profile generation succeeds' );
my $fallback_profile = File::Spec->catfile(
$fallback_root, 'etc', 'NetworkManager', 'system-connections', 'xcat-eth1.nmconnection'
);
open( my $fallback_fh, '<', $fallback_profile ) or die "Unable to read $fallback_profile: $!";
my $fallback = do { local $/; <$fallback_fh> };
close($fallback_fh);
like( $fallback, qr/^interface-name=eth1$/m, 'fallback profile binds to the boot interface' );
like( $fallback, qr/^mac-address=02:00:00:00:00:11$/m, 'fallback profile binds to the boot MAC' );
like( $fallback, qr/^\[ipv4\]\nmethod=disabled$/m, 'fallback profile does not enable IPv4' );
like( $fallback, qr/^\[ipv6\]\nmethod=manual$/m, 'fallback profile keeps the static IPv6 handoff after pivot' );
like( $fallback, qr/^address1=2001:db8:2::21\/64$/m, 'fallback profile persists the live IPv6 address and prefix' );
like( $fallback, qr/^gateway=fe80::1$/m, 'fallback profile persists the live IPv6 default gateway' );
unlike( $fallback, qr/^method=dhcp$/m, 'fallback profile does not reintroduce DHCPv6 identity drift' );
is(
( stat($fallback_profile) )[2] & oct('07777'),
oct('0600'),
'fallback NetworkManager profile has private permissions'
);
like(
$source,
qr/^MASTER="\$\(xcat_endpoint_host "\$XCATMASTER"\)"$/m,
'the runtime derives logger and updateflag host from the endpoint parser'
);
like(
$source,
qr{/tmp/updateflag "\$MASTER" "\$XCATIPORT" "installstatus netbooting"},
'updateflag receives the raw server host and the independent install port'
);
like(
$source,
qr/SYSLOGHOST=\(-n "\$MASTER"\)/,
'remote logger receives the raw server host as one argument'
);
like(
$source,
qr/curl --fail --output "\$FILENAME" -- "\$imgurl"/,
'curl receives the bracketed IPv6 URL and output filename as quoted arguments'
);
unlike(
$source,
qr/DHCPV6C=yes/,
'the EL10 stateless pivot does not create a competing DHCPv6 ifcfg profile'
);
like(
$source,
qr/rm -f "\$NEWROOT\/etc\/sysconfig\/network-scripts\/ifcfg-\$ETHX"/,
'the IPv6 path removes a stale legacy ifcfg profile'
);
like(
$source,
qr/echo "BOOTPROTO=dhcp" >> "\$NEWROOT\/etc\/sysconfig\/network-scripts\/ifcfg-\$ETHX"/,
'the existing IPv4 DHCP fallback remains intact'
);
done_testing();
-67
View File
@@ -1,67 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use File::Temp qw(tempfile);
use FindBin;
use Test::More;
my $source = File::Spec->catfile(
$FindBin::Bin, '..', '..',
'xCAT-server/share/xcat/netboot/rh/dracut_105/patch/syslog/rsyslogd-start.sh'
);
open(my $source_fh, '<', $source) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
is(system('sh', '-n', $source), 0, 'initrd rsyslog launcher has valid shell syntax');
sub shell_function {
my ($name) = @_;
my ($definition) = $content =~ /(^\Q$name\E\(\)\s*\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($definition);
return $definition;
}
my $format = shell_function('format_syslog_server');
my $configure = shell_function('rsyslog_config');
my ($template_fh, $template_path) = tempfile();
print {$template_fh} "# base config\n";
close($template_fh);
sub render_config {
my ($server) = @_;
open(
my $pipe, '-|', 'sh', '-c',
"$format\n$configure\nrsyslog_config \"\$1\" \"\$2\" '*.*'",
'sh', $server, $template_path
) or die "Unable to run initrd rsyslog helper: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is($?, 0, "rsyslog configuration renders for $server");
return $output;
}
like(
render_config('192.0.2.10'),
qr/^\*\.\* \@192\.0\.2\.10$/m,
'IPv4 initrd forwarding target remains unchanged'
);
like(
render_config('logs.example.test'),
qr/^\*\.\* \@logs\.example\.test$/m,
'hostname initrd forwarding target remains unchanged'
);
like(
render_config('2001:db8::10'),
qr/^\*\.\* \@\[2001:db8::10\]$/m,
'IPv6 initrd forwarding target is bracketed'
);
like(
render_config('[2001:db8::10]'),
qr/^\*\.\* \@\[2001:db8::10\]$/m,
'already-bracketed IPv6 initrd target is not double-bracketed'
);
done_testing();
-92
View File
@@ -1,92 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Test::More;
sub read_file {
my ($path) = @_;
open(my $fh, '<', $path) or die "Unable to read $path: $!";
my $contents = do { local $/; <$fh> };
close($fh);
return $contents;
}
sub shell_function {
my ($script, $name) = @_;
my ($definition) = $script =~ /(^\Q$name\E\(\)\n\{.*?^\})/ms;
return $definition;
}
sub run_function {
my ($definitions, $invocation, @args) = @_;
open(my $pipe, '-|', 'bash', '-c', "$definitions\n$invocation", 'bash', @args)
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is($?, 0, "$invocation exits successfully");
chomp($output);
return $output;
}
my $postinit_path = "$FindBin::Bin/../../xCAT/postscripts/xcatpostinit1.netboot";
my $installpost_path = "$FindBin::Bin/../../xCAT/postscripts/xcatinstallpost";
my $postinit = read_file($postinit_path);
my $installpost = read_file($installpost_path);
is(system('bash', '-n', $postinit_path), 0, 'stateless post-init script has valid bash syntax');
is(system('bash', '-n', $installpost_path), 0, 'stateful install-post script has valid bash syntax');
my $postinit_endpoint_host = shell_function($postinit, 'xcat_endpoint_host');
ok(defined($postinit_endpoint_host), 'stateless post-init endpoint parser is present');
is(
run_function($postinit_endpoint_host, 'xcat_endpoint_host "$1"', '[2001:db8::1]:3001'),
'2001:db8::1',
'stateless post-init extracts a complete IPv6 host from XCAT'
);
is(
run_function($postinit_endpoint_host, 'xcat_endpoint_host "$1"', '192.0.2.1:3001'),
'192.0.2.1',
'stateless post-init preserves IPv4 endpoint parsing'
);
my $install_endpoint_host = shell_function($installpost, 'xcat_endpoint_host');
my $install_format_host_port = shell_function($installpost, 'format_host_port');
ok(defined($install_endpoint_host), 'stateful postboot endpoint parser is present');
ok(defined($install_format_host_port), 'stateful postboot endpoint formatter is present');
is(
run_function(
"$install_endpoint_host\n$install_format_host_port",
'format_host_port "$1" "$2"',
q{'2001:db8::1'}, 3001
),
'[2001:db8::1]:3001',
'stateful postboot formats an OpenSSL-safe IPv6 endpoint'
);
is(
run_function(
"$install_endpoint_host\n$install_format_host_port",
'format_host_port "$1" "$2"',
'192.0.2.1', 3001
),
'192.0.2.1:3001',
'stateful postboot preserves the IPv4 endpoint form'
);
unlike(
$installpost,
qr/XCATSERVER="\$SIP:3001"/,
'stateful postboot never appends a port to a raw server address'
);
is(
scalar(() = $installpost =~ /updateflag\.awk \\"\\\$MASTER_IP\\" 3002/g),
2,
'stateful boot completion callbacks use the quoted resolved master address'
);
unlike(
$installpost,
qr/updateflag\.awk \\\$MASTER 3002/,
'stateful boot completion callbacks do not use an unresolved master hostname'
);
done_testing();
-92
View File
@@ -1,92 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use FindBin;
use Test::More;
my $source = File::Spec->catfile(
$FindBin::Bin, '..', '..', 'xCAT', 'postscripts', 'syslog'
);
open( my $source_fh, '<', $source ) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($definition) =
$content =~ /(^\Q$name\E\(\)\s*\n\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($definition);
return $definition;
}
sub run_shell_function {
my ( $definition, $invocation, @args ) = @_;
open( my $pipe, '-|', 'bash', '-c', "$definition\n$invocation", 'bash', @args )
or die "Unable to run bash: $!";
my $output = do { local $/; <$pipe> };
close($pipe);
is( $?, 0, "$invocation exits successfully" );
chomp($output);
return $output;
}
is( system( 'bash', '-n', $source ), 0, 'syslog postscript has valid bash syntax' );
my $format_target = shell_function('format_syslog_forward_target');
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '192.0.2.10' ),
'192.0.2.10',
'IPv4 rsyslog targets remain byte-for-byte unchanged'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', 'logs.example.test' ),
'logs.example.test',
'hostname rsyslog targets remain byte-for-byte unchanged'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '2001:db8::10' ),
'[2001:db8::10]',
'IPv6 rsyslog targets are bracketed to disambiguate address colons from a port'
);
is(
run_shell_function( $format_target, 'format_syslog_forward_target "$1"', '[2001:db8::10]' ),
'[2001:db8::10]',
'an already-bracketed IPv6 rsyslog target is not double-bracketed'
);
my $syslog_ng_driver = shell_function('syslog_ng_udp_driver');
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', '192.0.2.10' ),
'udp',
'syslog-ng keeps its legacy IPv4 UDP destination for IPv4 targets'
);
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', 'logs.example.test' ),
'udp',
'syslog-ng keeps name resolution behavior for hostname targets'
);
is(
run_shell_function( $syslog_ng_driver, 'syslog_ng_udp_driver "$1"', '2001:db8::10' ),
'udp6',
'syslog-ng selects its IPv6 UDP destination for an IPv6 literal'
);
unlike(
$content,
qr/echo\s+"[^"\n]*@\$master/,
'no rsyslog or traditional syslog forwarding rule appends a raw master address'
);
is(
scalar( () = $content =~ /echo\s+"[^"\n]*@\$syslog_forward_target/g ),
5,
'all selector-style forwarding paths use the family-safe target'
);
like(
$content,
qr/syslog_ng_driver=\$\(syslog_ng_udp_driver "\$master"\).*?\$\{syslog_ng_driver\}\(\\"\$master\\"\)/s,
'syslog-ng emits the selected address-family-specific destination driver'
);
done_testing();
-81
View File
@@ -1,81 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Temp qw(tempfile);
use Test::More;
my $source = "$FindBin::Bin/../../xCAT/postscripts/xcatdsklspost";
open(my $source_fh, '<', $source) or die "Unable to read $source: $!";
my $content = do { local $/; <$source_fh> };
close($source_fh);
sub shell_function {
my ($name) = @_;
my ($function) = $content =~ /^(\Q$name\E \(\)\n\{.*?^\})/ms;
die "Unable to extract $name from $source" unless defined($function);
return $function;
}
my ($fh, $script) = tempfile();
print {$fh} shell_function('parsehttpserver'), "\n";
print {$fh} shell_function('format_host_port'), "\n";
print {$fh} <<'SHELL';
set -e
check() {
expected=$1
shift
actual="$($@)"
[ "$actual" = "$expected" ] || {
echo "expected '$expected', got '$actual' from: $*" >&2
exit 1
}
}
check 192.0.2.10 parsehttpserver 192.0.2.10 server
check 80 parsehttpserver 192.0.2.10 port
check manager.example.test parsehttpserver manager.example.test:8080 server
check 8080 parsehttpserver manager.example.test:8080 port
check 2001:db8::10 parsehttpserver '[2001:db8::10]:8443' server
check 8443 parsehttpserver '[2001:db8::10]:8443' port
check 2001:db8::10 parsehttpserver 2001:db8::10 server
check 80 parsehttpserver 2001:db8::10 port
check 2001:db8::10 parsehttpserver '[2001:db8::10]' server
check 80 parsehttpserver '[2001:db8::10]' port
check 192.0.2.10:3001 format_host_port 192.0.2.10 3001
check manager.example.test:3001 format_host_port manager.example.test 3001
check '[2001:db8::10]:3001' format_host_port 2001:db8::10 3001
check '[2001:db8::10]:3001' format_host_port '[2001:db8::10]' 3001
SHELL
close($fh);
is(system('bash', $script), 0, 'endpoint helpers preserve IPv4 and support bracketed IPv6');
like(
$content,
qr/wget .*"http:\/\/\$authority\$INSTALLDIR\/postscripts\/"/,
'recursive postscript download quotes the normalized HTTP authority'
);
like(
$content,
qr/XCATSERVER=\$\(format_host_port "\$SIP" 3001\)/,
'runtime xCAT endpoint is formatted with IPv6 brackets when needed'
);
unlike(
$content,
qr/(?:XCATSERVER|SIP)=`echo \$(?:TMP|i) \| cut -d: -f1`/,
'kernel XCAT endpoint is not truncated at the first IPv6 colon'
);
is(
scalar(() = $content =~ /updateflag\.awk \\\"\\\$MASTER_IP\\\" 3002/g),
4,
'all generated boot completion callbacks use the quoted resolved master address'
);
unlike(
$content,
qr/updateflag\.awk \\\$MASTER 3002/,
'generated boot completion callbacks do not use an unresolved master hostname'
);
done_testing();