From aaa0068db7394326eac52b7be133f6794033d309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 26 Aug 2026 12:21:14 -0300 Subject: [PATCH] test: reuse repository file helpers --- xCAT-test/unit/copycd_grub2_loader.t | 13 ++--- xCAT-test/unit/dhcp_isc_client_arch.t | 11 ++-- xCAT-test/unit/el_riscv64_install_paths.t | 26 ++++----- xCAT-test/unit/install_profile_riscv64.t | 44 +++++++-------- xCAT-test/unit/lookup_netboot_arch.t | 23 +++----- xCAT-test/unit/mknb_xcatd_address.t | 10 ++-- xCAT-test/unit/netboot_profile_riscv64.t | 53 ++++++++++++------- xCAT-test/unit/nodediscover_default_netboot.t | 9 ++-- xCAT-test/unit/riscv64_packaging.t | 41 +++++++------- 9 files changed, 116 insertions(+), 114 deletions(-) diff --git a/xCAT-test/unit/copycd_grub2_loader.t b/xCAT-test/unit/copycd_grub2_loader.t index 5d6680ba5..dde0d982f 100644 --- a/xCAT-test/unit/copycd_grub2_loader.t +++ b/xCAT-test/unit/copycd_grub2_loader.t @@ -2,27 +2,24 @@ use strict; use warnings; -use Cwd qw(realpath); use File::Path qw(make_path); use File::Spec; use File::Temp qw(tempdir); use FindBin; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # copycd publishes the grub2 UEFI image of the installation media so that nodes # of an architecture xCAT builds no boot loader for -- riscv64 -- can net boot # without a further step. An image the management node already has is never # replaced, and the media of every other architecture is left alone. -my $repo_root = realpath( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); -my $plugin = File::Spec->catfile( $repo_root, 'xCAT-server', 'lib', 'xcat', 'plugins', 'anaconda.pm' ); +my $plugin = repo_path('xCAT-server/lib/xcat/plugins/anaconda.pm'); plan skip_all => "$plugin not found" unless -r $plugin; -my $source = do { - open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!"; - local $/; - <$fh>; -}; +my $source = slurp_repo_file('xCAT-server/lib/xcat/plugins/anaconda.pm'); # anaconda.pm needs a database to load, so take just the loader publication out # of it, the way the other unit tests here isolate a shipped sub. diff --git a/xCAT-test/unit/dhcp_isc_client_arch.t b/xCAT-test/unit/dhcp_isc_client_arch.t index d8a22aac2..8642528aa 100644 --- a/xCAT-test/unit/dhcp_isc_client_arch.t +++ b/xCAT-test/unit/dhcp_isc_client_arch.t @@ -3,23 +3,22 @@ use strict; use warnings; use FindBin; -use File::Spec; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # The ISC dhcpd subnet block in dhcp.pm maps DHCP option 93 (client system # architecture) to a boot file. The block is rendered inside a large # database-backed subroutine, so this pins the shipped source text: every # architecture branch must appear before the catch-all that hands unknown # clients /yaboot, otherwise the branch is unreachable. -my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); -my $plugin = File::Spec->catfile( $repo_root, 'xCAT-server', 'lib', 'xcat', 'plugins', 'dhcp.pm' ); +my $plugin = repo_path('xCAT-server/lib/xcat/plugins/dhcp.pm'); plan skip_all => "$plugin not found" unless -r $plugin; -open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!"; -my $source = do { local $/; <$fh> }; -close($fh); +my $source = slurp_repo_file('xCAT-server/lib/xcat/plugins/dhcp.pm'); my %branch = ( aarch64 => qr/client-architecture = 00:0b \{[^\n]*\n\s*push \@netent, "\s*filename \\"boot\/grub2\/grub2\.aarch64\\";/, diff --git a/xCAT-test/unit/el_riscv64_install_paths.t b/xCAT-test/unit/el_riscv64_install_paths.t index 8b9f97108..7b7438a0b 100644 --- a/xCAT-test/unit/el_riscv64_install_paths.t +++ b/xCAT-test/unit/el_riscv64_install_paths.t @@ -3,13 +3,15 @@ use strict; use warnings; use FindBin; -use File::Spec; +use lib "$FindBin::Bin/../lib"; use Test::More; 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 imgutils; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # EL riscv64 media and diskless images: the installer kernel/initrd live under # images/pxeboot like x86 and aarch64 media, and riscv64 diskless images need # their own default network drivers and lib64 resolver libraries. The @@ -17,21 +19,19 @@ use imgutils; # conditions are asserted in the shipped source and the resolver block is # extracted and evaluated directly. -my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); - -sub slurp { - my ($relative) = @_; - my $path = File::Spec->catfile( $repo_root, split( m{/}, $relative ) ); +my @source_files = ( + 'xCAT-server/lib/xcat/plugins/anaconda.pm', + 'xCAT-server/lib/xcat/plugins/geninitrd.pm', + 'xCAT-server/share/xcat/netboot/rh/genimage', +); +foreach my $relative (@source_files) { + my $path = repo_path($relative); plan skip_all => "$path not found" unless -r $path; - open( my $fh, '<', $path ) or die "Unable to read $path: $!"; - my $content = do { local $/; <$fh> }; - close($fh); - return $content; } -my $anaconda = slurp('xCAT-server/lib/xcat/plugins/anaconda.pm'); -my $geninitrd = slurp('xCAT-server/lib/xcat/plugins/geninitrd.pm'); -my $genimage = slurp('xCAT-server/share/xcat/netboot/rh/genimage'); +my $anaconda = slurp_repo_file($source_files[0]); +my $geninitrd = slurp_repo_file($source_files[1]); +my $genimage = slurp_repo_file($source_files[2]); # anaconda.pm: stateful install kernel/initrd discovery like( diff --git a/xCAT-test/unit/install_profile_riscv64.t b/xCAT-test/unit/install_profile_riscv64.t index 3a0cc3153..4a61ccae6 100644 --- a/xCAT-test/unit/install_profile_riscv64.t +++ b/xCAT-test/unit/install_profile_riscv64.t @@ -2,27 +2,20 @@ use strict; use warnings; -use Cwd qw(realpath); use File::Spec; use FindBin; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # EL10 riscv64 kickstart installs: the EL10 anaconda has no RISC-V EFI # platform, so the riscv64 templates tolerate its x86 boot loader package # request, pull grub2-efi-riscv64/efibootmgr in through the riscv64 package # lists, and run a %post that points the UEFI boot entry at grubriscv64.efi # and places the removable-media fallback loader. -my $repo_root = realpath( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); -my $install = File::Spec->catdir( $repo_root, 'xCAT-server', 'share', 'xcat', 'install' ); - -sub slurp { - my ($path) = @_; - open( my $fh, '<', $path ) or die "Unable to read $path: $!"; - my $content = do { local $/; <$fh> }; - close($fh); - return $content; -} +my $install = File::Spec->catdir( 'xCAT-server', 'share', 'xcat', 'install' ); for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { my ( $dir, $osbase ) = @$family; @@ -30,9 +23,9 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { my $tmpl = File::Spec->catfile( $install, $dir, "$profile.$osbase.riscv64.tmpl" ); my $pkglist = File::Spec->catfile( $install, $dir, "$profile.$osbase.riscv64.pkglist" ); my $base = File::Spec->catfile( $install, $dir, "$profile.$osbase.tmpl" ); - ok( -r $tmpl, "$dir/$profile.$osbase.riscv64.tmpl exists" ); - ok( -r $pkglist, "$dir/$profile.$osbase.riscv64.pkglist exists" ); - my $t = slurp($tmpl); + ok( -r repo_path($tmpl), "$dir/$profile.$osbase.riscv64.tmpl exists" ); + ok( -r repo_path($pkglist), "$dir/$profile.$osbase.riscv64.pkglist exists" ); + my $t = slurp_repo_file($tmpl); like( $t, qr/^%packages --ignoremissing$/m, "$dir/$profile.$osbase riscv64 template tolerates anaconda's x86 boot loader package request" ); like( $t, qr/^#INCLUDE_DEFAULT_PKGLIST#$/m, "$dir/$profile.$osbase riscv64 template still includes the default package list" ); like( $t, qr{^#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post\.rhels10\.riscv64#$}m, "$dir/$profile.$osbase riscv64 template runs the riscv64 UEFI boot entry fix-up" ); @@ -43,7 +36,7 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { like( $t, qr/^rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password#$/m, "$dir/$profile.$osbase riscv64 template keeps the shared root password directive" ); # the riscv64 template is the shared one plus the riscv64 changes - my $b = slurp($base); + my $b = slurp_repo_file($base); ( my $t_norm = $t ) =~ s/^# riscv64:.*\n(?:#.*\n)*%addon com_redhat_kdump --disable\n%end\n\n//m; $t_norm =~ s/^# riscv64:.*\n(?:#.*\n)*//m; $t_norm =~ s/^%packages --ignoremissing$/%packages/m; @@ -51,11 +44,13 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { $t_norm =~ s/\n# --ignoremissing above.*?\n%post --erroronfail.*?\n%end\n//s; is( $t_norm, $b, "$dir/$profile.$osbase riscv64 template only differs from the shared template in the riscv64 changes" ); - my $p = slurp($pkglist); + my $p = slurp_repo_file($pkglist); like( $p, qr/^grub2-efi-riscv64$/m, "$dir/$profile.$osbase riscv64 package list installs grub2-efi-riscv64" ); like( $p, qr/^efibootmgr$/m, "$dir/$profile.$osbase riscv64 package list installs efibootmgr" ); unlike( $p, qr/shim|grub2-efi-x64|grub2-efi-aa64/, "$dir/$profile.$osbase riscv64 package list asks for no other architecture's boot loader" ); - my $shared = slurp( File::Spec->catfile( $install, $dir, "$profile.$osbase.pkglist" ) ); + my $shared = slurp_repo_file( + File::Spec->catfile( $install, $dir, "$profile.$osbase.pkglist" ) + ); ( my $p_norm = $p ) =~ s/^grub2-efi-riscv64\n//m; $p_norm =~ s/^efibootmgr\n//m; s/\s+\z/\n/ for ( $p_norm, $shared ); @@ -69,7 +64,9 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { my ( $dir, $osbase ) = @$family; for my $profile (qw(compute service)) { - my $t = slurp( File::Spec->catfile( $install, $dir, "$profile.$osbase.riscv64.tmpl" ) ); + my $t = slurp_repo_file( + File::Spec->catfile( $install, $dir, "$profile.$osbase.riscv64.tmpl" ) + ); my ($section) = $t =~ /^(%post\b.*?)^%end/ms; ok( $section, "$dir/$profile.$osbase riscv64 template has a %post section" ) or next; @@ -78,7 +75,9 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { ok( defined $index, "$dir/$profile.$osbase riscv64 template includes the fix-up in the %post section" ) or next; for my $earlier ( @scripts[ 0 .. $index - 1 ] ) { - my $body = slurp( File::Spec->catfile( $install, 'scripts', $earlier ) ); + my $body = slurp_repo_file( + File::Spec->catfile( $install, 'scripts', $earlier ) + ); unlike( $body, qr/^\s*exit\b/m, "$dir/$profile.$osbase runs $earlier before the riscv64 fix-up, and $earlier does not end the %post" ); } @@ -86,10 +85,11 @@ for my $family ( [ 'rocky', 'rocky10' ], [ 'rh', 'rhels10' ] ) { } my $post = File::Spec->catfile( $install, 'scripts', 'post.rhels10.riscv64' ); -ok( -r $post, 'post.rhels10.riscv64 exists' ); -my $bash = `bash -n $post 2>&1`; +my $post_path = repo_path($post); +ok( -r $post_path, 'post.rhels10.riscv64 exists' ); +my $bash = `bash -n $post_path 2>&1`; is( $bash, '', 'post.rhels10.riscv64 parses as bash' ); -my $s = slurp($post); +my $s = slurp_repo_file($post); like( $s, qr/\[ "\$\(uname -m\)" = "riscv64" \]/, 'the fix-up only acts on riscv64' ); like( $s, qr{/boot/efi/EFI/\*/grubriscv64\.efi}, 'the fix-up locates the distro grub2 UEFI image on the ESP' ); like( $s, qr{cp -f "\$grubefi" /boot/efi/EFI/BOOT/BOOTRISCV64\.EFI}, 'the fix-up installs the removable-media fallback loader' ); diff --git a/xCAT-test/unit/lookup_netboot_arch.t b/xCAT-test/unit/lookup_netboot_arch.t index 15676ce8a..337d64b17 100644 --- a/xCAT-test/unit/lookup_netboot_arch.t +++ b/xCAT-test/unit/lookup_netboot_arch.t @@ -3,9 +3,11 @@ use strict; use warnings; use FindBin; -use File::Spec; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # riscv64 nodes boot through UEFI and grub2 only. This test pins the three # places that declare which noderes.netboot values an architecture accepts: # xCAT::Utils::lookupNetboot (used by nodeset/rinstall validation), the @@ -16,25 +18,16 @@ use Test::More; # time, so the shipped subroutines are extracted from the source and evaluated # directly instead of loading the whole modules. -my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); -my $utils_pm = File::Spec->catfile( $repo_root, 'perl-xCAT', 'xCAT', 'Utils.pm' ); -my $pnu_pm = File::Spec->catfile( $repo_root, 'perl-xCAT', 'xCAT', 'ProfiledNodeUtils.pm' ); +my $utils_pm = repo_path('perl-xCAT/xCAT/Utils.pm'); +my $pnu_pm = repo_path('perl-xCAT/xCAT/ProfiledNodeUtils.pm'); plan skip_all => "$utils_pm not found" unless -r $utils_pm; plan skip_all => "$pnu_pm not found" unless -r $pnu_pm; -sub slurp { - my ($path) = @_; - open( my $fh, '<', $path ) or die "Unable to read $path: $!"; - my $source = do { local $/; <$fh> }; - close($fh); - return $source; -} - # --------------------------------------------------------------------------- # xCAT::Utils::lookupNetboot # --------------------------------------------------------------------------- -my $utils_source = slurp($utils_pm); +my $utils_source = slurp_repo_file('perl-xCAT/xCAT/Utils.pm'); my ($lookup_sub) = $utils_source =~ m{^(sub lookupNetboot \{.*?^\})}ms; ok( $lookup_sub, 'lookupNetboot was located in xCAT::Utils' ) or BAIL_OUT('Utils.pm no longer matches the expected lookupNetboot shape'); @@ -69,7 +62,7 @@ is( Test::LookupNetboot::lookupNetboot( 'xCAT::Utils', 'rocky10.2', 'riscv64', ' # --------------------------------------------------------------------------- # xCAT::ProfiledNodeUtils netboot rule table + cal_netboot # --------------------------------------------------------------------------- -my $pnu_source = slurp($pnu_pm); +my $pnu_source = slurp_repo_file('perl-xCAT/xCAT/ProfiledNodeUtils.pm'); my ($netboot_dict) = $pnu_source =~ m{^(\s*my %netboot_dict = \(.*?^\s*\);)}ms; ok( $netboot_dict, 'the profiled-node netboot rule table was located' ) or BAIL_OUT('ProfiledNodeUtils.pm no longer matches the expected %netboot_dict shape'); @@ -102,7 +95,7 @@ is( Test::ProfiledNetboot::cal_netboot( $rule_table, [ 'aarch64', 'rhels', '9', # --------------------------------------------------------------------------- SKIP: { skip 'xCAT::Schema is not loadable here', 3 - unless eval { require lib; lib->import( File::Spec->catdir( $repo_root, 'perl-xCAT' ) ); require xCAT::Schema; 1 }; + unless eval { require lib; lib->import( repo_path('perl-xCAT') ); require xCAT::Schema; 1 }; like( $xCAT::Schema::tabspec{nodetype}{descriptions}{arch}, qr/\briscv64\b/, 'nodetype.arch documents riscv64 as a valid value' ); diff --git a/xCAT-test/unit/mknb_xcatd_address.t b/xCAT-test/unit/mknb_xcatd_address.t index 8cc92dd57..77836d302 100644 --- a/xCAT-test/unit/mknb_xcatd_address.t +++ b/xCAT-test/unit/mknb_xcatd_address.t @@ -4,9 +4,11 @@ use warnings; ## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings) use FindBin; +use lib "$FindBin::Bin/../lib"; use File::Path qw(make_path); use File::Temp qw(tempdir); use Test::More; +use XCAT::Test::File qw(repo_path); BEGIN { package xCAT::Utils; @@ -50,12 +52,8 @@ BEGIN { $INC{'xCAT/NodeRange.pm'} = __FILE__; } -my $source_mknb_plugin = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/mknb.pm"; -if (-f $source_mknb_plugin) { - require $source_mknb_plugin; -} else { - require xCAT_plugin::mknb; -} +my $source_mknb_plugin = repo_path('xCAT-server/lib/xcat/plugins/mknb.pm'); +require $source_mknb_plugin; my ($legacy, $selected) = xCAT_plugin::mknb::_select_network_addresses( { diff --git a/xCAT-test/unit/netboot_profile_riscv64.t b/xCAT-test/unit/netboot_profile_riscv64.t index 56a8f23c2..254e516bb 100644 --- a/xCAT-test/unit/netboot_profile_riscv64.t +++ b/xCAT-test/unit/netboot_profile_riscv64.t @@ -4,10 +4,12 @@ use warnings; ## no critic (Modules::RequireFilenameMatchesPackage) use FindBin; +use lib "$FindBin::Bin/../lib"; use File::Spec; -use Cwd qw(realpath); use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # EL10 riscv64 diskless and service profiles are plain data files resolved by # imgutils::get_profile_def_filename (osver.arch first, then osbase.arch, then # the arch-less fallbacks). Pin that the riscv64 files exist, win the lookup @@ -35,20 +37,15 @@ BEGIN { $INC{'xCAT/SvrUtils.pm'} = __FILE__; } -my $repo_root = realpath( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); -my $share = File::Spec->catdir( $repo_root, 'xCAT-server', 'share', 'xcat' ); -my $imgutils = File::Spec->catfile( $share, 'netboot', 'imgutils', 'imgutils.pm' ); +my $share_relative = File::Spec->catdir( 'xCAT-server', 'share', 'xcat' ); +my $share = repo_path($share_relative); +my $imgutils_relative = File::Spec->catfile( + $share_relative, 'netboot', 'imgutils', 'imgutils.pm' +); +my $imgutils = repo_path($imgutils_relative); plan skip_all => "$imgutils not found" unless -r $imgutils; require $imgutils; -sub slurp { - my ($path) = @_; - open( my $fh, '<', $path ) or die "Unable to read $path: $!"; - my $content = do { local $/; <$fh> }; - close($fh); - return $content; -} - my @families = ( [ 'rocky', 'rocky10', 'rocky10.2' ], [ 'rh', 'rhels10', 'rhels10.2' ], @@ -56,6 +53,7 @@ my @families = ( for my $family (@families) { my ( $dir, $osbase, $osver ) = @$family; + my $base_relative = File::Spec->catdir( $share_relative, 'netboot', $dir ); my $base = File::Spec->catdir( $share, 'netboot', $dir ); for my $profile (qw(compute service)) { @@ -68,34 +66,49 @@ for my $family (@families) { "$osver riscv64 $profile $ext resolves to the riscv64 file", ); } - my $x86 = slurp( File::Spec->catfile( $base, "$profile.$osbase.x86_64.pkglist" ) ); - my $rv = slurp( File::Spec->catfile( $base, "$profile.$osbase.riscv64.pkglist" ) ); + my $x86 = slurp_repo_file( + File::Spec->catfile( $base_relative, "$profile.$osbase.x86_64.pkglist" ) + ); + my $rv = slurp_repo_file( + File::Spec->catfile( $base_relative, "$profile.$osbase.riscv64.pkglist" ) + ); s/\s+\z/\n/ for ( $x86, $rv ); is( $rv, $x86, "$dir/$profile.$osbase riscv64 pkglist matches the x86_64 list (no arch-specific packages)" ); unlike( $rv, qr/^(?:microcode_ctl|grub2-efi-x64|shim-x64|syslinux|xnba)/m, "$dir/$profile.$osbase riscv64 pkglist has no x86-only packages" ); - my $exlist = slurp( File::Spec->catfile( $base, "$profile.$osbase.riscv64.exlist" ) ); + my $exlist = slurp_repo_file( + File::Spec->catfile( $base_relative, "$profile.$osbase.riscv64.exlist" ) + ); like( $exlist, qr{^\./lib/kbd/keymaps/include\*$}m, "$dir/$profile.$osbase riscv64 exlist excludes the kbd keymap includes" ); unlike( $exlist, qr{^\./lib/kdb/}m, "$dir/$profile.$osbase riscv64 exlist has no kdb typo" ); is( scalar( () = $exlist =~ m{^\./usr/share/man\*$}mg ), 1, "$dir/$profile.$osbase riscv64 exlist lists usr/share/man once" ); - my $postinstall = slurp( File::Spec->catfile( $base, "$profile.$osbase.riscv64.postinstall" ) ); + my $postinstall = slurp_repo_file( + File::Spec->catfile( $base_relative, "$profile.$osbase.riscv64.postinstall" ) + ); like( $postinstall, qr/^#!\/bin\/sh/, "$dir/$profile.$osbase riscv64 postinstall is a shell script" ); like( $postinstall, qr/SELINUX=disabled/, "$dir/$profile.$osbase riscv64 postinstall disables SELinux in the image" ); } my $otherpkgs = File::Spec->catfile( $base, "service.$osbase.riscv64.otherpkgs.pkglist" ); + my $otherpkgs_relative = File::Spec->catfile( + $base_relative, "service.$osbase.riscv64.otherpkgs.pkglist" + ); is( imgutils::get_profile_def_filename( $osver, 'service', 'riscv64', $base, 'otherpkgs.pkglist' ), $otherpkgs, "$osver riscv64 service otherpkgs resolves to the riscv64 file", ); - like( slurp($otherpkgs), qr{^xcat/xcat-dep/rh10/riscv64/goconserver$}m, "$dir netboot service otherpkgs pulls goconserver from the riscv64 EL10 dep repo" ); + like( slurp_repo_file($otherpkgs_relative), qr{^xcat/xcat-dep/rh10/riscv64/goconserver$}m, "$dir netboot service otherpkgs pulls goconserver from the riscv64 EL10 dep repo" ); - my $install_otherpkgs = File::Spec->catfile( $share, 'install', $dir, "service.$osbase.riscv64.otherpkgs.pkglist" ); + my $install_otherpkgs_relative = File::Spec->catfile( + $share_relative, 'install', $dir, + "service.$osbase.riscv64.otherpkgs.pkglist" + ); + my $install_otherpkgs = repo_path($install_otherpkgs_relative); ok( -r $install_otherpkgs, "install/$dir/service.$osbase.riscv64.otherpkgs.pkglist exists" ); - like( slurp($install_otherpkgs), qr{^xcat/xcat-dep/rh10/riscv64/goconserver$}m, "$dir install service otherpkgs pulls goconserver from the riscv64 EL10 dep repo" ); - like( slurp($install_otherpkgs), qr{^xcat/xcat-core/xCATsn$}m, "$dir install service otherpkgs installs xCATsn" ); + like( slurp_repo_file($install_otherpkgs_relative), qr{^xcat/xcat-dep/rh10/riscv64/goconserver$}m, "$dir install service otherpkgs pulls goconserver from the riscv64 EL10 dep repo" ); + like( slurp_repo_file($install_otherpkgs_relative), qr{^xcat/xcat-core/xCATsn$}m, "$dir install service otherpkgs installs xCATsn" ); } # an architecture without its own files still falls back to the arch-less ones diff --git a/xCAT-test/unit/nodediscover_default_netboot.t b/xCAT-test/unit/nodediscover_default_netboot.t index 39641171d..5edb8556c 100644 --- a/xCAT-test/unit/nodediscover_default_netboot.t +++ b/xCAT-test/unit/nodediscover_default_netboot.t @@ -4,9 +4,11 @@ use warnings; ## no critic (Modules::RequireFilenameMatchesPackage) use FindBin; -use File::Spec; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # nodediscover sets noderes.netboot for a freshly discovered node when the # admin did not pick a method that fits the reported architecture. The ladder # lives in _default_netboot() so it can be checked without a database: stub @@ -31,8 +33,7 @@ BEGIN { $INC{'xCAT/DiscoveryUtils.pm'} = __FILE__; } -my $repo_root = File::Spec->catdir( $FindBin::Bin, '..', '..' ); -my $plugin = File::Spec->catfile( $repo_root, 'xCAT-server', 'lib', 'xcat', 'plugins', 'nodediscover.pm' ); +my $plugin = repo_path('xCAT-server/lib/xcat/plugins/nodediscover.pm'); plan skip_all => "$plugin not found" unless -r $plugin; require $plugin; @@ -71,7 +72,7 @@ is( $warnings, 0, 'no warnings were emitted for undefined inputs' ); # The discovery request is stored as discovery data key by key, so reading the platform # of a node that never reported one must not add the key to the request. -my $source = do { open( my $fh, '<', $plugin ) or die "Unable to read $plugin: $!"; local $/; <$fh> }; +my $source = slurp_repo_file('xCAT-server/lib/xcat/plugins/nodediscover.pm'); like( $source, qr/my \$platform = exists \$request->\{platform\} \? \$request->\{platform\}->\[0\] : undef;/, diff --git a/xCAT-test/unit/riscv64_packaging.t b/xCAT-test/unit/riscv64_packaging.t index 99c5fd482..9f1fb0341 100644 --- a/xCAT-test/unit/riscv64_packaging.t +++ b/xCAT-test/unit/riscv64_packaging.t @@ -2,27 +2,18 @@ use strict; use warnings; -use File::Spec; use FindBin; +use lib "$FindBin::Bin/../lib"; use Test::More; +use XCAT::Test::File qw(repo_path slurp_repo_file); + # riscv64 packaging: the arch-named packages (xCAT, xCATsn) must resolve their # architecture token and dependencies for riscv64, and the build scripts must # know the riscv64 package names. The Genesis image comes from the OpenEmbedded # packages, so there is no arch-named Genesis package to resolve here. -my $repo_root = File::Spec->rel2abs( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); - -sub read_file { - my ($relative) = @_; - my $path = File::Spec->catfile( $repo_root, split( m{/}, $relative ) ); - open( my $fh, '<', $path ) or die "Unable to read $path: $!"; - my $content = do { local $/; <$fh> }; - close($fh); - return $content; -} - -my $xcat = read_file('xCAT/xCAT.spec'); +my $xcat = slurp_repo_file('xCAT/xCAT.spec'); like( $xcat, qr/^%ifarch riscv64\n(?:#[^\n]*\n)*Requires: ipmitool-xcat >= 1\.8\.18-4\n%endif$/m, 'xCAT.spec requires ipmitool-xcat on riscv64' ); my ($xcat_rv) = $xcat =~ /^%ifarch riscv64\n((?:#[^\n]*\n|Requires:[^\n]*\n)*)%endif$/m; unlike( $xcat_rv || '', qr/xnba-undi|syslinux-xcat|elilo-xcat/, 'xCAT.spec does not require the x86 PXE loaders on riscv64' ); @@ -32,16 +23,26 @@ unlike( $xcat_rv || '', qr/xnba-undi|syslinux-xcat|elilo-xcat/, 'xCAT.spec does like( $xcat, qr/^%\{\?genesistarch:Requires: xCAT-genesis-scripts-%\{genesistarch\} = 1:%\{version\}-%\{release\}\}$/m, 'xCAT.spec asks for the legacy Genesis package only where the architecture has one' ); SKIP: { - skip 'rpmspec is not installed', 2 unless `sh -c 'command -v rpmspec' 2>/dev/null`; - my $requires = `rpmspec -q --target riscv64 --requires xCAT/xCAT.spec 2>/dev/null`; + my $rpmspec = qx(command -v rpmspec 2>/dev/null); + chomp($rpmspec); + skip 'rpmspec is not installed', 2 unless $rpmspec && -x $rpmspec; + + my $spec = repo_path('xCAT/xCAT.spec'); + open( my $requires_fh, '-|', + $rpmspec, '-q', '--target', 'riscv64', '--requires', $spec ) + or BAIL_OUT("unable to run $rpmspec: $!"); + my $requires = do { local $/; <$requires_fh> }; + close($requires_fh) + or BAIL_OUT("rpmspec failed for $spec with status " . ($? >> 8)); + unlike( $requires, qr/genesis-scripts/, 'a riscv64 build requires no legacy Genesis package' ); unlike( $requires, qr/\Q%{genesistarch}\E/, 'a riscv64 build leaves no unexpanded architecture macro' ); } -my $xcatsn = read_file('xCATsn/xCATsn.spec'); +my $xcatsn = slurp_repo_file('xCATsn/xCATsn.spec'); like( $xcatsn, qr/^%ifarch riscv64\nRequires: ipmitool-xcat >= 1\.8\.17-1\n%endif$/m, 'xCATsn.spec requires ipmitool-xcat on riscv64' ); -my $server = read_file('xCAT-server/xCAT-server.spec'); +my $server = slurp_repo_file('xCAT-server/xCAT-server.spec'); like( $server, qr/^Recommends: perl-DB_File$/m, 'xCAT-server.spec recommends perl-DB_File on EL10 (riscv64 has no EPEL to provide it)' ); like( $server, @@ -61,14 +62,14 @@ like( like( $server, qr/^Requires: perl-Net-Telnet perl-Net-DNS perl-Crypt-CBC perl-Crypt-Rijndael$/m, 'xCAT-server.spec keeps the other EL perl requires' ); -my $buildcore = read_file('buildcore.sh'); +my $buildcore = slurp_repo_file('buildcore.sh'); like( $buildcore, qr/^\s*for arch in x86_64 ppc64 ppc64le s390x aarch64 riscv64; do$/m, 'buildcore.sh builds xCAT and xCATsn for riscv64' ); -my $buildlocal = read_file('buildlocal.sh'); +my $buildlocal = slurp_repo_file('buildlocal.sh'); like( $buildlocal, qr/^\s*for arch in x86_64 ppc64 s390x aarch64 riscv64; do$/m, 'buildlocal.sh builds xCAT and xCATsn for riscv64' ); like( $buildlocal, qr{^\s*cp /root/rpmbuild/RPMS/riscv64/\* \$CURDIR/build/$}m, 'buildlocal.sh collects riscv64 rpms' ); -my $buildrpms = read_file('buildrpms.pl'); +my $buildrpms = slurp_repo_file('buildrpms.pl'); like( $buildrpms, qr/forcearch/, 'buildrpms.pl documents the forcearch mock configuration for riscv64 builds' ); # buildrpms.pl derives the rpm architecture from the mock target name; a suffixed