2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-01 16:31:41 +00:00

Merge pull request #7892 from VersatusHPC/fix/xcattest-openeuler-os

fix(xcat-core): xcattest runs no test case on an openEuler management node
This commit is contained in:
Daniel Hilst
2026-09-30 21:06:14 -03:00
committed by GitHub
8 changed files with 207 additions and 25 deletions
+1
View File
@@ -5,3 +5,4 @@ share/doc/man1/* opt/xcat/share/doc/man1
autotest opt/xcat/share/xcat/tools
unit opt/xcat/share/xcat/tools/autotest
integration opt/xcat/share/xcat/tools/autotest
lib/xCAT/Test/OS.pm opt/xcat/lib/perl/xCAT/Test
+87
View File
@@ -0,0 +1,87 @@
package xCAT::Test::OS;
use strict;
use warnings;
#-----------------------------------------------------------------------------
=head1 NAME
xCAT::Test::OS - the operating system names xcattest matches a case against
=head1 DESCRIPTION
A test case declares the distributions it runs on in its C<os:> attribute, and xcattest compares
that list against the distribution it is running on. Both halves of the comparison live here, so a
distribution is named in one place and a unit test can call them.
=cut
#-----------------------------------------------------------------------------
#---
# =head3 linux_aliases
# Descriptions: the distributions a case's `os:Linux` stands for.
# Arguments: none
# Returns: the list of os names
#---
sub linux_aliases {
return qw(rhels sles ubuntu openeuler);
}
#---
# =head3 current_os
# Descriptions: the os name of the running system, in the spelling a case's `os:` attribute uses.
# Arguments: $root - a path prefix, for tests
# Returns: an os name, or undef
#---
sub current_os {
my ($root) = @_;
$root = '' unless defined $root;
if (-f "$root/etc/redhat-release") {
my $text = _slurp("$root/etc/redhat-release");
my ($major) = (defined($text) && $text =~ /(\d+)\.(\d*)/) ? ($1) : ('');
return "rhels$major";
}
return 'ubuntu' if -f "$root/etc/lsb-release";
if (-f "$root/etc/os-release") {
my $text = _slurp("$root/etc/os-release") // '';
return 'sles' if $text =~ /sles/;
if ($text =~ /^ID\s*=\s*"?openeuler"?\s*$/mi) {
my ($version) = $text =~ /^VERSION\s*=\s*"?([^"\n]+?)"?\s*$/mi;
my $release = _openeuler_release($version);
return defined($release) ? "openeuler$release" : 'openeuler';
}
return undef;
}
return 'sles' if -f "$root/etc/SuSE-release";
return 'aix';
}
#---
# =head3 _openeuler_release
# Descriptions: the release token openEuler's osimage names carry, from an os-release VERSION.
# Arguments: $version - the VERSION value of /etc/os-release
# Returns: a release token, or undef
#---
sub _openeuler_release {
my ($version) = @_;
return undef unless defined $version;
$version =~ s/^\s+|\s+$//g;
my ($release, $sp) = $version =~ /\A((?:20|22|24)\.03)(?:\s*\(LTS(?:-SP([1-9][0-9]*))?\))?\z/i
or return undef;
return $release . (defined($sp) ? "sp$sp" : '');
}
sub _slurp {
my ($path) = @_;
open my $fh, '<', $path or return undef;
local $/;
my $text = <$fh>;
close $fh;
return $text;
}
1;
@@ -54,9 +54,11 @@ for my $file (sort keys %checks) {
# xcattest derives its result directory from the location of the program, so the copy under the
# scratch tree keeps every file the run writes inside that tree.
my $root = tempdir(CLEANUP => 1);
make_path("$root/bin", "$root/cases");
make_path("$root/bin", "$root/cases", "$root/lib/perl/xCAT/Test");
copy($program, "$root/bin/xcattest") or die("copy xcattest: $!");
chmod 0755, "$root/bin/xcattest";
copy("$FindBin::Bin/../lib/xCAT/Test/OS.pm", "$root/lib/perl/xCAT/Test/OS.pm")
or die("copy xCAT/Test/OS.pm: $!");
open(my $fixture_fh, '>', "$root/cases/fixture") or die("write the fixture case: $!");
print $fixture_fh $fixture;
close($fixture_fh) or die("close the fixture case: $!");
+76
View File
@@ -0,0 +1,76 @@
#!/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();
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env perl
# The installed xcattest loads the modules under xCAT-test/lib/xCAT from /opt/xcat/lib/perl, so
# both packages must ship each one.
use strict;
use warnings;
use File::Find;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
use XCAT::Test::File qw(repo_path slurp_repo_file);
my $lib = repo_path('xCAT-test/lib');
my @modules;
find(sub { push @modules, $File::Find::name =~ s{\A\Q$lib\E/}{}r if /\.pm\z/ }, "$lib/xCAT");
@modules = sort @modules;
ok(@modules, 'xCAT-test ships at least one Perl module to the installed tree');
my $rpm_spec = slurp_repo_file('xCAT-test/xCAT-test.spec');
my $debian_install = slurp_repo_file('xCAT-test/debian/install');
for my $module (@modules) {
(my $dir = $module) =~ s{/[^/]+\z}{};
like($rpm_spec, qr{^cp\s+lib/\Q$module\E\s+\$RPM_BUILD_ROOT/%\{prefix\}/lib/perl/\Q$dir\E/?\s*$}m,
"the RPM installs $module under lib/perl/$dir");
like($debian_install, qr{^lib/\Q$module\E\s+opt/xcat/lib/perl/\Q$dir\E/?\s*$}m,
"the Debian package installs $module under opt/xcat/lib/perl/$dir");
}
done_testing();
+3 -1
View File
@@ -28,9 +28,11 @@ sub run_harness {
# xcattest derives its result directory from the location of the program, so the copy
# under the scratch tree keeps every file the run writes inside that tree.
my $root = tempdir(CLEANUP => 1);
make_path("$root/bin", "$root/cases");
make_path("$root/bin", "$root/cases", "$root/lib/perl/xCAT/Test");
copy($program, "$root/bin/xcattest") or die("copy xcattest: $!");
chmod 0755, "$root/bin/xcattest";
copy("$FindBin::Bin/../lib/xCAT/Test/OS.pm", "$root/lib/perl/xCAT/Test/OS.pm")
or die("copy xCAT/Test/OS.pm: $!");
open(my $case_fh, '>', "$root/cases/fixture") or die("write the fixture case: $!");
print $case_fh $case_text;
+4
View File
@@ -44,6 +44,7 @@ rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/sbin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/man/man1
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/man1
@@ -52,6 +53,9 @@ cp bin/* $RPM_BUILD_ROOT/%{prefix}/bin
cp xcattest $RPM_BUILD_ROOT/%{prefix}/bin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
cp lib/xCAT/Test/OS.pm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test
chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/Test/OS.pm
cp restapitest $RPM_BUILD_ROOT/%{prefix}/sbin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/sbin/*
+5 -23
View File
@@ -12,8 +12,11 @@ use File::Path;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';
my $here = File::Basename::dirname(__FILE__);
unshift @INC, "$here/../lib/perl", "$here/lib";
}
use lib "$::XCATROOT/lib/perl";
use xCAT::Test::OS;
#--------------global attributes----------------
my $program_path = dirname(File::Spec->rel2abs(__FILE__));
@@ -1040,7 +1043,7 @@ sub load_case {
my @newvalidoslist = ();
foreach my $validos (@validoslist) {
if ($validos =~ /linux/i) {
push(@newvalidoslist, ("rhels", "sles", "ubuntu"));
push(@newvalidoslist, xCAT::Test::OS::linux_aliases());
} else {
push(@newvalidoslist, $validos);
}
@@ -1831,28 +1834,7 @@ sub is_valid_case_name {
# Return code:
#--------------------------------------------------------
sub get_current_os {
if (-f "/etc/redhat-release") {
# Try to return "rhels" + major version, if can not get it, just return "rhels"
my $major_version = "";
my @output = &runcmd("cat /etc/redhat-release");
my $out_line = $output[0];
if ($out_line =~ (/(\d+)\.(\d*)/)) {
$major_version = $1;
}
return "rhels".$major_version;
} elsif (-f "/etc/lsb-release") {
return "ubuntu";
} elsif (-f "/etc/os-release") {
my $file="/etc/os-release";
&runcmd("grep -q sles $file");
if ($::RUNCMD_RC == 0) {
return "sles";
}
} elsif (-f "/etc/SuSE-release") {
return "sles";
} else {
return "aix";
}
return xCAT::Test::OS::current_os();
}