From 200302ca03f669d52da52d3ad467f94b7b372ec6 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, 25 Aug 2026 00:14:52 -0300 Subject: [PATCH] test(genesis): cover stale initramfs selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- xCAT-test/unit/mknb_exported_genesis.t | 4 ++ xCAT-test/unit/sles_genesis_boot_files.t | 63 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 xCAT-test/unit/sles_genesis_boot_files.t diff --git a/xCAT-test/unit/mknb_exported_genesis.t b/xCAT-test/unit/mknb_exported_genesis.t index 46f32e40e..4d8256751 100644 --- a/xCAT-test/unit/mknb_exported_genesis.t +++ b/xCAT-test/unit/mknb_exported_genesis.t @@ -106,6 +106,8 @@ my $tmpdir = tempdir(CLEANUP => 1); my $export = "$tmpdir/export"; my $tftpdir = "$tmpdir/tftpboot"; prepare_export($export, 'new kernel', 'new initramfs'); +make_path("$tftpdir/xcat"); +write_file("$tftpdir/xcat/genesis.fs.x86_64.lzma", 'old initramfs'); ok( xCAT_plugin::mknb::_prebuilt_genesis_requested($export), @@ -124,6 +126,8 @@ my ($published_kernel, $published_initramfs) = published_files($tftpdir, 'x86_64'); is(read_file($published_kernel), 'new kernel', 'the kernel is published'); is(read_file($published_initramfs), 'new initramfs', 'the initramfs is published'); +ok(!-e "$tftpdir/xcat/genesis.fs.x86_64.lzma", + 'installing an export removes the obsolete legacy initramfs'); is( read_file("$tftpdir/xcat/genesis.exact-arch.x86_64"), export_manifest('x86_64'), diff --git a/xCAT-test/unit/sles_genesis_boot_files.t b/xCAT-test/unit/sles_genesis_boot_files.t new file mode 100644 index 000000000..cc062689e --- /dev/null +++ b/xCAT-test/unit/sles_genesis_boot_files.t @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use FindBin; +use Test::More; + +BEGIN { + $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server"; +} + +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use lib "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins"; + +require sles; + +sub write_file { + my ($path) = @_; + open(my $fh, '>', $path) or die "open $path: $!"; + print {$fh} "test\n"; + close($fh) or die "close $path: $!"; +} + +my $tftp = tempdir(CLEANUP => 1); +make_path("$tftp/xcat"); + +my $kernel = "$tftp/xcat/genesis.kernel.x86_64"; +my $lzma = "$tftp/xcat/genesis.fs.x86_64.lzma"; +my $gzip = "$tftp/xcat/genesis.fs.x86_64.gz"; +write_file($_) for ($kernel, $lzma); +select(undef, undef, undef, 1.1); +write_file($gzip); + +my ($selected_kernel, $selected_initrd) = + xCAT_plugin::sles::_find_genesis_boot_files($tftp, 'x86_64'); +is($selected_kernel, 'genesis.kernel.x86_64', + 'SLES selects the matching Genesis kernel'); +is($selected_initrd, 'genesis.fs.x86_64.gz', + 'SLES selects the newer gzip initramfs'); + +select(undef, undef, undef, 1.1); +write_file($lzma); +($selected_kernel, $selected_initrd) = + xCAT_plugin::sles::_find_genesis_boot_files($tftp, 'x86_64'); +is($selected_initrd, 'genesis.fs.x86_64.lzma', + 'SLES keeps a newer legacy initramfs usable'); + +unlink($gzip); +($selected_kernel, $selected_initrd) = + xCAT_plugin::sles::_find_genesis_boot_files($tftp, 'x86_64'); +is($selected_initrd, 'genesis.fs.x86_64.lzma', + 'SLES accepts the legacy initramfs by itself'); + +unlink($lzma); +($selected_kernel, $selected_initrd) = + xCAT_plugin::sles::_find_genesis_boot_files($tftp, 'x86_64'); +is($selected_kernel, undef, 'a missing initramfs yields no partial boot selection'); +is($selected_initrd, undef, 'a missing initramfs leaves both paths undefined'); + +done_testing();