2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00
Files
xcat-core/xCAT-test/unit/grub2_kernel_command.t
T
Daniel Hilst ddaad73ab4 fix(grub2): a ppc node is given linuxefi when its image carries it
grub2_kernel_commands read the image and not the architecture, so a ppc node
whose grub2 image carries linuxefi was given it. linuxefi loads an EFI binary
and a ppc loader is not one. The previous commit removed the architecture test
along with the defect it carried.

The command now needs both: the architecture whose loader is an EFI binary, and
an image that carries the command.

grub2_netboot_protocol.t covers the three architectures and caught this. Its
loader fixture now records the commands it carries, because the configuration
follows the image.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-29 15:27:53 -03:00

70 lines
3.0 KiB
Perl

#!/usr/bin/env perl
#
# Which commands a grub2 configuration may use to load a kernel.
#
# linuxefi and initrdefi come from a downstream patch. grub2.pm chose them for every x86
# node, from the architecture alone. An image built from upstream grub carries neither, so
# such a node stopped at the grub menu with "can't find command `linuxefi'", asked for no
# kernel over TFTP, and the boot never started. Measured on grub2-xcat 2.12-2 for Ubuntu,
# whose image carries linux and not linuxefi.
use strict;
use warnings;
use File::Spec;
use File::Temp qw(tempdir);
use FindBin;
use Test::More tests => 9;
use lib "$FindBin::Bin/../../perl-xCAT";
use xCAT::BootUtils;
my $dir = tempdir(CLEANUP => 1);
# grub records the name of each command its modules register, so the name appears in the
# image exactly when the command can be run. The names are NUL delimited.
sub write_image {
my ($name, @commands) = @_;
my $path = File::Spec->catfile($dir, $name);
open(my $fh, '>:raw', $path) or die "cannot write $path: $!";
print {$fh} "\x7fELF", "\0" x 32;
print {$fh} "\0$_\0" for @commands;
print {$fh} "\0" x 16;
close($fh);
return $path;
}
my $downstream = write_image('grub2.downstream', qw(linux linuxefi initrd initrdefi));
my $upstream = write_image('grub2.upstream', qw(linux initrd));
is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($downstream, 'x86_64') ],
[ 'linuxefi', 'initrdefi' ],
'an image that carries linuxefi is given linuxefi and initrdefi' );
is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($upstream, 'x86_64') ],
[ 'linux', 'initrd' ],
'an image built from upstream grub is given linux and initrd' );
# A missing or unreadable image must not produce a command the node cannot run. linux is
# carried by every grub2 image, so it is the safe answer.
is_deeply( [ xCAT::BootUtils::grub2_kernel_commands( File::Spec->catfile($dir, 'absent'), 'x86_64' ) ],
[ 'linux', 'initrd' ], 'a missing image is given linux and initrd' );
is_deeply( [ xCAT::BootUtils::grub2_kernel_commands(undef, 'x86_64') ],
[ 'linux', 'initrd' ], 'an undefined image is given linux and initrd' );
ok( xCAT::BootUtils::grub2_image_provides($downstream, 'linuxefi'),
'the downstream image reports linuxefi' );
ok( !xCAT::BootUtils::grub2_image_provides($upstream, 'linuxefi'),
'the upstream image does not report linuxefi' );
ok( xCAT::BootUtils::grub2_image_provides($upstream, 'linux'),
'the upstream image does report linux, so the search is not refusing everything' );
# The name has to be the whole command, or linux would match linuxefi and every image
# would look downstream.
ok( !xCAT::BootUtils::grub2_image_provides( write_image('grub2.efionly', 'linuxefi'), 'linux' ),
'a longer command name does not satisfy a shorter one' );
# linuxefi loads an EFI binary, and a ppc loader is not one. The image is irrelevant there.
is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($downstream, 'ppc64le') ],
[ 'linux', 'initrd' ],
'a ppc node takes linux even from an image that carries linuxefi' );