From 8fadd0664ecf9196ca39fad852a132827bf84352 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, 25 Aug 2026 11:23:59 -0300 Subject: [PATCH] test(genesis): cover reviewed edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- .github/workflows/xcat_test.yml | 2 +- xCAT-test/unit/anaconda_genesis_boot_files.t | 10 +-- .../unit/genesis_openembedded_activation.t | 72 +++++++------------ xCAT-test/unit/mknb_exported_genesis.t | 25 +++++++ 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index f5fb41db8..b90553a92 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -7,7 +7,7 @@ jobs: steps: - uses: actions/checkout@v6 - name: Install dependencies - run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests build-essential fakeroot reprepro devscripts debhelper libcapture-tiny-perl libjson-perl libsoap-lite-perl libdbi-perl libcgi-pm-perl quilt openssh-server dpkg looptools genometools software-properties-common + run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests build-essential fakeroot reprepro devscripts debhelper libcapture-tiny-perl libfile-slurper-perl libjson-perl libsoap-lite-perl libdbi-perl libcgi-pm-perl quilt openssh-server dpkg looptools genometools software-properties-common - name: Run tests run: perl github_action_xcat_test.pl diff --git a/xCAT-test/unit/anaconda_genesis_boot_files.t b/xCAT-test/unit/anaconda_genesis_boot_files.t index 4d26a4950..6b7c6286f 100644 --- a/xCAT-test/unit/anaconda_genesis_boot_files.t +++ b/xCAT-test/unit/anaconda_genesis_boot_files.t @@ -3,6 +3,7 @@ use strict; use warnings; use File::Path qw(make_path); +use File::Slurper qw(write_text); use File::Temp qw(tempdir); use FindBin; use Test::More; @@ -17,13 +18,6 @@ use lib "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins"; require anaconda; -sub write_file { - my ($path) = @_; - open(my $fh, '>', $path) or die "open $path: $!"; - print {$fh} "test\n"; - close($fh) or die "close $path: $!"; -} - my $tftp = tempdir(CLEANUP => 1); make_path("$tftp/xcat"); for my $path (qw( @@ -32,7 +26,7 @@ for my $path (qw( genesis.fs.ppc64.lzma genesis.fs.ppc64le.gz )) { - write_file("$tftp/xcat/$path"); + write_text("$tftp/xcat/$path", "test\n"); } my ($kernel, $initrd) = diff --git a/xCAT-test/unit/genesis_openembedded_activation.t b/xCAT-test/unit/genesis_openembedded_activation.t index 820a8567e..8294c57df 100644 --- a/xCAT-test/unit/genesis_openembedded_activation.t +++ b/xCAT-test/unit/genesis_openembedded_activation.t @@ -2,36 +2,25 @@ use strict; use warnings; -use File::Spec; use FindBin; +use lib "$FindBin::Bin/../lib"; use Test::More; -my $root = File::Spec->rel2abs(File::Spec->catdir($FindBin::Bin, '..', '..')); +use XCAT::Test::File qw(slurp_repo_file); -sub read_file { - my ($relative) = @_; - my $path = File::Spec->catfile($root, split m{/}, $relative); - open(my $fh, '<', $path) or die "open $path: $!"; - my $content = do { local $/; <$fh> }; - close($fh) or die "close $path: $!"; - return $content; -} +my $rpm_weak_dependencies = join( + "\n", + '%if 0%{?fedora} || 0%{?rhel} >= 8 || 0%{?suse_version} >= 1500', + 'Recommends: xCAT-genesis-openembedded-x86_64', + 'Recommends: xCAT-genesis-openembedded-ppc64le', + '%endif', +); -my $rpm_spec = read_file('xCAT/xCAT.spec'); +my $rpm_spec = slurp_repo_file('xCAT/xCAT.spec'); like( $rpm_spec, - qr/^%if 0%\{\?fedora\} \|\| 0%\{\?rhel\} >= 8 \|\| 0%\{\?suse_version\} >= 1500$/m, - 'RPM weak dependencies are limited to package managers that support them', -); -like( - $rpm_spec, - qr/^Recommends:\s+xCAT-genesis-openembedded-x86_64$/m, - 'RPM installations recommend the first-class x86_64 image', -); -like( - $rpm_spec, - qr/^Recommends:\s+xCAT-genesis-openembedded-ppc64le$/m, - 'RPM installations recommend the first-class ppc64le image', + qr/^\Q$rpm_weak_dependencies\E$/m, + 'RPM weak dependencies stay inside their compatibility guard', ); unlike( $rpm_spec, @@ -39,7 +28,7 @@ unlike( 'missing OpenEmbedded images do not block an RPM upgrade', ); -my $deb_control = read_file('xCAT/debian/control'); +my $deb_control = slurp_repo_file('xCAT/debian/control'); like( $deb_control, qr/^Recommends:.*\bxcat-genesis-openembedded-x86-64\b/m, @@ -56,24 +45,14 @@ unlike( 'missing OpenEmbedded images do not block a DEB upgrade', ); -my $sn_rpm_spec = read_file('xCATsn/xCATsn.spec'); +my $sn_rpm_spec = slurp_repo_file('xCATsn/xCATsn.spec'); like( $sn_rpm_spec, - qr/^%if 0%\{\?fedora\} \|\| 0%\{\?rhel\} >= 8 \|\| 0%\{\?suse_version\} >= 1500$/m, - 'service-node weak dependencies use the same compatibility guard', -); -like( - $sn_rpm_spec, - qr/^Recommends:\s+xCAT-genesis-openembedded-x86_64$/m, - 'RPM service nodes recommend the first-class x86_64 image', -); -like( - $sn_rpm_spec, - qr/^Recommends:\s+xCAT-genesis-openembedded-ppc64le$/m, - 'RPM service nodes recommend the first-class ppc64le image', + qr/^\Q$rpm_weak_dependencies\E$/m, + 'service-node weak dependencies stay inside their compatibility guard', ); -my $sn_deb_control = read_file('xCATsn/debian/control'); +my $sn_deb_control = slurp_repo_file('xCATsn/debian/control'); like( $sn_deb_control, qr/^Recommends:.*\bxcat-genesis-openembedded-x86-64\b/m, @@ -85,7 +64,7 @@ like( 'DEB service nodes recommend the first-class ppc64le image', ); -my $go_xcat = read_file('xCAT-server/share/xcat/tools/go-xcat'); +my $go_xcat = slurp_repo_file('xCAT-server/share/xcat/tools/go-xcat'); unlike( $go_xcat, qr/GO_XCAT_LIBRARY_ONLY/, @@ -105,7 +84,7 @@ for my $architecture (qw(x86 x86_64 ppc64 ppc64le armv7hf aarch64 riscv64)) { ); } -my $mknb_pod = read_file('xCAT-client/pods/man8/mknb.8.pod'); +my $mknb_pod = slurp_repo_file('xCAT-client/pods/man8/mknb.8.pod'); like( $mknb_pod, qr{/opt/xcat/share/xcat/netboot/genesis-openembedded/ARCH}, @@ -122,7 +101,8 @@ unlike( 'the mknb man page no longer presents ppc64 as the ppc64le name', ); -my $offline_guide = read_file('docs/source/guides/install-guides/common_sections.rst'); +my $offline_guide = + slurp_repo_file('docs/source/guides/install-guides/common_sections.rst'); like( $offline_guide, qr/reposync.*--repofrompath=xcat-dep-common,https:\/\/xcat\.org\/.*\/xcat-dep\/common.*--repoid=xcat-dep-common.*--download-metadata/s, @@ -159,18 +139,16 @@ unlike( 'the offline guide does not depend on files reposync cannot download', ); -my $yum_guide = read_file( - 'docs/source/guides/install-guides/yum/configure_xcat.rst' -); +my $yum_guide = + slurp_repo_file('docs/source/guides/install-guides/yum/configure_xcat.rst'); like( $yum_guide, qr/start-after: BEGIN_configure_xcat_local_repo_xcat-dep_DNF/, 'the DNF guide includes the DNF common repository steps', ); -my $zypper_guide = read_file( - 'docs/source/guides/install-guides/zypper/configure_xcat.rst' -); +my $zypper_guide = + slurp_repo_file('docs/source/guides/install-guides/zypper/configure_xcat.rst'); like( $zypper_guide, qr/start-after: BEGIN_configure_xcat_local_repo_xcat-dep_ZYPPER/, diff --git a/xCAT-test/unit/mknb_exported_genesis.t b/xCAT-test/unit/mknb_exported_genesis.t index 4d8256751..faaf980a2 100644 --- a/xCAT-test/unit/mknb_exported_genesis.t +++ b/xCAT-test/unit/mknb_exported_genesis.t @@ -156,6 +156,31 @@ ok(!-e "$tftpdir/xcat/genesis.exact-arch.ppc64le", ok(-f "$tftpdir/xcat/genesis.kernel.ppc64", 'retiring ppc64le does not remove the legacy ppc64 fallback'); +my $failed_kernel = "$tftpdir/xcat/genesis.kernel.aarch64"; +make_path($failed_kernel); +for my $artifact (qw( + genesis.fs.aarch64.gz + genesis.fs.aarch64.lzma + genesis.exact-arch.aarch64 +)) { + write_file("$tftpdir/xcat/$artifact", 'stale artifact'); +} +($removed, $remove_error) = + xCAT_plugin::mknb::_remove_openembedded_genesis($tftpdir, 'aarch64'); +is($removed, 3, 'artifact cleanup continues after an unlink failure'); +like( + $remove_error, + qr/Unable to remove Genesis artifact: \Q$failed_kernel\E/, + 'artifact cleanup reports the failed path', +); +ok(-d $failed_kernel, 'the failed artifact remains in place'); +ok( + !-e "$tftpdir/xcat/genesis.fs.aarch64.gz" + && !-e "$tftpdir/xcat/genesis.fs.aarch64.lzma" + && !-e "$tftpdir/xcat/genesis.exact-arch.aarch64", + 'artifact cleanup removes every remaining path', +); + write_file($published_kernel, 'current kernel'); write_file($published_initramfs, 'current initramfs'); write_file("$export/kernel", 'corrupt kernel');