2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-30 14:22:23 +00:00

test(netboot): start kdump on stateless nodes only with dump memory

An image with kdump.service must get the dump-memory drop-in, once, next
to any site drop-in, and an image without it must get none. systemd itself
must start kdump.service with crashkernel= or fadump= on the command line,
and skip it with neither.
This commit is contained in:
Vinícius Ferrão
2026-11-02 19:26:32 -03:00
parent 48c4f81b82
commit 7a57007465
3 changed files with 95 additions and 1 deletions
+1 -1
View File
@@ -104,7 +104,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/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.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/kdump_condition_systemd.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log"
! grep -qi skipped "$log"
rpm_lifecycle_test:
runs-on: ubuntu-24.04
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Slurper qw(read_text write_text);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
use Test::More;
use XCAT::Test::Process qw(run_command);
use imgutils;
plan skip_all => 'systemd condition evaluation requires Linux' unless $^O eq 'linux';
my ($analyze) = grep { -x $_ } qw(/usr/bin/systemd-analyze /bin/systemd-analyze);
BAIL_OUT('Install systemd to run this test') unless $analyze;
# systemd evaluates the drop-in's own conditions; SYSTEMD_PROC_CMDLINE stands in
# for the kernel command line of the node.
my $root = tempdir(CLEANUP => 1);
make_path("$root/usr/lib/systemd/system");
write_text("$root/usr/lib/systemd/system/kdump.service", "[Service]\n");
imgutils::skip_kdump_without_dump_memory($root);
my @conditions = grep { /^Condition/ }
split /\n/, read_text("$root/etc/systemd/system/kdump.service.d/xcat-dump-memory.conf");
ok(@conditions, 'the drop-in carries conditions');
for my $case (
['crashkernel=256M quiet', 1, 'a crashkernel= reservation'],
['fadump=on fadump_reserve_mem=1G dump=nfs://192.0.2.1/dumps', 1, 'a POWER firmware-assisted dump'],
['quiet console=ttyS0,115200', 0, 'no dump memory'],
) {
my ($cmdline, $start, $label) = @$case;
local $ENV{SYSTEMD_PROC_CMDLINE} = $cmdline;
my ($status, $output) = run_command($analyze, 'condition', @conditions);
is($status == 0 ? 1 : 0, $start, ($start ? 'kdump.service starts with ' : 'kdump.service does not start with ') . $label)
or diag($output);
}
done_testing();
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Path qw(make_path);
use File::Slurper qw(read_text write_text);
use File::Temp qw(tempdir);
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
use Test::More;
use imgutils;
my $dropin = 'etc/systemd/system/kdump.service.d/xcat-dump-memory.conf';
my $condition = "[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n";
sub image_root {
my (%units) = @_;
my $root = tempdir(CLEANUP => 1);
for my $unit (keys %units) {
make_path("$root/usr/lib/systemd/system");
write_text("$root/usr/lib/systemd/system/$unit", $units{$unit});
}
return $root;
}
{
my $root = image_root('kdump.service' => "[Service]\nExecStart=/usr/bin/kdumpctl start\n",
'NetworkManager.service' => "[Service]\n");
make_path("$root/etc/systemd/system/kdump.service.d");
write_text("$root/etc/systemd/system/kdump.service.d/site.conf", "[Service]\nTimeoutSec=600\n");
for my $pass (1, 2) {
imgutils::skip_kdump_without_dump_memory($root);
is(read_text("$root/$dropin"), $condition,
"pass $pass: kdump.service runs only with crashkernel= or fadump=");
}
opendir(my $dh, "$root/etc/systemd/system/kdump.service.d") or die "opendir: $!";
is_deeply([sort grep { !/^\./ } readdir($dh)], ['site.conf', 'xcat-dump-memory.conf'],
'the drop-in is written once next to the site drop-ins');
closedir($dh);
is(read_text("$root/etc/systemd/system/kdump.service.d/site.conf"), "[Service]\nTimeoutSec=600\n",
'a site drop-in is unchanged');
ok(!-e "$root/etc/systemd/system/NetworkManager.service.d", 'other units get no drop-in');
}
{
my $root = image_root('NetworkManager.service' => "[Service]\n");
imgutils::skip_kdump_without_dump_memory($root);
ok(!-e "$root/etc/systemd/system/kdump.service.d", 'an image without kdump.service is unchanged');
}
done_testing();