From 9812d14928ca75674dc628a4651dabfb09aa6745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sat, 5 Sep 2026 01:49:30 -0300 Subject: [PATCH] test(xCAT-test): cover the netboot mirror genimage defaults to MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Evaluates the selection genimage performs, so the test tracks the script. Covers the ports archive for ppc64el and riscv64, the main archive for amd64 and i386, and site.ubuntu_apt_mirror overriding both without an empty value blanking the mirror. Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- xCAT-test/unit/ubuntu_genimage_apt_mirror.t | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 xCAT-test/unit/ubuntu_genimage_apt_mirror.t diff --git a/xCAT-test/unit/ubuntu_genimage_apt_mirror.t b/xCAT-test/unit/ubuntu_genimage_apt_mirror.t new file mode 100644 index 000000000..172ab8b47 --- /dev/null +++ b/xCAT-test/unit/ubuntu_genimage_apt_mirror.t @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Spec; +use FindBin; +use Test::More; + +# archive.ubuntu.com publishes amd64 and i386 only. A ppc64el or riscv64 netboot image built +# against it finds no package at all, and debootstrap fails before it copies anything, so the +# default mirror has to follow the image architecture. +# +# Driven by the real selection code: the two statements are extracted from genimage and +# evaluated here, so this test tracks the script rather than a copy of it. + +my $repo_root = File::Spec->rel2abs( File::Spec->catdir( $FindBin::Bin, '..', '..' ) ); +my $genimage_path = File::Spec->catfile( + $repo_root, 'xCAT-server', 'share', 'xcat', 'netboot', 'ubuntu', 'genimage' +); +plan skip_all => "genimage not found at $genimage_path" unless -f $genimage_path; + +my $src = do { local $/; open my $fh, '<', $genimage_path or die $!; <$fh> }; + +my ($default) = $src =~ /^\s*(my \$default = \(\$uarch =~.*?;)\s*$/ms; +ok( defined $default, 'found the default mirror selection in genimage' ) + or done_testing(), exit; + +my ($pick) = $src =~ /^\s*(my \$mirror = \(defined \$aptmirror\[0\].*?;)\s*$/ms; +ok( defined $pick, 'found the mirror override in genimage' ) + or done_testing(), exit; + +sub choose { + my ( $uarch, $site ) = @_; + my $set = defined $site ? "('$site')" : "()"; + ## no critic (BuiltinFunctions::ProhibitStringyEval) + my $mirror = eval "my \$uarch = '$uarch'; my \@aptmirror = $set; $default $pick \$mirror"; + ## use critic + die "failed to evaluate the genimage mirror selection: $@" if $@; + return $mirror; +} + +is( choose('riscv64'), 'http://ports.ubuntu.com/ubuntu-ports', + 'a riscv64 image takes the ports archive' ); +is( choose('ppc64el'), 'http://ports.ubuntu.com/ubuntu-ports', + 'a ppc64el image takes the ports archive' ); +is( choose('amd64'), 'http://archive.ubuntu.com/ubuntu', + 'an amd64 image keeps the main archive' ); +is( choose('i386'), 'http://archive.ubuntu.com/ubuntu', + 'an i386 image keeps the main archive' ); + +is( choose( 'riscv64', 'http://mirror.example.invalid/ubuntu' ), + 'http://mirror.example.invalid/ubuntu', + 'site.ubuntu_apt_mirror overrides the ports archive' ); +is( choose( 'amd64', 'http://mirror.example.invalid/ubuntu' ), + 'http://mirror.example.invalid/ubuntu', + 'site.ubuntu_apt_mirror overrides the main archive' ); +is( choose( 'riscv64', '' ), 'http://ports.ubuntu.com/ubuntu-ports', + 'an empty site.ubuntu_apt_mirror does not blank the mirror' ); + +done_testing();