From 7fe2244d9dc6f2b7a509a00bec7aa3770ad0a135 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 23 Jul 2026 09:14:03 -0300 Subject: [PATCH] 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> (cherry picked from commit a0d2322b71692a058aa57a12f61cdfd4e73ef3bb) --- github_action_xcat_test.pl | 43 +++++++++++++++++++ xCAT-test/autotest/testcase/dhcp_unit/cases0 | 8 ---- xCAT-test/autotest/testcase/ipmi_unit/cases0 | 8 ---- .../autotest/testcase/xcatprobe_unit/cases0 | 8 ---- xCAT-test/unit/ubuntu_subiquity_template.t | 5 ++- 5 files changed, 46 insertions(+), 26 deletions(-) delete mode 100644 xCAT-test/autotest/testcase/dhcp_unit/cases0 delete mode 100644 xCAT-test/autotest/testcase/ipmi_unit/cases0 delete mode 100644 xCAT-test/autotest/testcase/xcatprobe_unit/cases0 diff --git a/github_action_xcat_test.pl b/github_action_xcat_test.pl index ec78b8f0d..fb915964e 100644 --- a/github_action_xcat_test.pl +++ b/github_action_xcat_test.pl @@ -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(); diff --git a/xCAT-test/autotest/testcase/dhcp_unit/cases0 b/xCAT-test/autotest/testcase/dhcp_unit/cases0 deleted file mode 100644 index b95fe7e68..000000000 --- a/xCAT-test/autotest/testcase/dhcp_unit/cases0 +++ /dev/null @@ -1,8 +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 diff --git a/xCAT-test/autotest/testcase/ipmi_unit/cases0 b/xCAT-test/autotest/testcase/ipmi_unit/cases0 deleted file mode 100644 index 1d3448314..000000000 --- a/xCAT-test/autotest/testcase/ipmi_unit/cases0 +++ /dev/null @@ -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 diff --git a/xCAT-test/autotest/testcase/xcatprobe_unit/cases0 b/xCAT-test/autotest/testcase/xcatprobe_unit/cases0 deleted file mode 100644 index 17f15982e..000000000 --- a/xCAT-test/autotest/testcase/xcatprobe_unit/cases0 +++ /dev/null @@ -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 diff --git a/xCAT-test/unit/ubuntu_subiquity_template.t b/xCAT-test/unit/ubuntu_subiquity_template.t index a06ba2ae2..2af9692aa 100644 --- a/xCAT-test/unit/ubuntu_subiquity_template.t +++ b/xCAT-test/unit/ubuntu_subiquity_template.t @@ -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');