2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

test(netboot): cover copied profile helper layouts

This commit is contained in:
Vinícius Ferrão
2026-10-26 18:05:41 -03:00
parent 447db00a81
commit c35fabe185
2 changed files with 58 additions and 1 deletions
+22 -1
View File
@@ -48,6 +48,21 @@ my ($status, $output) = run_command($^X,
repo_path('xCAT-test/unit/profile_customization.t'), "$root/opt/xcat");
is($status, 0, 'packaged profiles resolve and remain independently customizable') or diag($output);
my $netboot = "$root/opt/xcat/share/xcat/netboot";
for my $directory (qw(debian imgutils)) {
my $helper = "$netboot/$directory/xCAT/ProfileUtils.pm";
ok(-f $helper && !-l $helper, "$directory ships a regular profile helper") or next;
is(sprintf('%04o', S_IMODE((stat($helper))[2])), '0644', "$directory helper is readable without write access for others");
}
for my $case (
['unit/imgutils_standalone.t', 'imgutils'],
['native/debian_genimage_profile_assets.t', 'debian'],
) {
my ($test, $directory) = @$case;
my ($rc, $result) = run_command($^X, repo_path("xCAT-test/$test"), "$netboot/$directory");
is($rc, 0, "packaged $directory works when copied without sibling directories") or diag($result);
}
if (!-f '/etc/debian_version') {
local $ENV{fsm} = 1;
my $reduced = tempdir(CLEANUP => 1);
@@ -65,7 +80,7 @@ if (!-f '/etc/debian_version') {
my $data = 'install/rh/compute.rhels10.riscv64.pkglist';
my $postinstall = 'netboot/rocky/compute.rocky10.riscv64.postinstall';
chmod(oct('0666'), "$profiles/$data") == 1 or die "chmod: $!";
for my $mask ('0022', '0002') {
for my $mask ('0022', '0002', '0077') {
subtest "Debian writable sources with umask $mask" => sub {
my $previous = umask oct($mask);
my $deb = XCAT::Test::Lifecycle::build_deb('xCAT-server', $fixture);
@@ -80,6 +95,12 @@ if (!-f '/etc/debian_version') {
my $payload = tempdir(CLEANUP => 1);
XCAT::Test::Lifecycle::checked('dpkg-deb', '-x', $deb, $payload);
check_assets($payload, '', @assets);
for my $directory (qw(debian imgutils)) {
my $helper = "$payload/opt/xcat/share/xcat/netboot/$directory/xCAT/ProfileUtils.pm";
ok(-f $helper && !-l $helper, "$directory ships a regular helper with umask $mask");
is(sprintf('%04o', S_IMODE((stat($helper))[2])), '0644',
"$directory helper retains readable permissions with umask $mask");
}
for my $path (qw(install install/rh netboot netboot/rocky netboot/ubuntu/genimage)) {
is(sprintf('%04o', S_IMODE((stat("$payload/opt/xcat/share/xcat/$path"))[2])),
'0755', "$path remains executable without group or other write access");
+36
View File
@@ -0,0 +1,36 @@
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Cwd qw(realpath);
use File::Path qw(make_path);
use File::Slurper qw(write_text);
use File::Temp qw(tempdir);
use Test::More;
use XCAT::Test::File qw(repo_path);
use XCAT::Test::Process qw(run_command);
my $source = shift @ARGV // repo_path('xCAT-server/share/xcat/netboot/imgutils');
my $root = tempdir(CLEANUP => 1);
my ($status, $output) = run_command('cp', '-R', $source, "$root/imgutils");
die "copy imgutils: $output" if $status;
make_path("$root/assets");
my $assets = realpath("$root/assets");
local $ENV{PERL5LIB} = '';
local $ENV{XCATROOT} = '/nonexistent';
for my $extension (qw(pkglist otherpkgs.pkglist postinstall)) {
my $selected = "$assets/compute.debian12.x86_64.$extension";
write_text($selected, "selected\n");
write_text("$root/assets/compute.$extension", "fallback\n");
my ($rc, $result) = run_command($^X,
'-I' . repo_path('perl-xCAT'), '-I' . repo_path('xCAT-server/lib/perl'),
'-e', 'require shift @ARGV; print imgutils::get_profile_def_filename(@ARGV)',
"$root/imgutils/imgutils.pm",
'debian12.5', 'compute', 'x86_64', "$root/assets", $extension);
is($rc, 0, "copied imgutils loads without any sibling distro directory") or diag($result);
is($result, $selected, "copied imgutils selects the $extension version fallback");
}
done_testing();