Skip to content

Commit 35e38fc

Browse files
authored
Merge pull request #1819 from stdweird/grub_defkernel
ncm-grub: add for_next boolean to set default kernel outside ncm-grub
2 parents f94ee7c + 5e07575 commit 35e38fc

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

ncm-grub/src/main/pan/components/grub/schema.pan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ type grub_component = {
9696
@{pxeboot first: set the PXE boot device as first device. Only
9797
for supported platforms (e.g. UEFI)}
9898
'pxeboot' ? boolean
99+
@{Set arguments of default kernel also for next kernel(s) (to be picked up outside ncm-grub)}
100+
'for_next' ? boolean
99101
} with {
100102
if (exists(SELF['args']) && exists(SELF['arguments'])) {
101103
error("Only one of args or arguments can be set for the default kernel boot arguments");

ncm-grub/src/main/perl/grub.pm

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use CAF::FileWriter;
77
use CAF::Process;
88
use EDG::WP4::CCM::Path qw(unescape);
99

10+
use File::Temp qw(tempdir);
1011
use Readonly;
1112
use parent qw(NCM::Component CAF::Path);
1213
our $EC = LC::Exception::Context->new->will_store_all;
@@ -803,6 +804,8 @@ sub default_options
803804

804805
my ($current, $currargs) = $self->get_current_arguments($default);
805806

807+
my @default_options;
808+
806809
# If we want full control of the arguments:
807810
if ($fullcontrol) {
808811
# Check if the arguments we want to add are the same we have
@@ -846,12 +849,12 @@ sub default_options
846849
$arguments->{remove} = {};
847850
};
848851

849-
my @options = $self->grubby_arguments_options($arguments);
850-
if (@options) {
851-
if ($self->grubby(['--update-kernel', $default, @options], success => 1)) {
852-
$self->info("fullcontrol set args with '@options' for default kernel $default");
852+
@default_options = $self->grubby_arguments_options($arguments);
853+
if (@default_options) {
854+
if ($self->grubby(['--update-kernel', $default, @default_options], success => 1)) {
855+
$self->info("fullcontrol set args with '@default_options' for default kernel $default");
853856
} else {
854-
$self->error("fullcontrol cannot set args with '@options' for default kernel $default");
857+
$self->error("fullcontrol cannot set args with '@default_options' for default kernel $default");
855858
return;
856859
}
857860
} else {
@@ -860,19 +863,33 @@ sub default_options
860863
}
861864
} else {
862865
# If we want no full control of the arguments
863-
my @options = $self->grubby_arguments_options($arguments);
864-
if (@options) {
865-
if ($self->grubby(['--update-kernel', $default, @options], success => 1)) {
866-
$self->info("set args with '@options' for default kernel $default");
866+
@default_options = $self->grubby_arguments_options($arguments);
867+
if (@default_options) {
868+
if ($self->grubby(['--update-kernel', $default, @default_options], success => 1)) {
869+
$self->info("set args with '@default_options' for default kernel $default");
867870
} else {
868-
$self->error("cannot set args with '@options' for default kernel $default");
871+
$self->error("cannot set args with '@default_options' for default kernel $default");
869872
return;
870873
}
871874
} else {
872875
$self->verbose("No kernel arguments set");
873876
}
874877
}
875878

879+
if ($tree->{for_next}) {
880+
# Set default options for "next" kernel that will be installed with e.g. new rpm.
881+
# This involves updating /etc/default/grub and /etc/kernel/cmdline
882+
# As there is no direct way in grubby to only update these files,
883+
# we use hack to pass ALL kernels and point to empty bootloader dir
884+
my $bls_tmpdir = tempdir("ncm-grub-bls-XXXXXX", TMPDIR => 1, CLEANUP => 1);
885+
if ($self->grubby(['--bls-directory', $bls_tmpdir, '--update-kernel', 'ALL', @default_options], success => 1)) {
886+
$self->info("set args with '@default_options' for next kernel");
887+
} else {
888+
$self->error("cannot set args with '@default_options' for next kernel");
889+
return;
890+
}
891+
}
892+
876893
return SUCCESS;
877894
}
878895

ncm-grub/src/test/perl/methods.t

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,24 +381,38 @@ ok($cmp->default_options({arguments => {
381381
b => {enable => 0},
382382
escape("c_aa") => {enable => 1, value => 'xyz'},
383383
escape("d.e.f") => {enable => 0, value => 'ghi'},
384-
}}, '/boot/vmlinuz-1.2.3.4'), "default_options returns success on non-fullcontrol");
384+
}, for_next => 1}, '/boot/vmlinuz-1.2.3.4'), "default_options returns success on non-fullcontrol");
385385
ok(command_history_ok([
386386
'/sbin/grubby --info /boot/vmlinuz-1.2.3.4',
387387
'/sbin/grubby --update-kernel /boot/vmlinuz-1.2.3.4 --args a c_aa=xyz --remove-args b d.e.f=ghi',
388+
'/sbin/grubby --bls-directory /.*?/ncm-grub-bls-\w{6} --update-kernel ALL --args a c_aa=xyz --remove-args b d.e.f=ghi',
388389
]), 'grubby commands from default options non-fullcontrol from arguments');
389390

390391
command_history_reset();
391392
# fullcontrol, existing options will not match;
392393
# but there are current args to remove first
393394
# settings args with a - with fullcontrol is pointless; all current args are removed first
394395
set_desired_output('/sbin/grubby --info /boot/vmlinuz-1.2.3.4', "blablah\nargs=\"something special\"\nkernel=/boot/vmlinuz-1.2.3.4\n");
395-
ok($cmp->default_options({fullcontrol => 1, args => 'a -b c'}, '/boot/vmlinuz-1.2.3.4'), "default_options returns success on fullcontrol");
396+
ok($cmp->default_options({fullcontrol => 1, args => 'a -b c', for_next => 1}, '/boot/vmlinuz-1.2.3.4'), "default_options returns success on fullcontrol");
396397
ok(command_history_ok([
397398
'/sbin/grubby --info /boot/vmlinuz-1.2.3.4',
398399
'/sbin/grubby --update-kernel /boot/vmlinuz-1.2.3.4 --remove-args something special',
399400
'/sbin/grubby --update-kernel /boot/vmlinuz-1.2.3.4 --args a c', # no remove opts, they make no sense
401+
'/sbin/grubby --bls-directory /.*?/ncm-grub-bls-\w{6} --update-kernel ALL --args a c',
400402
]), 'grubby commands from default options fullcontrol');
401403

404+
command_history_reset();
405+
# fullcontrol, existing options will not match; no for_next
406+
# but there are current args to remove first
407+
# settings args with a - with fullcontrol is pointless; all current args are removed first
408+
set_desired_output('/sbin/grubby --info /boot/vmlinuz-1.2.3.4', "blablah\nargs=\"something special\"\nkernel=/boot/vmlinuz-1.2.3.4\n");
409+
ok($cmp->default_options({fullcontrol => 1, args => 'a -b c'}, '/boot/vmlinuz-1.2.3.4'), "default_options returns success on fullcontrol without for_next");
410+
ok(command_history_ok([
411+
'/sbin/grubby --info /boot/vmlinuz-1.2.3.4',
412+
'/sbin/grubby --update-kernel /boot/vmlinuz-1.2.3.4 --remove-args something special',
413+
'/sbin/grubby --update-kernel /boot/vmlinuz-1.2.3.4 --args a c', # no remove opts, they make no sense
414+
], ['bls-directtory']), 'grubby commands from default options fullcontrol without for_next');
415+
402416

403417
=head1 pxeboot
404418

0 commit comments

Comments
 (0)