2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-20 17:32:15 +00:00
Files
xcat-core/xCAT-test/unit/runxcmd_subrequest_errorcode.t
T
Daniel Hilst b999334d1a test(xcat-core): a nodeset subrequest reports a command it never ran
rinstall prints "Failed to run 'nodeset' against the node" while nodeset
succeeds and reports no error. xCAT::Utils::runxcmd returns $::RUNCMD_RC, and
xCAT::Utils::runcmd and the service helpers of every plugin inside the
subrequest assign to that global, so the status of the last command of the
subrequest becomes the status of the subrequest. makedhcp supplies that
command: the ISC branch restarts dhcpd6 whenever /etc/dhcp/dhcpd6.conf is
absent or foreign, which is every run of a cluster with no IPv6 network, and
the restart fails because dhcpd6 has no subnet to serve.

runxcmd_subrequest_errorcode.t holds the result of a subrequest to the
errorcode of its responses. dhcp_isc_dhcp6_restart.t holds the restart of
dhcpd6 to a run that serves an IPv6 network. The condition moves out of
dhcp.pm into xCAT::DHCP::Backend::ISC unchanged, so that a test can read it.

Against this tree the first test fails 3 of its 5 assertions and the second
fails 1 of its 4.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-11-07 07:18:31 -03:00

67 lines
2.3 KiB
Perl

#!/usr/bin/env perl
# The result of an internal subrequest is the errorcode of its responses. A plugin of the
# subrequest runs commands of its own, and xCAT::Utils::runcmd and the service helpers write
# the exit status of each one to $::RUNCMD_RC, so a caller that reads that global after the
# subrequest can read a command it never asked for.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
# xCAT::Utils puts $XCATROOT/lib/perl in front of @INC. On a host with xCAT installed that is
# the installed product, so point it at the checkout under test.
BEGIN { $ENV{XCATROOT} = "$FindBin::Bin/../../xCAT-server" }
use Test::More;
use xCAT::Utils;
my $request = { command => ['nodeset'], node => ['node1'], arg => ['osimage'] };
# makedhcp restarts dhcpd6 through xCAT::Utils::restartservice, which assigns the exit status
# of the restart to $::RUNCMD_RC. The stub writes the same value without running a command.
sub leftover_status {
my ($status) = @_;
return sub {
my ( $req, $cb ) = @_;
$cb->({ node => [ { name => ['node1'], data => ['netboot alma8.10-x86_64-compute'] } ] });
$::RUNCMD_RC = $status;
return;
};
}
my $output = xCAT::Utils->runxcmd( $request, leftover_status(256), -1, 1 );
is( $::RUNCMD_RC, 0,
'a subrequest whose responses carry no errorcode reports 0, whatever its commands returned' );
is_deeply( $output, ['node1: netboot alma8.10-x86_64-compute'],
'the node response still reaches the caller' );
xCAT::Utils->runxcmd(
$request,
sub {
my ( $req, $cb ) = @_;
$cb->({ node => [ { name => ['node1'], error => ['no MAC address available'], errorcode => [1] } ] });
return;
},
-1, 1
);
is( $::RUNCMD_RC, 1, 'the errorcode of a node response reaches the caller' );
xCAT::Utils->runxcmd(
$request,
sub {
my ( $req, $cb ) = @_;
$cb->({ error => ['unknown state requested'], errorcode => [2] });
$::RUNCMD_RC = 0;
return;
},
-1, 1
);
is( $::RUNCMD_RC, 2, 'a response errorcode survives a command that returned 0' );
# The hash form, which runxcmd collects with runxcmd_output2.
my $hash = xCAT::Utils->runxcmd( $request, leftover_status(1), -1, 2 );
is( $::RUNCMD_RC, 0, 'the hash form reports 0 for a subrequest that reported no error' );
done_testing();