2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-22 07:38:08 +00:00
Files
xcat-core/xCAT-test/unit/xcattest_os_selection.t
T
Daniel Hilst 3582c6ab19 fix(xcat-core): xcattest runs no test case on an openEuler management node
xcattest reports "Test case <name> has an invalid OS option - Linux" and then
"There is no valid case to run", so every case is skipped on openEuler.
Recorded on an openEuler 24.03 LTS SP4 management node with xCAT 2.20.0: both
flat provisioning cases were rejected and the run measured nothing.

Two causes, both in the os: comparison in xCAT-test/xcattest. get_current_os
takes the /etc/os-release branch, finds no sles, and falls off the end of that
branch, so it returns the exit status of the failed grep, 256, which names no
distribution. And a case marked os:Linux expands to exactly rhels, sles and
ubuntu, so openEuler would be rejected even by a correct get_current_os.

Both halves move into xCAT::Test::OS. xcattest finds it beside itself and the
package installs it at <prefix>/lib/perl. current_os takes a path prefix, so a
test describes a system by writing release files into a scratch tree. openEuler
is named in both halves and nothing else changes.

xCAT-test/unit/xcattest_os_selection.t covers it. Removing openeuler from
linux_aliases fails two checks, and removing the openEuler branch from
current_os fails three. A further case gives a root both /etc/redhat-release
and an openEuler /etc/os-release and asserts rhels10, so the precedence is
named: openEuler ships neither that file nor /etc/lsb-release.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-09-30 19:59:41 -03:00

77 lines
2.9 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
use xCAT::Test::OS;
sub a_system {
my (%files) = @_;
my $root = tempdir(CLEANUP => 1);
make_path("$root/etc");
for my $name (sort keys %files) {
open my $fh, '>', "$root/etc/$name" or die "write $root/etc/$name: $!";
print {$fh} $files{$name};
close $fh or die "close $root/etc/$name: $!";
}
return $root;
}
my $OPENEULER_OS_RELEASE = <<'REL';
NAME="openEuler"
VERSION="24.03 (LTS-SP4)"
ID="openEuler"
VERSION_ID="24.03"
PRETTY_NAME="openEuler 24.03 (LTS-SP4)"
REL
is(xCAT::Test::OS::current_os(a_system('os-release' => $OPENEULER_OS_RELEASE,
'openEuler-release' => "openEuler release 24.03 (LTS-SP4)\n",
'system-release' => "openEuler release 24.03 (LTS-SP4)\n")),
'openeuler24.03sp4',
'openEuler 24.03 SP4 is named, with the release copycds puts in its osimage names');
is(xCAT::Test::OS::current_os(a_system('redhat-release' => "AlmaLinux release 10.2 (Lavender Lion)\n",
'os-release' => $OPENEULER_OS_RELEASE)),
'rhels10',
'/etc/redhat-release decides before /etc/os-release, so openEuler must not ship one');
my $sp3 = $OPENEULER_OS_RELEASE;
$sp3 =~ s/LTS-SP4/LTS-SP3/;
is(xCAT::Test::OS::current_os(a_system('os-release' => $sp3)), 'openeuler24.03sp3',
'a different service pack is a different name');
my $lts = $OPENEULER_OS_RELEASE;
$lts =~ s/VERSION="24\.03 \(LTS-SP4\)"/VERSION="22.03 (LTS)"/;
is(xCAT::Test::OS::current_os(a_system('os-release' => $lts)), 'openeuler22.03',
'a release with no service pack carries no sp token');
is(xCAT::Test::OS::current_os(a_system('os-release' => qq{NAME="Fedora Linux"\nID=fedora\n})),
undef, 'a distribution whose ID is not openEuler is not openEuler');
is(xCAT::Test::OS::current_os(a_system('redhat-release' => "AlmaLinux release 9.4 (Seafoam Ocelot)\n",
'os-release' => qq{ID="almalinux"\n})),
'rhels9', 'a Red Hat family system is rhels plus its major version');
is(xCAT::Test::OS::current_os(a_system('lsb-release' => "DISTRIB_ID=Ubuntu\n")), 'ubuntu',
'Ubuntu is named from lsb-release');
is(xCAT::Test::OS::current_os(a_system('os-release' => qq{ID="sles"\nVERSION="15-SP6"\n})), 'sles',
'SLES is named from os-release');
is(xCAT::Test::OS::current_os(a_system()), 'aix',
'a system with none of the release files is aix, as before');
my @aliases = xCAT::Test::OS::linux_aliases();
for my $family (qw(rhels sles ubuntu openeuler)) {
ok(scalar(grep { $_ eq $family } @aliases), "os:Linux includes $family");
}
my $current = 'openeuler24.03sp4';
ok(scalar(grep { $current =~ /$_/i } @aliases),
'an openEuler management node matches an os:Linux case');
done_testing();