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

Merge pull request #8006 from VersatusHPC/fix/el-kickstart-pre-log

fix(install): copy the kickstart pre-install log from the installer
This commit is contained in:
Daniel Hilst
2026-11-07 00:54:01 -03:00
committed by GitHub
14 changed files with 243 additions and 16 deletions
+1 -1
View File
@@ -110,7 +110,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/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 | 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/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"
! grep -qi skipped "$log"
rpm_lifecycle_test:
runs-on: ubuntu-24.04
+4 -2
View File
@@ -456,7 +456,8 @@ sub subvars {
$partcontent .= "rm -rf /tmp/partitionfile\n";
# Put the code to decode the partitionfile
$partcontent .= "base64decode</tmp/partscript.enc >/tmp/partscript\n";
# A traced decode prints the partition data, which can hold a passphrase.
$partcontent .= "(set +x; base64decode</tmp/partscript.enc >/tmp/partscript)\n";
$partcontent .= "chmod 755 /tmp/partscript\n";
$partcontent .= "/tmp/partscript\n";
@@ -517,7 +518,8 @@ sub subvars {
$partcontent .= "rm -rf /tmp/partitionfile\n";
# Put the code to decode the partitionfile
$partcontent .= "base64decode</tmp/partitionfile.enc >/tmp/partitionfile\n";
# A traced decode prints the partition data, which can hold a passphrase.
$partcontent .= "(set +x; base64decode</tmp/partitionfile.enc >/tmp/partitionfile)\n";
#replace the #XCA_PARTITION_SCRIPT#
$inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/;
@@ -48,9 +48,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
@@ -27,9 +27,13 @@ echo "Running Kickstart Pre-installation script..."
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash --erroronfail
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.openeuler#
@@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10#
@@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10#
@@ -47,9 +47,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
@@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
@@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
} &>>/tmp/pre-install.log
%end
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
%post --nochroot --interpreter=/bin/bash
mkdir -p /mnt/sysimage/var/log/xcat/
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
%end
%post --interpreter=/bin/bash
mkdir -p /var/log/xcat/
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
{
echo "Running Kickstart Post-installation script..."
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
@@ -309,7 +309,12 @@ fi
# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log
# so that we can inspect the partition scheme after installation
echo "================ The Partition Scheme ==============="
cat /tmp/partitionfile
# A custom partition file can hold credentials, and this log reaches the node.
if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then
echo "The custom partition file is not logged."
else
cat /tmp/partitionfile
fi
echo "====================================================="
msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label"
# The following code is to generate the repository for the installation
@@ -310,7 +310,12 @@ fi
# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log
# so that we can inspect the partition scheme after installation
echo "================ The Partition Scheme ==============="
cat /tmp/partitionfile
# A custom partition file can hold credentials, and this log reaches the node.
if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then
echo "The custom partition file is not logged."
else
cat /tmp/partitionfile
fi
echo "====================================================="
msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label"
# The following code is to generate the repository for the installation
+10 -4
View File
@@ -173,7 +173,8 @@ for my $rendered (@rendered_profiles) {
my $root = installed_root(1, sandbox_root());
make_path("$root/etc/systemd/system/multi-user.target.wants", "$root/etc/yum.repos.d");
write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n");
write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n");
make_path("$root/installer-tmp");
write_text("$root/installer-tmp/pre-install.log", "pre-install fixture diagnostic\n");
copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!;
write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n");
for my $name (qw(uname findmnt lsblk efibootmgr)) {
@@ -189,9 +190,14 @@ for my $rendered (@rendered_profiles) {
my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/;
$interpreter //= '/bin/sh';
write_text("$root/post.sh", $post->[1]);
my ($rc, $log) = sandbox_run($root, {
env => {XCAT_EFI_LOG => '/fixture/efi.log'},
}, 'timeout', '30', $interpreter, '/fixture/post.sh');
my %options = (env => {XCAT_EFI_LOG => '/fixture/efi.log'});
# anaconda runs a --nochroot block in the installer, which has its own /tmp and the installed system at /mnt/sysimage
if ($post->[0] =~ /(?:^|\s)--nochroot(?:\s|$)/) {
$options{writable} = {map { ("$root/$_->[0]" => $_->[1]) }
['installer-tmp', '/tmp'], ['boot', '/mnt/sysimage/boot'],
['etc', '/mnt/sysimage/etc'], ['log', '/mnt/sysimage/var/log']};
}
my ($rc, $log) = sandbox_run($root, \%options, 'timeout', '30', $interpreter, '/fixture/post.sh');
is($rc, 0, 'post block ' . ++$index . ' completes')
or diag($log, read_text("$root/log/xcat/xcat.log"));
}
@@ -0,0 +1,101 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
use File::Path qw(make_path);
use File::Slurper qw(read_binary write_binary);
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 => 'installer execution requires Linux namespaces' unless $^O eq 'linux';
my $database = template_database();
set_row('site', {key => 'nodestatus'}, {value => 0});
write_binary("$database/image.pkglist", '');
# Credentials in the forms that kickstart's shell-style parser accepts.
my $custom = join("\n",
'part /data --fstype=xfs --size=1024 --encrypted --passphrase=s3cret-one --ondisk=sdb',
'logvol /home --vgname=vg --name=home --size=1 --encrypted --passphrase "s3cret two"',
"raid /srv --level=1 --device=md0 --encrypted --passphrase='s3cret three' raid.01 raid.02",
'part /esc --size=1 --encrypted --passphrase=prefix\\ s3cret\\ four --ondisk=sdb',
'part /quote --size=1 --encrypted --pass"phrase"="s3cret \\"five\\"" --ondisk=sdb',
'bootloader --iscrypted --password=s3cret-six',
'rootpw --plaintext s3cret-seven');
write_binary("$database/partitionfile", "$custom\n");
write_binary("$database/partscript", "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n$custom\nEOF\n");
# Commands that the pre-installation scripts call in the installer.
sub installer_root {
my $root = sandbox_root();
make_path("$root/libexec");
write_binary("$root/partitions", "major minor #blocks name\n\n 8 16 524288000 sdb\n");
write_binary("$root/bin/udevadm", <<'SH');
#!/bin/sh
case "$*" in
'info --attribute-walk --name=sdb') printf ' ATTRS{size}=="1024000000"\n DRIVERS=="ahci"\n' ;;
'info --query=property --name='*) printf 'DEVTYPE=disk\n' ;;
*) exit 97 ;;
esac
SH
write_binary("$root/bin/find", "#!/bin/sh\nprintf '/usr/bin/awk\\n'\n");
write_binary("$root/libexec/platform-python", "#!/bin/sh\nexit 0\n");
write_binary("$root/bin/mknod", "#!/bin/sh\n: >\"\$1\"\n");
for my $name (qw(logger vgs vgchange vgremove chown)) {
write_binary("$root/bin/$name", "#!/bin/sh\nexit 0\n");
}
chmod oct('755'), glob("$root/bin/*"), "$root/libexec/platform-python" or die $!;
return $root;
}
for my $case (['rh/compute.rhels9.tmpl', 'alma9.6'], ['rh/compute.rhels10.tmpl', 'rhels10']) {
my ($template, $os) = @$case;
for my $input (['generated', undef], ['custom file', "$database/partitionfile"],
['custom script', "s:$database/partscript"]) {
my ($kind, $partitionfile) = @$input;
for my $mode (0, 1, 2) {
subtest "$template, $kind, xcatdebugmode $mode" => sub {
set_row('site', {key => 'xcatdebugmode'}, {value => $mode});
set_row('nodetype', {node => 'node'}, {os => $os, arch => 'x86_64', provmethod => 'install'});
render_template($database, repo_path("xCAT-server/share/xcat/install/$template"), "$database/ks",
'node', "$database/image.pkglist", "/install/$os/x86_64", 'rh', $partitionfile,
{xcatmaster => '192.0.2.1'}, osarch => 'x86_64');
my ($pre) = read_binary("$database/ks") =~ /^%pre\b[^\n]*\n(.*?)^%end$/ms;
write_binary("$database/pre.sh", $pre // '');
my $root = installer_root();
my ($rc, $output) = sandbox_run($root, {
read_only => {"$root/partitions" => '/proc/partitions', "$root/libexec" => '/usr/libexec',
"$database/pre.sh" => '/pre.sh'},
env => {MASTER_IP => '192.0.2.1', log_label => 'install'},
}, '/bin/bash', '-c', '. /pre.sh');
is($rc, 0, 'the %pre block completes') or diag($output);
my $log = -f "$root/tmp/pre-install.log" ? read_binary("$root/tmp/pre-install.log") : '';
my ($scheme) = $log =~ /^=+ The Partition Scheme =+\n(.*?)^=+$/ms;
if ($mode) {
like($log, qr/^\++ /m, 'traces the %pre block into the pre-install log');
}
if (!defined $partitionfile) {
like($scheme // '', qr/^volgroup xcatvg /m, 'logs the partition scheme that xCAT generated');
return;
}
like($scheme // '', qr/^The custom partition file is not logged\.$/m,
'logs a notice in place of the custom partition file');
unlike($scheme // '', qr/^(?:part|logvol|raid|bootloader|rootpw) /m,
'logs no line of the custom partition file');
unlike($log . $output, qr/s3cret/, 'leaves no credential in the log or the trace');
# The decoder prints three bytes at a time, so a traced decode spells them out in hex.
my $traced = join('', map { pack('H*', join('', /\\x([0-9A-Fa-f]{2})/g)) }
$log =~ /^\++ printf '([^']*)'$/mg);
unlike($traced, qr/s3cret/, 'traces no decoded byte of the custom input');
like(read_binary("$root/tmp/partitionfile"), qr/\A\Q$custom\E\n?\z/,
'hands anaconda the custom partition definitions');
};
}
}
}
set_row('site', {key => 'xcatdebugmode'}, {value => 0});
done_testing();
@@ -0,0 +1,80 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(make_path);
use File::Slurper qw(read_text write_text);
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
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 => 'kickstart execution requires Linux' unless $^O eq 'linux';
my $database = template_database();
# The kickstart templates whose %pre writes /tmp/pre-install.log, each with an OS that uses it.
my @templates = (
[ 'rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh' ],
[ 'rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh' ],
[ 'rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh' ],
[ 'centos/compute.centos8.tmpl', 'centos8', 'x86_64', 'centos' ],
[ 'openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler' ],
[ 'rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh' ],
[ 'rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky' ],
);
my $diagnostic = "pre-install fixture diagnostic\n";
for my $case (@templates) {
my ($template, $os, $arch, $platform) = @$case;
subtest $template => sub {
set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'});
my $path = repo_path("xCAT-server/share/xcat/install/$template");
(my $pkglist = $path) =~ s/\.tmpl$/.pkglist/;
$pkglist = '' unless -r $pkglist;
my $output = "$database/ks";
render_template($database, $path, $output, 'node', $pkglist, '/install/media', $platform, undef,
{xcatmaster => '192.0.2.1'});
my $ks = read_text($output);
like($ks, qr/^%pre\b.*?pre-install\.log.*?^%end/ms, 'the %pre block writes the pre-install log');
my @posts;
while ($ks =~ /^%post([^\n]*)\n(.*?)^%end/msg) {
push @posts, [$1, $2];
}
my @installer = grep { $posts[$_][0] =~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts;
my ($chroot) = grep { $posts[$_][0] !~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts;
ok(defined $chroot, 'has a %post block that runs in the installed system');
# anaconda keeps the installer's /tmp out of the chroot, so only a --nochroot block can read the log
for my $earlier ('', "earlier entry\n") {
my $label = length($earlier) ? 'an existing log' : 'a new log';
my $root = sandbox_root();
my $xcatlog = "$root/log/xcat/xcat.log";
make_path("$root/installer-tmp");
write_text("$root/installer-tmp/pre-install.log", $diagnostic);
if (length($earlier)) {
make_path("$root/log/xcat");
write_text($xcatlog, $earlier);
chmod(oct('644'), $xcatlog) or die $!;
}
for my $index (@installer) {
my ($interpreter) = $posts[$index][0] =~ /--interpreter=(\S+)/;
write_text("$root/post.sh", $posts[$index][1]);
my ($rc, $log) = sandbox_run($root, {
writable => {"$root/installer-tmp" => '/tmp', "$root/log" => '/mnt/sysimage/var/log'},
}, $interpreter // '/bin/sh', '/fixture/post.sh');
is($rc, 0, "%post --nochroot block $index completes for $label") or diag($log);
}
is(-f $xcatlog ? read_text($xcatlog) : '', $earlier . $diagnostic,
"appends the pre-install log to $label of the installed system");
}
ok(@installer && defined $chroot && $installer[0] < $chroot,
'copies it before the first %post block in the installed system writes that log');
};
}
done_testing();