2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-07-31 18:19:40 +00:00

fix(xcat-core): run every xCAT-test unit test in the GitHub CI

The 47 test files under xCAT-test/unit/ were shipped but almost never
executed on a pull request. Only three hand-written xcattest cases
reached them -- dhcp_unit, ipmi_unit and xcatprobe_unit -- and each
proved a single glob against the installed copy, so the majority of the
suite had never run at all. Real drift went unnoticed as a result:
ubuntu_subiquity_template.t still asserted the pre-86e77bcd7 shape of
compute.subiquity.tmpl and failed against the current template.

Run `prove xCAT-test/unit/*.t` directly from github_action_xcat_test.pl.
The tests resolve xCAT modules and fixture files relative to the repo
root through FindBin, so they must be proved from the checkout and not
from /opt/xcat/share/xcat/tools/autotest/unit; install_xcat() chdir's
away, hence the getcwd() captured up front. The step runs after the
install because the suite needs the perl dependencies xCAT pulls in
(Net::DNS, XML::Simple) and a usable xCAT database.

Drop the three prove testcases so their tests do not run twice, and
refresh the two stale ubuntu_subiquity_template.t assertions: the
identity section is now intentional (86e77bcd7) and the MAC
normalization gained cut filters ahead of the tr (c6e38483f), which the
loosened regex plus a new assertion for the suffix stripping now cover.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-07-23 09:14:03 -03:00
parent cf44f51463
commit a0d2322b71
5 changed files with 46 additions and 35 deletions
+43
View File
@@ -27,6 +27,11 @@ my $check_result_str="``CI CHECK RESULT`` : ";
my $last_func_start = timelocal(localtime());
my $GITHUB_API = "https://api.github.com";
# The workflow starts us in the checked out source tree, but install_xcat()
# chdir's away from it. Remember the checkout up front: the unit tests under
# xCAT-test/unit resolve xCAT modules and fixture files relative to it.
my $srcdir = getcwd();
#--------------------------------------------------------
# Fuction name: runcmd
# Description: run a command after 'cmd' label in one case
@@ -384,6 +389,34 @@ sub install_xcat{
}
#--------------------------------------------------------
# Fuction name: run_unit_tests
# Description: Run every Perl unit test under xCAT-test/unit with prove.
# The tests are source tree tests: they pull xCAT modules and
# fixture files out of the checkout through FindBin, so they
# have to be proved from the checkout root rather than from the
# copy installed under /opt/xcat/share/xcat/tools/autotest.
# Attributes:
# Return code: 0 all tests passed, 1 otherwise
#--------------------------------------------------------
sub run_unit_tests{
my $cmd = "cd $srcdir && prove xCAT-test/unit/*.t";
print "[run_unit_tests] running $cmd\n";
my @output = runcmd("$cmd");
print Dumper \@output;
if($::RUNCMD_RC){
print RED "[run_unit_tests] $cmd ....[Failed]\n";
$check_result_str .= "> **UNIT TESTS Failed** : Please click ``Details`` label in ``Merge pull request`` box for detailed information\n";
print $check_result_str;
return 1;
}
print "[run_unit_tests] $cmd ....[Pass]\n";
$check_result_str .= "> **UNIT TESTS Successful**\n";
print $check_result_str;
return 0;
}
#--------------------------------------------------------
# Fuction name: check_syntax
# Description:
@@ -583,6 +616,16 @@ if($rst){
}
mark_time("install_xcat");
#Run the xCAT-test unit tests. They need the perl dependencies xCAT pulls in
#(Net::DNS, XML::Simple) and a usable xCAT database, so they run after install.
print GREEN "\n------Running xCAT-test unit tests ------\n";
$rst = run_unit_tests();
if($rst){
print RED "Run of xCAT-test unit tests failed\n";
exit $rst;
}
mark_time("run_unit_tests");
#Check the syntax of changing code
print GREEN "\n------ Checking the syntax of changed code------\n";
$rst = check_syntax();
@@ -1,17 +0,0 @@
start:dhcp_backend_unit_tests
description:Run the DHCP backend Perl unit tests through xcattest
os:Linux
label:mn_only,ci_test,dhcp,unit,dhcp_unit
cmd:prove -I/opt/xcat/lib/perl -I/opt/xcat/lib/perl/xCAT /opt/xcat/share/xcat/tools/autotest/unit/dhcp_*.t
check:rc==0
check:output=~All tests successful
end
start:ddns_omapi_policy_unit_tests
description:Run the DDNS OMAPI policy Perl unit test through xcattest
os:Linux
label:mn_only,ci_test,dhcp,dns,unit,ddns_unit
cmd:prove -I/opt/xcat/lib/perl -I/opt/xcat/lib/perl/xCAT /opt/xcat/share/xcat/tools/autotest/unit/ddns_omapi_policy.t
check:rc==0
check:output=~All tests successful
end
@@ -1,8 +0,0 @@
start:ipmi_rakp2_unit_tests
description:Run the IPMI RAKP2 Perl unit tests through xcattest
os:Linux
label:mn_only,ci_test,ipmi,unit,ipmi_unit
cmd:prove -I/opt/xcat/lib/perl -I/opt/xcat/lib/perl/xCAT /opt/xcat/share/xcat/tools/autotest/unit/ipmi_*.t
check:rc==0
check:output=~All tests successful
end
@@ -1,8 +0,0 @@
start:xcatprobe_tcp_listener_unit_tests
description:Run the xCAT probe TCP listener Perl unit tests through xcattest
os:Linux
label:mn_only,ci_test,xcatprobe,unit,xcatprobe_unit
cmd:prove -I/opt/xcat/probe/lib/perl /opt/xcat/share/xcat/tools/autotest/unit/probe_utils_tcp_listener.t
check:rc==0
check:output=~All tests successful
end
+3 -2
View File
@@ -15,7 +15,7 @@ like($tmpl, qr/^#cloud-config/, 'template starts with #cloud-config');
like($tmpl, qr/autoinstall:/, 'template has autoinstall: key');
like($tmpl, qr/version:\s*1/, 'template has version: 1');
unlike($tmpl, qr/^\s*identity:/m, 'template must not have identity section (use user-data instead)');
like($tmpl, qr/^\s*identity:/m, 'template has an identity section so subiquity does not prompt');
like($tmpl, qr/kernel:/, 'template has kernel section');
like($tmpl, qr/package:\s*linux-generic/, 'template specifies linux-generic kernel');
like($tmpl, qr/#UBUNTU_SUBIQUITY_APT_CONFIG#/, 'template renders apt section from osimage context');
@@ -38,7 +38,8 @@ like($tmpl, qr/printf ''%s\\n'' ''GRUB_CMDLINE_LINUX="#TABLEBLANKOKAY:bootparams
like($tmpl, qr/\/target\/etc\/netplan\/00-xcat-install\.yaml/, 'template writes an xCAT-owned target netplan file');
like($tmpl, qr/installnic="#TABLE:noderes:\$NODE:installnic#"/, 'target netplan uses node installnic');
like($tmpl, qr/installmac="#TABLE:mac:\$NODE:mac#"/, 'target netplan uses node MAC');
like($tmpl, qr/installmac="\$\(printf ''%s'' "\$\{installmac\}" \| tr ''A-F'' ''a-f''\)"/, 'target netplan normalizes MAC case');
like($tmpl, qr/installmac="\$\(printf ''%s'' "\$\{installmac\}".*\| tr ''A-F'' ''a-f''\)"/, 'target netplan normalizes MAC case');
like($tmpl, qr/installmac="\$\(printf ''%s'' "\$\{installmac\}" \| cut -d''\|'' -f1 \| cut -d''!'' -f1/, 'target netplan strips mac table suffixes before matching');
like($tmpl, qr/printf ''%s\\n'' "network:" " version: 2" " ethernets:" " xcat-install:" " match:" " macaddress: \\"\$\{installmac\}\\"" " set-name: \$\{installnic\}" " dhcp4: true" >\/target\/etc\/netplan\/00-xcat-install\.yaml;/, 'target netplan printf stays on one shell line');
like($tmpl, qr/" macaddress: \\"\$\{installmac\}\\""/, 'target netplan matches by MAC address');
like($tmpl, qr/" set-name: \$\{installnic\}"/, 'target netplan sets the expected installnic name');