From bf561167325361a4496258d56827096f389c66d2 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:07:52 -0300 Subject: [PATCH] refactor(debian): map media architectures through a shared table copycd translated the architecture the Ubuntu media reports with its own if/elsif chain, and genimage translates the same names back for debootstrap with another one. Neither can be reused, so a new architecture has to be added to both. Put both directions in xCAT::Utils and have copycd read from there. The names and the fallback do not change: media that xCAT has no name for still leave the architecture as the media reported it. --- perl-xCAT/xCAT/Utils.pm | 49 ++++++++++++++++++++++++++ xCAT-server/lib/xcat/plugins/debian.pm | 18 ++-------- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 142164f08..838e40bbb 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -4862,6 +4862,55 @@ sub splitkcmdline { } +################################################################################### +#subroutine debian_arch +#Usage: give the Debian architecture name for an xCAT architecture. The media, the +# package lists and debootstrap all use the Debian name. +#Input Params: +# $arch: the xCAT architecture, for example x86_64 or ppc64le +#Return value: +# the Debian architecture name, or the input when Debian names it the same +################################################################################### +# ppc64le is deliberately absent: the Ubuntu driver table, the NSS libraries and the +# image paths all key on ppc64el, so translating it here alone would build an image +# without network drivers instead of stopping at debootstrap. +my %DEBIAN_ARCH = ( + 'x86_64' => 'amd64', +); + +sub debian_arch { + my $arch = shift; + $arch = shift if ($arch =~ /xCAT::Utils/); + return unless defined $arch; + return $DEBIAN_ARCH{ lc $arch } // $arch; +} + +################################################################################### +#subroutine xcat_arch_from_debian +#Usage: give the xCAT architecture for the architecture the Ubuntu media reports. +#Input Params: +# $darch: the architecture from the media, for example amd64 or ppc64el +#Return value: +# the xCAT architecture, or undef when the media names one xCAT does not know +################################################################################### +my @XCAT_ARCH_FROM_DEBIAN = ( + [ qr/^i.86$/ => 'x86' ], + [ qr/^ppc64el$/ => 'ppc64el' ], + [ qr/ppc|powerpc/ => 'ppc64' ], + [ qr/^amd64$/ => 'x86_64' ], +); + +sub xcat_arch_from_debian { + my $darch = shift; + $darch = shift if ($darch =~ /xCAT::Utils/); + return unless defined $darch and $darch ne ''; + foreach my $rule (@XCAT_ARCH_FROM_DEBIAN) { + my ($pattern, $arch) = @{$rule}; + return $arch if $darch =~ $pattern; + } + return; +} + ################################################################################### #subroutine lookupNetboot #Usage: determine the possible noderes.netboot values of the osimage diff --git a/xCAT-server/lib/xcat/plugins/debian.pm b/xCAT-server/lib/xcat/plugins/debian.pm index fbae0f344..7f98fdf7e 100644 --- a/xCAT-server/lib/xcat/plugins/debian.pm +++ b/xCAT-server/lib/xcat/plugins/debian.pm @@ -368,22 +368,8 @@ sub copycd # So that I can use amd64 below my $debarch = $darch; - if ($darch and $darch =~ /i.86/) - { - $darch = "x86"; - } - elsif ($darch and $darch =~ /ppc64el/) - { - $darch = "ppc64el"; - } - elsif ($darch and ($darch =~ /ppc/ or $darch =~ /powerpc/)) - { - $darch = "ppc64"; - } - elsif ($darch and $darch =~ /amd64/) - { - $darch = "x86_64"; - } + my $mapped = xCAT::Utils->xcat_arch_from_debian($darch); + $darch = $mapped if $mapped; if ($darch) {