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

test(install): sandbox intact openEuler partition scripts

This commit is contained in:
Vinícius Ferrão
2026-11-19 02:05:15 -03:00
parent 4111e4eef3
commit 8bd74c086e
3 changed files with 51 additions and 64 deletions
+1 -1
View File
@@ -123,7 +123,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
+8 -1
View File
@@ -455,7 +455,8 @@ 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,
@@ -467,6 +468,12 @@ 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. 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,31 @@
#!/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) = @_;
my $root = sandbox_root();
make_path("$root/proc", "$root/firmware", "$root/libexec", "$root/log/xcat");
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\n252 0 " . ($sectors / 2) . " vda\n");
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 +35,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;
@@ -74,50 +65,39 @@ my @cases = (
['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'],
);
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 $fixture = installer_root($efi, $sectors);
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');
is($rc, 0, "$label executes the complete generated pre-install script") or diag($output);
my $layout = read_file("$fixture/tmp/partitionfile");
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 +106,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");