From 7a570074654564a34993930ff35ecabfeda3f6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 2 Nov 2026 19:26:32 -0300 Subject: [PATCH] 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. --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/native/kdump_condition_systemd.t | 42 +++++++++++++++++ xCAT-test/unit/imgutils_kdump_condition.t | 52 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 xCAT-test/native/kdump_condition_systemd.t create mode 100644 xCAT-test/unit/imgutils_kdump_condition.t diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index fa31e51ee5..3fbad86536 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -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 diff --git a/xCAT-test/native/kdump_condition_systemd.t b/xCAT-test/native/kdump_condition_systemd.t new file mode 100755 index 0000000000..dba670b81f --- /dev/null +++ b/xCAT-test/native/kdump_condition_systemd.t @@ -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(); diff --git a/xCAT-test/unit/imgutils_kdump_condition.t b/xCAT-test/unit/imgutils_kdump_condition.t new file mode 100644 index 0000000000..d3d16bb45c --- /dev/null +++ b/xCAT-test/unit/imgutils_kdump_condition.t @@ -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();