From ca2aec5397233926ebb2984c4e10391b6d976da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 3 Sep 2026 19:12:24 -0300 Subject: [PATCH] test(xCAT-test): cover the debootstrap architecture genimage passes Drive the assignment genimage makes and check the name debootstrap receives for each architecture, including the POWER LE spelling that debootstrap rejects. --- .../unit/ubuntu_genimage_debootstrap_arch.t | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 xCAT-test/unit/ubuntu_genimage_debootstrap_arch.t diff --git a/xCAT-test/unit/ubuntu_genimage_debootstrap_arch.t b/xCAT-test/unit/ubuntu_genimage_debootstrap_arch.t new file mode 100644 index 000000000..f47341864 --- /dev/null +++ b/xCAT-test/unit/ubuntu_genimage_debootstrap_arch.t @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Spec; +use FindBin; +use Test::More; + +# debootstrap takes the Debian architecture name, which differs from the name xCAT uses for +# the node. Drive the assignment genimage makes and check the name it computes. The +# invocation that consumes it is not exercised here. + +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use xCAT::Utils; + +my $repo_root = File::Spec->rel2abs(File::Spec->catdir($FindBin::Bin, '..', '..')); +my $genimage = File::Spec->catfile( + $repo_root, 'xCAT-server', 'share', 'xcat', 'netboot', 'ubuntu', 'genimage'); +plan skip_all => "genimage not found at $genimage" unless -f $genimage; + +my $src = do { local $/; open my $fh, '<', $genimage or die $!; <$fh> }; +# Take every line that assigns $uarch, not just the first: the name has been built in +# more than one statement before, and half of it would look like a different value. +my ($assignment) = $src =~ /^(my \$uarch\b.*?)\n\s*\n/ms; +ok(defined $assignment, 'found the debootstrap architecture assignment in genimage') + or do { done_testing(); exit }; + +sub debootstrap_arch { + my ($arch) = @_; + my $uarch; + my $code = $assignment; + $code =~ s/^my\s+//; + no strict 'subs'; ## the script itself does not enable strict subs + eval "$code 1" or die $@; ## no critic (BuiltinFunctions::ProhibitStringyEval) + return $uarch; +} + +is(debootstrap_arch('x86_64'), 'amd64', 'x86_64 resolves to the Debian name amd64'); +is(debootstrap_arch('ppc64el'), 'ppc64el', 'the Debian spelling of POWER LE is kept'); +is(debootstrap_arch('ppc64le'), 'ppc64le', 'the POWER LE alias is passed through, as it is today'); +is(debootstrap_arch('s390x'), 's390x', 'an architecture Debian names the same is passed through'); + +done_testing();