From d198efde019c8898c616b6a79b98d85f6465366d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:33:41 -0300 Subject: [PATCH 1/5] test(install): run riscv64 %post --nochroot blocks outside the chroot The riscv64 profile test runs every rendered %post block as if it ran in the installed system. Anaconda runs a --nochroot block in the installer, with the installed system at /mnt/sysimage, so give such a block that view. --- xCAT-test/native/install_profile_riscv64.t | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index 2fe46f52ca..3703c9c460 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -189,9 +189,13 @@ 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, with the installed system at /mnt/sysimage + if ($post->[0] =~ /(?:^|\s)--nochroot(?:\s|$)/) { + $options{writable} = {map { ("$root/$_->[0]" => "/mnt/sysimage/$_->[1]") } + ['boot', 'boot'], ['etc', 'etc'], ['log', '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")); } From 944ac3f6e994e3446c51db92f084747a25b91b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:10:50 -0300 Subject: [PATCH 2/5] fix(install): keep custom partition files out of the install log pre.rhels8 and pre.rhels10 print /tmp/partitionfile into the pre-install log, so that the partition scheme can be inspected after the installation. A custom partitionfile can hold credentials, such as the --passphrase of an encrypted partition or a boot loader --password, and the log then holds them in clear text. With site.xcatdebugmode 1 or 2, %pre also traces the decoding of a custom partitionfile or partition script, and the trace spells out every decoded byte. The pre-install log now shows the partition scheme only when xCAT generated it, and says that a custom partition file is not logged. The decoding of a custom partitionfile or partition script runs untraced. /tmp/partitionfile, which anaconda reads, is unchanged. --- xCAT-server/lib/perl/xCAT/Template.pm | 6 ++++-- xCAT-server/share/xcat/install/scripts/pre.rhels10 | 7 ++++++- xCAT-server/share/xcat/install/scripts/pre.rhels8 | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index e681dee5ae..9fce2796ba 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -456,7 +456,8 @@ sub subvars { $partcontent .= "rm -rf /tmp/partitionfile\n"; # Put the code to decode the partitionfile - $partcontent .= "base64decode/tmp/partscript\n"; + # A traced decode prints the partition data, which can hold a passphrase. + $partcontent .= "(set +x; base64decode/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\n"; + # A traced decode prints the partition data, which can hold a passphrase. + $partcontent .= "(set +x; base64decode/tmp/partitionfile)\n"; #replace the #XCA_PARTITION_SCRIPT# $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels10 b/xCAT-server/share/xcat/install/scripts/pre.rhels10 index 80d6d40741..affecf081f 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.rhels10 +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels10 @@ -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 diff --git a/xCAT-server/share/xcat/install/scripts/pre.rhels8 b/xCAT-server/share/xcat/install/scripts/pre.rhels8 index b9900825b7..978fd1e7fe 100644 --- a/xCAT-server/share/xcat/install/scripts/pre.rhels8 +++ b/xCAT-server/share/xcat/install/scripts/pre.rhels8 @@ -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 From e1d9900b3eca278471a3c87365fe7c0e479434a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:10:51 -0300 Subject: [PATCH 3/5] test(install): keep custom partition files out of the install log Render the rhels9 and rhels10 kickstarts with no partitionfile, a custom partitionfile and a custom partition script, each with xcatdebugmode 0, 1 and 2, and run %pre in a sandbox. The custom input holds credentials in the =, separated, quoted, escaped and split option forms, a boot loader password and a root password. The pre-install log must show the generated partition scheme, or a notice for custom input, with neither a credential nor a traced decoded byte of the custom input, and anaconda must still get the custom partition definitions. Run the new test in the profile artifact job. --- .github/workflows/xcat_test.yml | 2 +- .../native/kickstart_partition_scheme_log.t | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 xCAT-test/native/kickstart_partition_scheme_log.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 6034769ca7..4b7a611cb1 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -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 | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/kickstart_partition_scheme_log.t b/xCAT-test/native/kickstart_partition_scheme_log.t new file mode 100644 index 0000000000..e04af4b6f6 --- /dev/null +++ b/xCAT-test/native/kickstart_partition_scheme_log.t @@ -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(); From b45dc1e85fe633bb462078ea5ab0b5179ff564dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:33:48 -0300 Subject: [PATCH 4/5] fix(install): copy the kickstart pre-install log from the installer The EL8 and later kickstart templates append /tmp/pre-install.log to /var/log/xcat/xcat.log in the chroot %post. Anaconda runs that block in the installed system, whose /tmp does not hold the installer's log, so the %pre output, such as the install disk and the partition layout, never reaches the node's xcat.log. Copy the log in a %post --nochroot block before the main %post, from the installer's /tmp to the installed system at /mnt/sysimage. The EL6 and EL7 templates use %include for this and are unchanged. --- xCAT-server/share/xcat/install/centos/compute.centos8.tmpl | 6 +++++- .../share/xcat/install/openeuler/compute.openeuler.tmpl | 6 +++++- .../share/xcat/install/rh/compute.rhels10.riscv64.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl | 6 +++++- xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl | 6 +++++- .../share/xcat/install/rocky/service.rocky10.riscv64.tmpl | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl b/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl index 3719fd0c6f..47883b685c 100644 --- a/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl +++ b/xCAT-server/share/xcat/install/centos/compute.centos8.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl index a022871a5f..81693da645 100644 --- a/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl +++ b/xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl index 63e697b6bb..6ad5f24316 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.riscv64.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl index 3c90ba493d..8e5596971b 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl index 64daf4a34f..e758bc7489 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels8.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl index 6cb3a98883..bffe965899 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels9.tmpl @@ -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# diff --git a/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl b/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl index bc1cc270bd..2866a3b1d3 100644 --- a/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl +++ b/xCAT-server/share/xcat/install/rocky/service.rocky10.riscv64.tmpl @@ -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# From 568db909722f264950217e5cba22b0ce5719cb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:02:07 -0300 Subject: [PATCH 5/5] test(install): cover the kickstart pre-install log handoff Run the rendered %post --nochroot blocks of each kickstart template whose %pre writes /tmp/pre-install.log the way anaconda runs them: in the installer, with its own /tmp and the installed system at /mnt/sysimage. Each run must append the log to a new or an existing xcat.log. The riscv64 profile test now keeps the installer's /tmp out of the installed root too. Both fail on the old templates, whose chroot %post reads a /tmp that does not hold the log. Run the new test in the profile artifact job. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/install_profile_riscv64.t | 10 ++- xCAT-test/native/kickstart_pre_install_log.t | 80 ++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 xCAT-test/native/kickstart_pre_install_log.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index 4b7a611cb1..11b71e4635 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -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 xCAT-test/native/kickstart_partition_scheme_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/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 diff --git a/xCAT-test/native/install_profile_riscv64.t b/xCAT-test/native/install_profile_riscv64.t index 3703c9c460..4eb540dc79 100644 --- a/xCAT-test/native/install_profile_riscv64.t +++ b/xCAT-test/native/install_profile_riscv64.t @@ -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)) { @@ -190,10 +191,11 @@ for my $rendered (@rendered_profiles) { $interpreter //= '/bin/sh'; write_text("$root/post.sh", $post->[1]); my %options = (env => {XCAT_EFI_LOG => '/fixture/efi.log'}); - # anaconda runs a --nochroot block in the installer, with the installed system at /mnt/sysimage + # 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]" => "/mnt/sysimage/$_->[1]") } - ['boot', 'boot'], ['etc', 'etc'], ['log', 'var/log']}; + $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') diff --git a/xCAT-test/native/kickstart_pre_install_log.t b/xCAT-test/native/kickstart_pre_install_log.t new file mode 100644 index 0000000000..a1440aac80 --- /dev/null +++ b/xCAT-test/native/kickstart_pre_install_log.t @@ -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();