From 995c89cbdb9cec78aae5f4cecea6046d4f9e04b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:55:25 -0300 Subject: [PATCH] test(install): cover unavailable kdump policy assets --- xCAT-test/native/openeuler_post_kdump.t | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/xCAT-test/native/openeuler_post_kdump.t b/xCAT-test/native/openeuler_post_kdump.t index dc38999215..1c1dd7c584 100644 --- a/xCAT-test/native/openeuler_post_kdump.t +++ b/xCAT-test/native/openeuler_post_kdump.t @@ -14,6 +14,7 @@ use Test::More; use imgutils; use XCAT::Test::File qw(repo_path); +use XCAT::Test::Process qw(run_command); use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); use XCAT::Test::Template qw(template_database set_row render_template); @@ -93,4 +94,52 @@ for my $profile (qw(compute service)) { }; } +my $delivered = "$database/delivered"; +my ($copy_rc, $copy_output) = run_command('cp', '-a', repo_path('xCAT-server'), $delivered); +die "copy delivered templates: $copy_output" if $copy_rc; +my $asset = "$delivered/share/xcat/netboot/imgutils/xcat-dump-memory.conf"; +my $asset_bytes = read_text($asset); +for my $case (qw(missing unreadable trailing_newlines)) { + subtest "delivered kdump policy: $case" => sub { + local $ENV{XCATROOT} = $delivered; + if ($case eq 'missing') { + unlink($asset) or die $!; + } elsif ($case eq 'unreadable') { + chmod oct('0000'), $asset or die $!; + } else { + write_text($asset, $asset_bytes . "\n\n"); + } + render_template($database, repo_path('xCAT-server/share/xcat/install/openeuler/compute.openeuler.tmpl'), + "$database/policy.ks", 'node', '', '/install/media', 'openeuler', undef, {xcatmaster => '192.0.2.1'}); + my $root = post_root('kdump.service' => "[Service]\n"); + make_path("$root/etc/systemd/system/kdump.service.d"); + write_text("$root/$dropin", "previous policy\n"); + chmod oct('0640'), "$root/$dropin" or die $!; + my $rendered = read_text("$database/policy.ks"); + my $chroot_posts = 0; + while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) { + my ($options, $body) = ($1, $2); + my ($interpreter) = $options =~ /--interpreter=(\S+)/; + write_text("$root/post.sh", $body); + my ($rc, $output) = sandbox_run($root, {read_only => {"$root/units" => '/usr/lib/systemd/system'}}, + 'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh'); + if ($options =~ /--nochroot/ || $case eq 'trailing_newlines') { + is($rc, 0, 'the valid installer stage completes') or diag($output); + } else { + ++$chroot_posts; + like($options, qr/--erroronfail/, 'anaconda treats the failed stage as fatal'); + isnt($rc, 0, 'the unavailable policy fails the chroot stage'); + like($output . read_text("$root/log/xcat/xcat.log"), qr/INCLUDEBAD:cannot open .*xcat-dump-memory\.conf/, + 'reports the missing policy include'); + } + } + ok($chroot_posts, 'exercised a failing chroot stage') unless $case eq 'trailing_newlines'; + is(read_text("$root/$dropin"), $case eq 'trailing_newlines' ? $asset_bytes . "\n\n" : "previous policy\n", + 'valid policy bytes are exact; an unavailable policy leaves the old drop-in intact'); + is((stat("$root/$dropin"))[2] & oct('0777'), oct('0640'), 'retains the drop-in permissions'); + chmod oct('0644'), $asset or die $! if -e $asset; + write_text($asset, $asset_bytes); + }; +} + done_testing();