From d5b986b104df8da043645c59858a829f1ad65145 Mon Sep 17 00:00:00 2001 From: ulrich1919 Date: Wed, 28 Aug 2024 13:55:20 +0200 Subject: [PATCH] Fixes #1704: ncm-grub::pxeboot return SUCCESS on non-UEFI systems --- ncm-grub/src/main/perl/grub.pm | 6 ++++++ ncm-grub/src/test/perl/methods.t | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ncm-grub/src/main/perl/grub.pm b/ncm-grub/src/main/perl/grub.pm index 3c24ba42aa..8fcba8ae73 100755 --- a/ncm-grub/src/main/perl/grub.pm +++ b/ncm-grub/src/main/perl/grub.pm @@ -21,6 +21,7 @@ Readonly my $GRUB2_USER_CFG => "$GRUB2_DIR/user.cfg"; Readonly my $GRUBBY => '/sbin/grubby'; Readonly my $PREFIX => '/boot'; Readonly my $EFIBOOTMGR => '/sbin/efibootmgr'; +Readonly my $SYS_FIRMWARE_EFI => '/sys/firmware/efi'; Readonly::Hash my %SERIAL_CONSOLE_DEFAULTS => { unit => 0, speed => 9600, @@ -894,6 +895,11 @@ sub pxeboot return SUCCESS; } + if (!$self->directory_exists($SYS_FIRMWARE_EFI)) { + $self->info("pxeboot: no $SYS_FIRMWARE_EFI found. Not doing anything"); + return SUCCESS; + } + my $efi = CAF::Process->new([$EFIBOOTMGR, '-v'], log => $self, keeps_state => 1)->output(); if (!$efi) { $self->error("No output from $EFIBOOTMGR"); diff --git a/ncm-grub/src/test/perl/methods.t b/ncm-grub/src/test/perl/methods.t index e09aa1e584..8d0b614879 100644 --- a/ncm-grub/src/test/perl/methods.t +++ b/ncm-grub/src/test/perl/methods.t @@ -405,21 +405,26 @@ ok(command_history_ok([ =cut my $ebm = '/sbin/efibootmgr'; +my $sfe = '/sys/firmware/efi'; command_history_reset(); ok (!$cmp->file_exists($ebm), "efibootmgr does not exist"); ok($cmp->pxeboot(), "pxeboot returns success when efibootmgr is missing"); ok(command_history_ok(undef, ['']), "No commands were run when efibootmgr is missing"); +ok (!$cmp->directory_exists($sfe), "/sys/firmware/efi does not exist"); +ok($cmp->pxeboot(), "pxeboot returns success when /sys/firmware/efi is missing"); +ok(command_history_ok(undef, ['']), "No commands were run when /sys/firmware/efi is missing"); +$mock->mock('directory_exists', 1); set_file_contents($ebm, ''); set_desired_output("$ebm -v", "$EFIBOOTMGROUT"); ok ($cmp->file_exists($ebm), "efibootmgr does exist"); ok($cmp->pxeboot(), "pxeboot returns success"); +$mock->unmock('directory_exists'); ok(command_history_ok([ "$ebm -v", "$ebm -o 4,3,2", ]), "efibootmgr called, correct bootorder set"); - =head1 sanitize_arguments =cut