2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00

Merge pull request #8038 from VersatusHPC/codex/r220-test-correctness

test(provision): exercise complete installer and netboot scripts
This commit is contained in:
Daniel Hilst
2026-12-01 13:09:47 -03:00
committed by GitHub
9 changed files with 283 additions and 198 deletions
+15 -2
View File
@@ -9,7 +9,7 @@ jobs:
- name: Refresh package indexes
run: sudo apt-get update
- name: Install dependencies
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests bats bubblewrap cpio xz-utils gzip gawk mawk jq socat rpm rsyslog build-essential fakeroot reprepro devscripts debhelper libcapture-tiny-perl libfile-slurper-perl libjson-perl libjson-xs-perl libyaml-pp-perl libparallel-forkmanager-perl libsoap-lite-perl libdbi-perl libdbd-sqlite3-perl libcgi-pm-perl quilt openssh-server dpkg looptools genometools software-properties-common grub-common grub-efi-amd64-bin squashfs-tools pigz python3-yaml
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests bats bubblewrap cpio xz-utils gzip gawk mawk jq socat rpm rsyslog build-essential fakeroot reprepro devscripts debhelper libcapture-tiny-perl libfile-slurper-perl libjson-perl libjson-xs-perl libyaml-pp-perl libparallel-forkmanager-perl libsoap-lite-perl libdbi-perl libdbd-sqlite3-perl libcgi-pm-perl quilt openssh-server dpkg looptools genometools software-properties-common grub-common grub-efi-amd64-bin squashfs-tools pigz python3-yaml netcat-openbsd
- name: Enable postscript test namespaces
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
- name: Install lifecycle test dependencies
@@ -55,6 +55,19 @@ jobs:
- name: Prepare xCAT syslog directory
if: ${{ !cancelled() }}
run: sudo install -d -o syslog -g adm -m 0750 /var/log/xcat
- name: Test native syslog receiver cleanup
if: ${{ !cancelled() }}
run: |
set -o pipefail
log=$(mktemp)
trap 'rm -f "$log"' EXIT
docker run --rm --init --privileged --security-opt apparmor=unconfined \
-v "$PWD:/src:ro" -w /src ubuntu:24.04 bash -ec '
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
perl rsyslog iproute2 util-linux systemd gawk
prove -v xCAT-test/native/syslog_openeuler.t' 2>&1 | tee "$log"
! grep -Eq 'skipped:|Result: NOTESTS' "$log"
- name: Run Ubuntu image fixture tests
if: ${{ !cancelled() }}
run: >-
@@ -113,7 +126,7 @@ jobs:
run: |
log=$(mktemp)
trap 'rm -f -- "$log"' EXIT
prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/post_rhels8_link_nics.t xCAT-test/native/selinux_kickstart_relabel.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log"
prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/post_rhels8_link_nics.t xCAT-test/native/selinux_kickstart_relabel.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/openeuler_pre_partition.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log"
! grep -qi skipped "$log"
rpm_lifecycle_test:
runs-on: ubuntu-24.04
@@ -1,92 +0,0 @@
#!/usr/bin/env bats
load 'helpers/shell_source'
setup()
{
SYSLOG="$(repo_path 'xCAT/postscripts/syslog')"
[ -r "$SYSLOG" ] || skip "$SYSLOG is required"
RECEIVER_FUNCTION="${BATS_TEST_TMPDIR}/receiver.bash"
extract_shell_function "$SYSLOG" config_native_rsyslog_receiver >"$RECEIVER_FUNCTION"
RECEIVER_CONF="${BATS_TEST_TMPDIR}/rsyslog.conf"
ALLOCATED_PATH="${BATS_TEST_TMPDIR}/expanded config"
ALLOCATION_OUTPUT="$ALLOCATED_PATH"
ALLOCATION_STATUS=0
VALIDATION_STATUS=0
RSYSLOG_LOG="${BATS_TEST_TMPDIR}/rsyslog.log"
REMOVE_LOG="${BATS_TEST_TMPDIR}/remove.log"
printf '# existing configuration\n' >"$RECEIVER_CONF"
}
run_receiver()
{
local conf_file="$RECEIVER_CONF"
mktemp()
{
[ "$ALLOCATION_STATUS" -eq 0 ] || return "$ALLOCATION_STATUS"
if [ -n "$ALLOCATION_OUTPUT" ]; then
: >"$ALLOCATION_OUTPUT"
printf '%s\n' "$ALLOCATION_OUTPUT"
fi
}
rsyslogd()
{
printf '%s\n' "$@" >"$RSYSLOG_LOG"
[ "$VALIDATION_STATUS" -eq 0 ] || return "$VALIDATION_STATUS"
if [ -n "$5" ]; then
cat "$3" >"$5"
fi
}
rm()
{
printf '%s\n' "$@" >"$REMOVE_LOG"
command rm "$@"
}
source "$RECEIVER_FUNCTION"
config_native_rsyslog_receiver "$RECEIVER_CONF"
}
@test "native syslog receiver removes its expanded configuration after success" {
run run_receiver
[ "$status" -eq 0 ]
[ "$(cat "$REMOVE_LOG")" = "$(printf '%s\n' -f "$ALLOCATED_PATH")" ]
[ ! -e "$ALLOCATED_PATH" ]
[ "$(cat "$RECEIVER_CONF")" = $'# existing configuration\nmodule(load="imudp")\ninput(type="imudp" port="514")\nmodule(load="imtcp")\ninput(type="imtcp" port="514")' ]
}
@test "native syslog receiver removes its expanded configuration after validation fails" {
VALIDATION_STATUS=37
run run_receiver
[ "$status" -eq 37 ]
[ "$(cat "$REMOVE_LOG")" = "$(printf '%s\n' -f "$ALLOCATED_PATH")" ]
[ ! -e "$ALLOCATED_PATH" ]
[ "$(cat "$RECEIVER_CONF")" = '# existing configuration' ]
}
@test "native syslog receiver returns an allocation failure before validation or cleanup" {
ALLOCATION_STATUS=43
run run_receiver
[ "$status" -eq 43 ]
[ ! -e "$RSYSLOG_LOG" ]
[ ! -e "$REMOVE_LOG" ]
[ ! -e "$ALLOCATED_PATH" ]
[ "$(cat "$RECEIVER_CONF")" = '# existing configuration' ]
}
@test "native syslog receiver skips cleanup when allocation succeeds with an empty path" {
ALLOCATION_OUTPUT=
run run_receiver
[ "$status" -eq 0 ]
[ -s "$RSYSLOG_LOG" ]
[ ! -e "$REMOVE_LOG" ]
[ "$(cat "$RECEIVER_CONF")" = '# existing configuration' ]
}
+52 -5
View File
@@ -312,12 +312,59 @@ check_each_script()
check_each_script 'packed image' "$URL " 0 'Cannot receive .*rootimg.cpio.gz over UFTP'
}
@test 'the EL10 initial ramdisk copies no dhclient lease and writes no ifcfg file' {
SCRIPTS='xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot bash'
# Leave the legacy input and output paths usable, so a silent copy would succeed.
check_el10_handoff()
{
local script=$1 image=${2:-rootimg.cpio.gz}
local initrd_etc=(--tmpfs /etc --ro-bind "$FX/resolv.conf" /etc/resolv.conf)
[ ! -d /etc/alternatives ] || initrd_etc+=(--ro-bind /etc/alternatives /etc/alternatives)
mkdir -p "$FX/tree/etc/sysconfig/network-scripts" "$FX/tree/var/lib/dhclient" \
"$FX/tree/.statelite" "$FX/tree/etc/init.d" "$FX/initrd-tmp" "$FX/hooks/initqueue" "$FX/newroot"
printf 'existing lease\n' >"$FX/tree/var/lib/dhclient/dhclient-eth1.leases"
printf 'existing configuration\n' >"$FX/tree/etc/sysconfig/network-scripts/ifcfg-eth1"
printf 'lease for eth0\n' >"$FX/initrd-tmp/dhclient.eth0.lease"
printf 'nameserver 192.0.2.53\n' >"$FX/resolv.conf"
for tool in localdisk statelite; do
printf '#!/bin/sh\nprintf "%%s\\n" %s >>/fx/init-scripts\n' "$tool" >"$FX/tree/etc/init.d/$tool"
chmod +x "$FX/tree/etc/init.d/$tool"
done
printf '#!/bin/sh\nexit 0\n' >"$FX/bin/modprobe"
chmod +x "$FX/bin/modprobe"
(cd "$FX/tree" && find . | cpio -H newc -o 2>/dev/null | gzip -c) >"$FX/served/$image"
(cd "$FX/served" && sha256sum "$image" >"$image.sha256")
URL="http://192.0.2.1:80//install/netboot/img/$image"
case "$script" in *xcat-prepivot.sh) cp -a "$FX/tree/." "$FX/newroot/" ;; esac
KERNEL_ARGS='ifname=eth0:52:54:00:12:34:56'
check_each_script 'packed image' "$URL.sha256 $URL $URL.sha256 " 0 ''
run grep -E 'dhclient|network-scripts' "$FX/console"
[ "$status" -eq 1 ] || { echo "$output"; return 1; }
run_xcatroot "$script" bash \
--bind "$FX/newroot" /sysroot --bind "$FX/initrd-tmp" /tmp --bind "$FX/hooks" /hooks \
"${initrd_etc[@]}" --setenv hookdir /hooks \
--setenv BASH_ENV /lib/dracut-lib.sh --setenv ifname eth0:52:54:00:12:34:56
case "$script" in
*xcat-prepivot.sh) ;;
*) [ "$(cat "$FX/extracted")" = 'packed image' ] ;;
esac
cmp "$FX/resolv.conf" "$FX/newroot/etc/resolv.conf"
[ -s "$FX/hooks/initqueue/xcat.sh" ]
[ -f "$FX/hooks/initqueue/work" ]
[ "$(find "$FX/newroot/var/lib/dhclient" -mindepth 1 -printf '%f\n')" = dhclient-eth1.leases ]
[ "$(cat "$FX/newroot/var/lib/dhclient/dhclient-eth1.leases")" = 'existing lease' ]
[ "$(find "$FX/newroot/etc/sysconfig/network-scripts" -mindepth 1 -printf '%f\n')" = ifcfg-eth1 ]
[ "$(cat "$FX/newroot/etc/sysconfig/network-scripts/ifcfg-eth1")" = 'existing configuration' ]
case "$script" in
*/statelite/*) [ "$(cat "$FX/init-scripts")" = "$(printf 'localdisk\nstatelite')" ] ;;
esac
}
@test 'the EL10 stateless handoff leaves leases and ifcfg files unchanged' {
check_el10_handoff xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot
}
@test 'the EL10 statelite image handoff leaves leases and ifcfg files unchanged' {
check_el10_handoff xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcatroot rootimg-statelite.gz
}
@test 'the EL10 statelite prepivot handoff leaves leases and ifcfg files unchanged' {
check_el10_handoff xCAT-server/share/xcat/netboot/rh/dracut_105/statelite/xcat-prepivot.sh
}
@test 'the Ubuntu xcatroot reads its kernel arguments when systemd starts it without them' {
+29 -2
View File
@@ -151,6 +151,19 @@ sudo prove xCAT-test/native/ip_forwarding.t \
xCAT-test/native/syslog_openeuler*.t
```
The syslog receiver case runs the whole postscript with the native rsyslog
parser and real TCP/UDP messages in a private network namespace. It checks
temporary-file cleanup after success and parser failure, and injects an
allocation failure at the `mktemp` command boundary. It isolates `/dev`, masks
the kernel log, drops CAP_SYS_ADMIN and CAP_SYSLOG after setup, and uses a
private PID namespace. The native rsyslog binary is bound at a fixture path
to avoid the host service's AppArmor
attachment; this test does not validate that service profile. CI runs it in a
disposable Ubuntu container and rejects skips. It needs rsyslog, util-linux and
iproute2; service activation uses a stub that starts only the test daemon.
On EL10, install `util-linux`; `util-linux-core` alone does not provide `setpriv`.
Use the CI container on AppArmor hosts instead of the direct-root command above.
The mock result directory case needs the mock Python library, and root for its
ownership checks. The staged sources case needs root to read the sources as uid
1000. The `xcat_test` workflow runs both as root in a Fedora container:
@@ -462,13 +475,27 @@ prove xCAT-test/native/install_profile_riscv64.t \
xCAT-test/native/netboot_profile_postinstall.t \
xCAT-test/native/builddebs_riscv64.t \
xCAT-test/native/ubuntu_subiquity_template.t \
xCAT-test/native/ubuntu_subiquity_install_disk.t
xCAT-test/native/ubuntu_subiquity_install_disk.t \
xCAT-test/native/openeuler_pre_partition.t
```
The renderers need the system Perl with the xCAT dependencies, XML::Simple,
DBD::SQLite, Capture::Tiny, and File::Slurper. The sandbox clears the environment
and does not mount perlbrew or local::lib directories. The Subiquity cases also
need /usr/bin/python3 with PyYAML; on EL8, install python36 for that path.
need /usr/bin/python3 with PyYAML. On EL8, install python39 and python39-pyyaml,
then select /usr/bin/python3.9 through the python3 alternatives group.
The install-disk case runs the complete rendered pre-install scripts. It needs
netcat at `/usr/bin/nc` (`netcat-openbsd` on Ubuntu) as a mount point for its
network boundary stub. Service management, logging and the install monitor
use stubs; partition selection and storage-layout validation run unchanged.
The openEuler partition case runs the rendered Kickstart `%pre` block without
rewriting paths. It supplies private firmware and partition tables, with
command fixtures for disks, LVM and logging. Tool discovery uses native find
over a private directory; the fallback case rejects calls to awk. It covers
BIOS, UEFI and POWER layouts and administrator overrides for openEuler and
the shared EL8 script.
These architecture cases simulate firmware and disk discovery; they do not
boot hardware or write a partition table.
The Debian case needs debhelper, devscripts, fakeroot, and reprepro, and skips
on non-Debian hosts. Each case creates its own temporary files and database.
The temporary directory must allow execution; set TMPDIR if /tmp is noexec.
@@ -1,43 +1,45 @@
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'once';
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use File::Slurper qw(read_text write_text);
use Test::More;
use XCAT::Test::File qw(repo_path);
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
use XCAT::Test::Template qw(template_database set_row render_template);
plan skip_all => 'pre-install scripts require Linux bash' unless $^O eq 'linux' && -x '/bin/bash';
my $tmp = tempdir(CLEANUP => 1);
make_path("$tmp/db", "$tmp/bin");
$ENV{XCATROOT} = repo_path('xCAT-server');
$ENV{XCATCFG} = "SQLite:$tmp/db";
require xCAT::Table;
require xCAT::Template;
%::XCATSITEVALS = (xcatdebugmode => 0, nodestatus => 0, secureroot => 1, httpport => 80, xcatiport => 3002);
my $site = xCAT::Table->new('site', -create => 1);
for my $key (keys %::XCATSITEVALS) {
$site->setAttribs({key => $key}, {value => $::XCATSITEVALS{$key}});
}
$site->close();
plan skip_all => 'pre-install scripts require Linux namespaces' unless $^O eq 'linux';
my $database = template_database();
set_row('site', {key => 'nodestatus'}, {value => 0});
sub write_file {
my ($path, $contents) = @_;
open(my $fh, '>', $path) or die "$path: $!";
print {$fh} $contents;
close($fh) or die "$path: $!";
}
sub read_file {
my ($path) = @_;
open(my $fh, '<', $path) or die "$path: $!";
local $/;
return <$fh> // '';
}
write_file("$tmp/bin/double", <<'SH');
sub installer_root {
my ($efi, $sectors, $discover_awk) = @_;
my $root = sandbox_root();
make_path("$root/proc", "$root/firmware", "$root/libexec", "$root/log/xcat", "$root/discovery");
make_path("$root/firmware/efi") if $efi;
write_text("$root/proc/cmdline", "inst.ks=http://192.0.2.1/node.ks\n");
write_text("$root/proc/partitions", "major minor #blocks name\n\n 252 0 " . ($sectors / 2) . " vda\n");
write_text("$root/discovery/awk", '') if $discover_awk;
unless ($discover_awk) {
write_text("$root/bin/awk", "#!/bin/sh\n: > /fixture/awk-called\nexit 127\n");
chmod 0755, "$root/bin/awk" or die $!;
}
# Keep tool discovery independent of the host's installed software.
write_text("$root/bin/find", <<'SH');
#!/bin/sh
case "$1" in
/usr/*) exec /usr/bin/find /fixture/discovery -name awk ;;
*) exec /usr/bin/find "$@" ;;
esac
SH
chmod 0755, "$root/bin/find" or die $!;
write_text("$root/libexec/platform-python", '#!/bin/sh' . "\n" . 'exec /usr/bin/python3 "$@"' . "\n");
chmod 0755, "$root/libexec/platform-python" or die $!;
write_text("$root/bin/double", <<'SH');
#!/bin/bash
case "${0##*/}" in
uname) printf '%s\n' "$XCAT_PART_ARCH" ;;
@@ -47,12 +49,15 @@ case "${0##*/}" in
*--attribute-walk*) printf 'ATTR{size}=="%s"\nDRIVERS=="virtio_blk"\n' "$XCAT_PART_SECTORS" ;;
*) printf 'DEVTYPE=disk\nDEVPATH=/devices/pci0000:00/virtio0/block/vda\nID_WWN=0x1234\n' ;;
esac ;;
mknod) : >"$1" ;;
*) exit 0 ;;
esac
SH
chmod 0755, "$tmp/bin/double";
for my $name (qw(uname blockdev udevadm mknod chown vgs vgchange vgremove logger python3)) {
symlink 'double', "$tmp/bin/$name" or die $!;
chmod 0755, "$root/bin/double" or die $!;
for my $name (qw(uname blockdev udevadm mknod chown vgs vgchange vgremove logger)) {
symlink 'double', "$root/bin/$name" or die $!;
}
return $root;
}
my $small = 62914560;
my $large = 8589934592;
@@ -73,51 +78,46 @@ my @cases = (
['native BIOS script custom', 'openeuler', 'x86_64', 0, $small, 0, 0, 0, 'xfs', 'script'],
['native UEFI custom', 'openeuler', 'x86_64', 1, $small, 0, 0, 0, 'xfs', 'static'],
['native POWER custom', 'openeuler', 'ppc64le', 0, $large, 0, 0, 0, 'ext4', 'static'],
['native BIOS without awk discovery', 'openeuler', 'x86_64', 0, $small, 1, 0, 0, 'xfs', undef, 0],
);
my $sequence = 0;
for my $case (@cases) {
my ($label, $platform, $arch, $efi, $sectors, $bios, $esp, $prep, $fstype, $custom) = @$case;
my $fixture = tempdir(DIR => $tmp, CLEANUP => 1);
make_path(map { "$fixture/$_" } qw(tmp dev proc sys/firmware var/log/xcat etc));
make_path("$fixture/sys/firmware/efi") if $efi;
write_file("$fixture/proc/cmdline", "inst.ks=http://192.0.2.1/node.ks\n");
write_file("$fixture/proc/partitions", "major minor #blocks name\n252 0 " . ($sectors / 2) . " vda\n");
my $template = "$fixture/input.tmpl";
write_file($template, "#XCAT_PARTITION_START#\n%include /tmp/partitionfile\n#XCAT_PARTITION_END#\n%pre\n#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.$platform#\n%end\n");
my ($label, $platform, $arch, $efi, $sectors, $bios, $esp, $prep, $fstype, $custom, $discover_awk) = @$case;
$discover_awk //= 1;
my $fixture = installer_root($efi, $sectors, $discover_awk);
my $render = "$database/case-" . ++$sequence;
make_path($render);
my $template = "$render/input.tmpl";
write_text($template, "#XCAT_PARTITION_START#\n%include /tmp/partitionfile\n#XCAT_PARTITION_END#\n%pre\n#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.$platform#\n%end\n");
my $partition = '';
my $custom_data = "part / --fstype=ext4 --ondisk=vda --size=4096\nbootloader --boot-drive=vda\n";
if ($custom) {
$partition = "$fixture/custom";
$partition = "$render/custom";
if ($custom eq 'script') {
write_file($partition, "#!/bin/bash\ncat > \"\$XCAT_PART_FIXTURE/tmp/partitionfile\" <<'EOF'\n$custom_data" . "EOF\n");
write_text($partition, "#!/bin/bash\ncat > /tmp/partitionfile <<'EOF'\n$custom_data" . "EOF\n");
$partition = "s:$partition";
} else {
write_file($partition, $custom_data);
write_text($partition, $custom_data);
}
}
local $ENV{PERSKCMDLINE} = '';
local $ENV{MASTER_IP} = '192.0.2.1';
my $error = xCAT::Template->subvars($template, "$fixture/output.ks", 'node', undef,
render_template($database, $template, "$render/output.ks", 'node', undef,
'/install/media', $platform eq 'openeuler' ? 'openeuler' : 'rh', $partition,
{xcatmaster => '192.0.2.1'});
ok(!$error, "$label renders through the production Template entry point") or diag($error);
my $rendered = read_file("$fixture/output.ks");
my $rendered = read_text("$render/output.ks");
my ($pre) = $rendered =~ /^%pre[^\n]*\n(.*?)^%end/ms;
defined($pre) or die 'rendered Kickstart did not contain a pre-install script';
$pre =~ s{(?<![[:alnum:]_/:])(/(?:tmp|dev|proc|sys|etc|var)(?=/|\b)|/foo\.log)}{$fixture$1}g;
$pre =~ s{/(?:usr/bin/python3|usr/libexec/platform-python)}{$tmp/bin/python3}g;
write_file("$fixture/pre.sh", $pre);
my ($rc, $output);
{
local %ENV = (%ENV, PATH => "$tmp/bin:/usr/bin:/bin:/usr/sbin:/sbin", XCAT_PART_ARCH => $arch,
XCAT_PART_SECTORS => $sectors, XCAT_PART_FIXTURE => $fixture);
delete @ENV{qw(XCAT_BIOSBOOT XCAT_BOOT_FSTYPE XCAT_ROOT_FSTYPE XCAT_INSTALL_PYTHON)};
open(my $pipe, '-|', 'sh', '-c', 'exec "$@" 2>&1', 'sh', '/bin/bash', "$fixture/pre.sh") or die $!;
$output = do {local $/; <$pipe>};
close($pipe);
$rc = (($? & 127) ? 128 + ($? & 127) : $? >> 8);
ok(defined $pre, "$label renders a Kickstart pre-install script") or die 'missing %pre block';
write_text("$fixture/pre.sh", $pre);
my ($rc, $output) = sandbox_run($fixture, {
read_only => {"$fixture/proc/cmdline" => '/proc/cmdline', "$fixture/proc/partitions" => '/proc/partitions',
"$fixture/firmware" => '/sys/firmware', "$fixture/libexec" => '/usr/libexec'},
env => {XCAT_PART_ARCH => $arch, XCAT_PART_SECTORS => $sectors},
}, '/bin/bash', '/fixture/pre.sh');
unless (is($rc, 0, "$label executes the complete generated pre-install script")) {
diag($output);
diag(read_text("$fixture/log/xcat/xcat.log")) if -f "$fixture/log/xcat/xcat.log";
}
is($rc, 0, "$label executes the complete generated pre-install script") or diag($output);
my $layout = read_file("$fixture/tmp/partitionfile");
ok(!-e "$fixture/awk-called", "$label does not require awk") unless $discover_awk;
my $layout = -f "$fixture/tmp/partitionfile" ? read_text("$fixture/tmp/partitionfile") : '';
is(scalar(() = $layout =~ /^part biosboot\b/gm), $bios, "$label BIOS boot partition count");
is(scalar(() = $layout =~ m{^part /boot/efi\b}gm), $esp, "$label EFI system partition count");
is(scalar(() = $layout =~ /^part prepboot\b/gm), $prep, "$label PReP boot partition count");
@@ -126,7 +126,7 @@ for my $case (@cases) {
$custom_data =~ s/\s+\z//;
is($layout, $custom_data, "$label replaces all generated defaults with the administrator's layout");
} else {
my $disk = "$fixture/dev/vda";
my $disk = '/dev/vda';
like($layout, qr/^ignoredisk --only-use=\Q$disk\E$/m, "$label retains actual selected disk");
like($layout, qr/^part biosboot --ondisk=\Q$disk\E --size=1$/m, "$label reserves one MiB on the selected disk") if $bios;
like($layout, qr{^part /boot --fstype=$fstype }m, "$label retains boot filesystem policy");
+85 -16
View File
@@ -9,13 +9,14 @@ use FindBin;
use Test::More;
plan skip_all => 'requires Linux root and mount/network namespaces' unless $^O eq 'linux' && $> == 0;
plan skip_all => 'namespaces unavailable' if system('unshare -mn -- true >/dev/null 2>&1');
plan skip_all => 'requires native rsyslogd, logger, ip and ss'
if system('command -v rsyslogd logger ip ss >/dev/null');
plan skip_all => 'namespaces unavailable' if system('unshare -mnpf --mount-proc -- true >/dev/null 2>&1');
plan skip_all => 'requires native rsyslogd, logger, ip, ss and setpriv'
if system(q{for tool in rsyslogd logger ip ss setpriv; do command -v "$tool" >/dev/null || exit 1; done});
my $source = $ENV{XCAT_SYSLOG_SOURCE_ROOT} || abs_path("$FindBin::Bin/../..");
my $tmp = tempdir(DIR => '/var/tmp', CLEANUP => !$ENV{XCAT_SYSLOG_KEEP});
diag("fixtures: $tmp") if $ENV{XCAT_SYSLOG_KEEP};
make_path("$tmp/bin");
symlink(abs_path('/usr/bin/awk'), "$tmp/bin/awk") or die $!;
sub write_file {
my ($path, $contents) = @_;
open(my $fh, '>', $path) or die "$path: $!";
@@ -32,6 +33,7 @@ sub read_file {
for my $name (qw(syslog xcatlib.sh)) {
copy("$source/xCAT/postscripts/$name", "$tmp/bin/$name") or die $!;
}
write_file("$tmp/bin/native-rsyslogd", '');
write_file("$tmp/bin/systemctl", <<'SH');
#!/bin/bash
printf '%s\n' "$*" >> "$XCAT_SYSLOG_FIXTURE/services.log"
@@ -41,23 +43,52 @@ if [ -s /run/rsyslog-test.pid ]; then
kill "$(cat /run/rsyslog-test.pid)"
for i in {1..50}; do [ -f /run/rsyslog-test.pid ] || break; sleep .1; done
fi
exec /usr/sbin/rsyslogd -i /run/rsyslog-test.pid -f /etc/rsyslog.conf
exec "$XCAT_SYSLOG_BIN/native-rsyslogd" -i /run/rsyslog-test.pid -f /etc/rsyslog.conf
SH
write_file("$tmp/bin/logger", <<'SH');
#!/bin/bash
printf '%s\n' "$*" >> "$XCAT_SYSLOG_FIXTURE/logger.log"
SH
write_file("$tmp/bin/mktemp", <<'SH');
#!/bin/sh
printf 'allocate\n' >>"$XCAT_SYSLOG_FIXTURE/allocation-attempts"
[ "$XCAT_SYSLOG_FAIL" != allocation ] || exit 43
path=$(/usr/bin/mktemp "$@") || exit $?
printf '%s\n' "$path" >>"$XCAT_SYSLOG_FIXTURE/allocated"
printf '%s\n' "$path"
SH
write_file("$tmp/bin/rsyslogd", <<'SH');
#!/bin/sh
printf '%s\n' "$*" >>"$XCAT_SYSLOG_FIXTURE/rsyslog-calls"
exec "$XCAT_SYSLOG_BIN/native-rsyslogd" "$@"
SH
write_file("$tmp/bin/namespace", <<'SH');
#!/bin/bash
set -eu
mount --make-rprivate /
# A private executable path avoids the host service's AppArmor attachment.
mount --bind /usr/sbin/rsyslogd "$XCAT_SYSLOG_BIN/native-rsyslogd"
for device in null zero random urandom; do
mount --bind "/dev/$device" "$XCAT_SYSLOG_FIXTURE/dev/$device"
done
mount --rbind "$XCAT_SYSLOG_FIXTURE/dev" /dev
mkfifo "$XCAT_SYSLOG_FIXTURE/kmsg"
exec {kmsg_writer}<>"$XCAT_SYSLOG_FIXTURE/kmsg"
mount --bind "$XCAT_SYSLOG_FIXTURE/kmsg" /proc/kmsg
mount --bind "$XCAT_SYSLOG_FIXTURE/etc" /etc
mount --bind "$XCAT_SYSLOG_FIXTURE/log" /var/log
mount --bind "$XCAT_SYSLOG_FIXTURE/run" /run
mount --bind "$XCAT_SYSLOG_FIXTURE/state" /var/lib/rsyslog
mount --bind "$XCAT_SYSLOG_FIXTURE/lib" /var/lib
mount --bind "$XCAT_SYSLOG_FIXTURE/spool" /var/spool
mount --bind "$XCAT_SYSLOG_FIXTURE/tmp" /tmp
ip link set lo up
exec setpriv --bounding-set=-sys_admin,-syslog -- "$XCAT_SYSLOG_BIN/run"
SH
write_file("$tmp/bin/run", <<'SH');
#!/bin/bash
set -eu
trap 'for f in /run/*pid; do [ ! -f "$f" ] || kill "$(cat "$f")" 2>/dev/null || :; done' EXIT
/usr/sbin/rsyslogd -i /run/upstream.pid -f "$XCAT_SYSLOG_FIXTURE/upstream.conf"
"$XCAT_SYSLOG_BIN/native-rsyslogd" -i /run/upstream.pid -f "$XCAT_SYSLOG_FIXTURE/upstream.conf"
for pass in 1 2; do
set +e
bash "$XCAT_SYSLOG_BIN/syslog" > "$XCAT_SYSLOG_FIXTURE/postscript-$pass.log" 2>&1
@@ -66,10 +97,11 @@ for pass in 1 2; do
echo "$rc" > "$XCAT_SYSLOG_FIXTURE/postscript-$pass.rc"
cp /etc/rsyslog.conf "$XCAT_SYSLOG_FIXTURE/config-$pass"
cp /etc/rsyslog.d/remote.conf "$XCAT_SYSLOG_FIXTURE/remote-$pass" 2>/dev/null || :
find /tmp -mindepth 1 -printf '%P\n' >"$XCAT_SYSLOG_FIXTURE/temporary-$pass"
[ "$rc" -eq 0 ] || break
done
set +e
/usr/sbin/rsyslogd -N1 -f /etc/rsyslog.conf > "$XCAT_SYSLOG_FIXTURE/parser.log" 2>&1
"$XCAT_SYSLOG_BIN/native-rsyslogd" -N1 -f /etc/rsyslog.conf > "$XCAT_SYSLOG_FIXTURE/parser.log" 2>&1
echo "$?" > "$XCAT_SYSLOG_FIXTURE/parser.rc"
set -e
ss -H -lun 'sport = :514' > "$XCAT_SYSLOG_FIXTURE/udp-514"
@@ -92,15 +124,15 @@ for i in {1..30}; do
sleep .1
done
SH
chmod 0755, "$tmp/bin/$_" for qw(systemctl logger namespace);
chmod 0755, "$tmp/bin/$_" for qw(systemctl logger mktemp rsyslogd namespace run);
my $default = read_file('/etc/rsyslog.conf');
my $minimal = "global(workDirectory=\"/var/lib/rsyslog\")\ninclude(file=\"/etc/rsyslog.d/*.conf\" mode=\"optional\")\n*.info /var/log/messages\n";
my $modern = "module(\n load=\"imudp\"\n)\ninput(\n address=\"127.0.0.1\"\n port=\"514\"\n type=\"imudp\"\n)\nmodule(load=\"imtcp\")\ninput(type=\"imtcp\" address=\"127.0.0.1\" port=\"514\")\n";
my $legacy = "\$ModLoad imudp\n\$UDPServerRun 514\n\$ModLoad imtcp\n\$InputTCPServerRun 514\n";
my @cases = (
['native default MN', 'mn', 'openeuler24.03', $default],
['native default SN local', 'snlocal', 'openeuler24.03', $default],
['native default SN forwarding', 'snforward', 'openeuler24.03', $default],
['native default MN', 'mn', 'openeuler24.03', $default, '', '', 1],
['native default SN local', 'snlocal', 'openeuler24.03', $default, '', '', 1],
['native default SN forwarding', 'snforward', 'openeuler24.03', $default, '', '', 1],
['native CN forwarding', 'cn', 'openeuler24.03', $minimal],
['native os-release fallback', 'mn', '', $minimal],
['native nested modern admin', 'mn', 'openeuler24.03', $minimal, $modern],
@@ -114,14 +146,29 @@ my @cases = (
['legacy commented examples', 'mn', 'rhels9.6', $minimal . join('', map { "#$_\n" } split /\n/, $legacy)],
['legacy no examples', 'mn', 'rhels9.6', $minimal],
['native invalid configuration', 'mn', 'openeuler24.03', $minimal . "invalid_rsyslog_directive()\n", '', 'parser'],
['native allocation failure', 'mn', 'openeuler24.03', $minimal, '', 'allocation'],
['native restart failure', 'mn', 'openeuler24.03', $minimal, '', 'restart'],
);
my $number = 0;
for my $case (@cases) {
my ($name, $role, $osver, $config, $admin, $failure) = @$case;
my ($name, $role, $osver, $config, $admin, $failure, $native_defaults) = @$case;
$admin //= ''; $failure //= '';
my $fixture = "$tmp/" . ++$number;
make_path(map { "$fixture/$_" } qw(etc/rsyslog.d etc/admin log run state));
make_path(map { "$fixture/$_" } qw(dev etc/rsyslog.d etc/admin log run lib/rsyslog spool/rsyslog tmp));
write_file("$fixture/dev/$_", '') for qw(null zero random urandom);
for my $file (qw(passwd group nsswitch.conf)) {
next unless -f "/etc/$file";
copy("/etc/$file", "$fixture/etc/$file") or die $!;
}
# Some native configurations drop privileges and keep their rules in a separate file.
if ($native_defaults) {
write_file("$fixture/etc/rsyslog.d/local.conf", "*.info /var/log/messages\n");
write_file("$fixture/log/messages", '');
my ($uid, $gid) = (getpwnam('syslog'))[2, 3];
if (defined $uid) {
chown($uid, $gid, map { "$fixture/$_" } qw(log log/messages lib/rsyslog spool/rsyslog)) == 4 or die $!;
}
}
write_file("$fixture/etc/os-release", 'ID="' . ($osver =~ /^rhels/ ? 'rhel' : 'openEuler') . "\"\n");
write_file("$fixture/etc/xCATMN", '') if $role eq 'mn';
if ($admin ne '') {
@@ -134,17 +181,39 @@ for my $case (@cases) {
write_file("$fixture/etc/rsyslog.conf", $config);
write_file("$fixture/upstream.conf", "module(load=\"imudp\")\ninput(type=\"imudp\" port=\"1514\")\n*.* /var/log/upstream\n");
local %ENV = (%ENV, PATH => "$tmp/bin:$ENV{PATH}", XCAT_SYSLOG_FIXTURE => $fixture,
XCAT_SYSLOG_BIN => "$tmp/bin", XCAT_SYSLOG_FAIL => $failure, XCAT_SYSLOG_ROLE => $role,
XCAT_SYSLOG_BIN => "$tmp/bin", XCAT_SYSLOG_FAIL => $failure, XCAT_SYSLOG_ROLE => $role, TMPDIR => '/tmp',
OSVER => $osver, NTYPE => ($role =~ /^sn/ ? 'service' : 'compute'),
SVLOGLOCAL => ($role eq 'snlocal' ? 1 : 0), MASTER => '127.0.0.1:1514', SYSLOG => '');
is(system('unshare', '-mn', '--', "$tmp/bin/namespace"), 0, "$name: isolated driver completed");
is(system('unshare', '-mnpf', '--mount-proc', '--', "$tmp/bin/namespace"), 0, "$name: isolated driver completed");
my $rc = read_file("$fixture/postscript-1.rc");
chomp $rc;
die "Missing postscript status for $name" unless $rc =~ /^\d+$/;
my $receiver = $role ne 'cn' && $osver !~ /^rhels/;
my @allocated = split /\n/, read_file("$fixture/allocated");
if ($failure eq 'allocation') {
ok(-s "$fixture/allocation-attempts", "$name: allocation fault was reached");
is(scalar @allocated, 0, "$name: failed allocation creates no file");
} elsif ($receiver) {
ok(scalar @allocated > 0, "$name: receiver allocated a temporary configuration");
}
for my $pass ($failure ? (1) : (1, 2)) {
is(-f "$fixture/temporary-$pass" ? read_file("$fixture/temporary-$pass") : 'missing evidence', '',
"$name: no temporary artifact remains after invocation $pass");
}
for my $path (@allocated) {
like($path, qr{^/tmp/[^/]+$}, "$name: allocation stays in the private temporary directory");
}
if ($failure) {
isnt($rc, 0, "$name: failure reaches postscript exit");
is(read_file("$fixture/logger.log"), '', "$name: no success log");
is(read_file("$fixture/services.log"), '', "$name: invalid configuration is not restarted") if $failure eq 'parser';
is(read_file("$fixture/services.log"), '', "$name: failed configuration is not restarted") if $failure ne 'restart';
if ($failure eq 'allocation') {
is($rc, 43, "$name: allocation status reaches the caller");
unlike(read_file("$fixture/rsyslog-calls"), qr/^-N1\b/m, "$name: validation is not attempted");
like(read_file("$fixture/config-1"), qr/^\Q$config\E/, "$name: existing configuration is preserved");
unlike(read_file("$fixture/config-1"), qr/^(?:module|input)\(/m,
"$name: no receiver is added after allocation fails");
}
next;
}
is($rc, 0, "$name: first postscript succeeds");
@@ -16,6 +16,7 @@ my $source = $ENV{XCAT_SYSLOG_SOURCE_ROOT} || abs_path("$FindBin::Bin/../..");
my $tmp = tempdir(DIR => '/var/tmp', CLEANUP => !$ENV{XCAT_SYSLOG_KEEP});
diag("fixtures: $tmp") if $ENV{XCAT_SYSLOG_KEEP};
make_path("$tmp/bin");
symlink(abs_path('/usr/bin/awk'), "$tmp/bin/awk") or die $!;
sub write_file {
my ($path, $text) = @_;
open(my $fh, '>', $path) or die "$path: $!";
@@ -5,7 +5,9 @@ use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
use File::Basename qw(dirname);
use File::Path qw(make_path);
use File::Spec;
use File::Slurper qw(read_text write_text);
use Test::More;
use XCAT::Test::File qw(repo_path);
@@ -13,13 +15,19 @@ use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
use XCAT::Test::Template qw(template_database render_template);
plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux';
die 'Install netcat to provide the /usr/bin/nc sandbox mount point' unless -e '/usr/bin/nc';
# Bubblewrap needs the alternatives target, with /bin kept as a separate mount.
my $nc_mount = '/usr/bin/nc';
while (-l $nc_mount) {
$nc_mount = File::Spec->rel2abs(readlink($nc_mount), dirname($nc_mount));
}
my $database = template_database();
# Subiquity runs its early commands under dash.
my ($shell) = grep { -x $_ } qw(/usr/bin/dash /bin/dash /bin/sh);
my $sequence = 0;
sub render_part {
my ($script, $pattern, @entries) = @_;
sub render_preinstall {
my ($script, @entries) = @_;
my $dir = "$database/case-" . ++$sequence;
make_path($dir);
my @partitionfile;
@@ -30,16 +38,22 @@ sub render_part {
}
render_template($database, repo_path("xCAT-server/share/xcat/install/scripts/$script"), "$dir/node.pre",
'node', '', '', '', join(',', @partitionfile), {xcatmaster => '192.0.2.1'});
my ($part) = read_text("$dir/node.pre") =~ $pattern;
return $part;
return read_text("$dir/node.pre");
}
# getinstdisk has already chosen /dev/sdz.
sub installer_root {
my $root = sandbox_root();
make_path("$root/efi", "$root/by-id");
write_text("$root/bin/logger", "#!/bin/sh\nexit 0\n");
for my $tool (qw(systemctl systemd-run killall syslogd debconf-get mknod)) {
write_text("$root/bin/$tool", "#!/bin/sh\nexit 0\n");
chmod 0755, "$root/bin/$tool" or die $!;
}
write_text("$root/bin/logger", '#!/bin/sh' . "\n" . 'printf "%s\n" "$*" >>/fixture/messages' . "\n");
chmod 0755, "$root/bin/logger" or die $!;
# The monitor waits for a peer until the sandbox exits; it must not contact an xcatd.
write_text("$root/bin/nc", "#!/bin/sh\nexec /bin/sleep 300\n");
chmod 0755, "$root/bin/nc" or die $!;
write_text("$root/tmp/xcat.install_disk", "/dev/sdz\n");
write_text("$root/nvme7n1", '');
symlink('../../nvme7n1', "$root/by-id/nvme-link") or die $!;
@@ -95,23 +109,26 @@ my @cases = (
for my $case (@cases) {
my ($label, $entries, $expected, $expected_layout) = @$case;
subtest $label => sub {
my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries);
ok($part, 'the rendered script defines base64decode before the partitioning') or return;
my $preinstall = render_preinstall('pre.ubuntu.subiquity', @$entries);
my $root = installer_root();
write_text("$root/part.sh", $part);
write_text("$root/preinstall.sh", $preinstall);
my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi',
"$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh');
"$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1',
"$root/bin/nc" => $nc_mount}}, $shell, '/fixture/preinstall.sh');
if (defined $expected_layout) {
is($rc, 0, "the partitioning runs under $shell") or diag($output);
is($rc, 0, "the pre-install script runs under $shell") or diag($output);
is(storage_config($root), $expected_layout, 'the storage config is the expected layout');
return;
}
if (!defined $expected) {
isnt($rc, 0, "the pre-install script fails under $shell");
is($rc, 1, "the pre-install script rejects the entry under $shell") or diag($output);
like(-e "$root/messages" ? read_text("$root/messages") : '',
qr/The partitionfile (?:disk|layout) entry .*stopping the install/,
'the installer reports the invalid partitionfile entry');
ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject');
return;
}
is($rc, 0, "the partitioning runs under $shell") or diag($output);
is($rc, 0, "the pre-install script runs under $shell") or diag($output);
my $config = storage_config($root);
my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m;
is($disk, $expected, "the storage config partitions $expected");
@@ -125,13 +142,13 @@ for my $case (@cases) {
# The debian-installer path renders the same entries into pre.ubuntu, under a shell with read -n.
subtest 'a debian-installer recipe file after a recipe script' => sub {
my $part = render_part('pre.ubuntu', qr/(^base64decode\(\)\n.*?^exit 0$)/ms,
my $preinstall = render_preinstall('pre.ubuntu',
['s:', "#!/bin/sh\nexit 0\n"], ['', "recipe ::\n .\n"]);
ok($part, 'the rendered script defines base64decode before the recipe') or return;
my $root = installer_root();
write_text("$root/part.sh", $part);
my ($rc, $output) = sandbox_run($root, '/bin/bash', '/fixture/part.sh');
is($rc, 0, 'the recipe step runs') or diag($output);
write_text("$root/preinstall.sh", $preinstall);
my ($rc, $output) = sandbox_run($root, {read_only => {"$root/bin/nc" => $nc_mount}},
'/bin/bash', '/fixture/preinstall.sh');
is($rc, 0, 'the debian-installer pre-install script runs') or diag($output);
is(storage_config($root), "recipe ::\n .\n", 'the later recipe file replaces the default recipe');
};
done_testing();
+4 -1
View File
@@ -4,10 +4,12 @@ use warnings;
use FindBin;
use File::Slurper qw(write_text);
use File::Temp qw(tempdir);
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
use Test::More;
use XCAT::Test::Process qw(run_command);
use imgutils;
plan skip_all => 'bash is not installed' unless -x '/bin/bash';
@@ -22,7 +24,8 @@ sub uname {
my $script = tempdir(CLEANUP => 1) . '/uname';
write_text($script, imgutils::uname_script($kernelver));
local $ENV{PATH} = "$bin:$ENV{PATH}";
my $output = `/bin/bash $script @options`;
my ($status, $output) = run_command('/bin/bash', $script, @options);
is($status, 0, 'uname ' . join(' ', @options) . ' exits successfully') or diag($output);
chomp($output);
return $output;
}