From 19242f88c210c9da6c5d6ca042b1cb2ec2bcf8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:12:56 -0300 Subject: [PATCH 1/4] fix(ipmi): report device ID and SDR errors against the node When Get Device ID or a step of the SDR read failed, the plugin reported the error through sendoutput. Seven of these calls passed an array reference, which sendoutput takes as its return code, so the error was dropped. The other five named the node BADCODE. A refused SDR reservation also went on to read records with no reservation ID. Report these errors with sendmsg against the node, as the rest of the plugin does, and stop after a refused reservation. --- xCAT-server/lib/xcat/plugins/ipmi.pm | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index e683d872e9..9081e06921 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -7653,12 +7653,12 @@ sub initsdr_withrepinfo { if ($sessdata->{sdr_info}->{version} != 0x51) { - sendoutput(1, "SDR version unsupported."); + xCAT::SvrUtils::sendmsg([ 1, "SDR version unsupported." ], $callback, $sessdata->{node}, %allerrornodes); return (1); #bail, do not try to continue } if ($sessdata->{sdr_info}->{resv_sdr} != 1) { - sendoutput(1, "SDR reservation unsupported."); + xCAT::SvrUtils::sendmsg([ 1, "SDR reservation unsupported." ], $callback, $sessdata->{node}, %allerrornodes); return 1; } @@ -7695,7 +7695,7 @@ sub start_sdr_record { my $rsp = shift; my $sessdata = shift; if ($rsp->{error}) { - sendoutput(1, $rsp->{error}); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } my $resv_id_ls = shift @{ $sessdata->{sdr_fetch_args} }; @@ -7709,7 +7709,7 @@ sub start_sdr_record { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput(1, $text); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } $sessdata->{sdr_nrid_ls} = $returnd[1]; @@ -7763,7 +7763,7 @@ sub add_sdr_data { my $numbytes = $sessdata->{sdr_fetch_args}->[5]; my $offset = $sessdata->{sdr_offset}; #shorten typing a little if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; #give up } my @returnd = ($rsp->{code}, @{ $rsp->{data} }); @@ -7773,7 +7773,7 @@ sub add_sdr_data { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; #abort the whole mess } push @{ $sessdata->{sdr_data} }, @returnd[ 3 .. @returnd - 1 ]; @@ -7996,7 +7996,7 @@ sub gotdevid { my $text; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8007,7 +8007,7 @@ sub gotdevid { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } } @@ -8093,7 +8093,7 @@ sub got_sdr_rep_info { my $sessdata = shift; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8104,7 +8104,7 @@ sub got_sdr_rep_info { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput(1, $text); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); return; } } @@ -8119,7 +8119,7 @@ sub reserved_sdr_repo { my $rsp = shift; my $sessdata = shift; if ($rsp->{error}) { - sendoutput([ 1, $rsp->{error} ]); + xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes); return; } else { @@ -8130,7 +8130,8 @@ sub reserved_sdr_repo { if (!$text) { $text = sprintf("unknown response %02x", $code); } - sendoutput([ 1, $text ]); + xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); + return; } } my @returnd = @{ $rsp->{data} }; From 0c3640c74f6fa4a73bc77970fd74f7f612639476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:13:04 -0300 Subject: [PATCH 2/4] test(ipmi): cover device ID and SDR errors against the node Each step of the device ID and SDR read reports a timeout as an error of the node and stops, and a refused SDR reservation sends no Get SDR request. --- xCAT-test/unit/ipmi_sdr_errors.t | 131 +++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 xCAT-test/unit/ipmi_sdr_errors.t diff --git a/xCAT-test/unit/ipmi_sdr_errors.t b/xCAT-test/unit/ipmi_sdr_errors.t new file mode 100644 index 0000000000..384f8e00d1 --- /dev/null +++ b/xCAT-test/unit/ipmi_sdr_errors.t @@ -0,0 +1,131 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings) +no warnings qw(once redefine); + +use File::Spec; +use FindBin; +use Test::More; + +# An IPMI command reads the device ID and then the SDR repository before it can answer. +# A failure in that chain must reach the administrator as an error of the node and must end +# the chain, instead of being dropped or reported under no node. + +BEGIN { + for my $module (qw( + xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI + xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils + xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage + xCAT::data::ibmhwtypes xCAT::data::ibmleds + xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents + IBM::EnergyManager + )) { + (my $file = $module) =~ s{::}{/}g; + $INC{"$file.pm"} = __FILE__; + no strict 'refs'; + *{"${module}::import"} = sub { }; + } + + package xCAT::SvrUtils; + our @messages; + sub import { } + sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; } + $INC{'xCAT/SvrUtils.pm'} = __FILE__; + + package xCAT::SPD; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::decode_spd"} = sub { return; }; + } + $INC{'xCAT/SPD.pm'} = __FILE__; + + package File::Path; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::mkpath"} = sub { return; }; + } + $INC{'File/Path.pm'} = __FILE__; + + package Thread; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::yield"} = sub { return; }; + } + $INC{'Thread.pm'} = __FILE__; + + package LWP; + our $VERSION = 5.64; + sub import { } + $INC{'LWP.pm'} = __FILE__; + + package HTTP::Request::Common; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::GET"} = sub { return; }; + *{"${caller}::POST"} = sub { return; }; + } + $INC{'HTTP/Request/Common.pm'} = __FILE__; + + package main; + *CORE::GLOBAL::chmod = sub (@) { return 1; }; +} + +package FakeSession; +sub new { return bless { calls => [] }, shift; } +sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; } + +package main; + +my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..'); +$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server'); +my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm)); +do $plugin or die $@ || "Unable to load $plugin: $!"; + +# Run one callback of the chain with a reply and return what it reported and requested. +sub run_step { + my ($step, $rsp, %state) = @_; + my $sessdata = { node => 'node01', ipmisession => FakeSession->new(), %state }; + local @xCAT::SvrUtils::messages = (); + my $ok = eval { $step->($rsp, $sessdata); 1 }; + return { + died => $ok ? '' : ($@ || 'died'), + messages => [@xCAT::SvrUtils::messages], + requests => $sessdata->{ipmisession}->{calls}, + }; +} + +sub assert_node_error { + my ($result, $text, $case) = @_; + is($result->{died}, '', "$case: the callback returns"); + is(scalar @{ $result->{messages} }, 1, "$case: one message"); + my $message = $result->{messages}->[0] || {}; + is($message->{node}, 'node01', "$case: the message names the node"); + is_deeply($message->{text}, [ 1, $text ], "$case: the message is an error with the reply text"); + is(scalar @{ $result->{requests} }, 0, "$case: the chain stops"); +} + +my $invalid_command = { code => 0xc1, data => [] }; +my $timeout = { error => 'timeout' }; + +for my $step ( + [ 'Get Device ID', \&xCAT_plugin::ipmi::gotdevid ], + [ 'Get SDR Repository Info', \&xCAT_plugin::ipmi::got_sdr_rep_info ], + [ 'Reserve SDR Repository', \&xCAT_plugin::ipmi::reserved_sdr_repo ], + [ 'the first Get SDR', \&xCAT_plugin::ipmi::start_sdr_record ], + [ 'a following Get SDR', \&xCAT_plugin::ipmi::add_sdr_data ], +) { + my ($name, $callback) = @$step; + assert_node_error(run_step($callback, $timeout), 'timeout', "$name times out"); +} + +my $result = run_step(\&xCAT_plugin::ipmi::reserved_sdr_repo, $invalid_command, + sdr_info => { resv_sdr => 1 }); +assert_node_error($result, "Invalid or unsupported command", "a refused SDR reservation"); + +done_testing(); From c6dcdb9b572387621d87de7e1c317bc45344be1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:15:31 -0300 Subject: [PATCH 3/4] fix(ipmi): read the SDR when the BMC grants an unadvertised reservation rinv, rvitals and reventlog stopped with "SDR reservation unsupported." when Get SDR Repository Info did not set the reservation bit. An OpenBMC build clears that bit but grants Reserve SDR Repository, so these commands failed on a server that ipmitool reads. Send Reserve SDR Repository in every case. When the bit is clear and the BMC rejects the command as invalid, the error stays "SDR reservation unsupported." Other refusals report their completion code. --- xCAT-server/lib/xcat/plugins/ipmi.pm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index 9081e06921..d3b450507c 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -7657,11 +7657,7 @@ sub initsdr_withrepinfo { return (1); #bail, do not try to continue } - if ($sessdata->{sdr_info}->{resv_sdr} != 1) { - xCAT::SvrUtils::sendmsg([ 1, "SDR reservation unsupported." ], $callback, $sessdata->{node}, %allerrornodes); - return 1; - } - + # Some BMCs grant a reservation that Get SDR Repository Info does not advertise. $sessdata->{ipmisession}->subcmd(netfn => 0x0a, command => 0x22, data => [], callback => \&reserved_sdr_repo, callback_args => $sessdata); } @@ -8127,7 +8123,9 @@ sub reserved_sdr_repo { if ($code != 0x00) { my $text = $codes{$code}; - if (!$text) { + if ($code == 0xc1 && !$sessdata->{sdr_info}->{resv_sdr}) { + $text = "SDR reservation unsupported."; + } elsif (!$text) { $text = sprintf("unknown response %02x", $code); } xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes); From fd3f1889beb8232d8d87860f4d74b73addd6fc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:16:33 -0300 Subject: [PATCH 4/4] test(ipmi): cover an SDR reservation that is not advertised Replay the Get SDR Repository Info reply of an OpenBMC build that clears the reservation bit. The read asks for the reservation and uses the ID it gets. An invalid command refusal still reports "SDR reservation unsupported." against the node, a busy or privilege refusal reports its completion code, and a BMC that sets the bit is asked as before. --- xCAT-test/unit/ipmi_sdr_reservation.t | 175 ++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 xCAT-test/unit/ipmi_sdr_reservation.t diff --git a/xCAT-test/unit/ipmi_sdr_reservation.t b/xCAT-test/unit/ipmi_sdr_reservation.t new file mode 100644 index 0000000000..df10162695 --- /dev/null +++ b/xCAT-test/unit/ipmi_sdr_reservation.t @@ -0,0 +1,175 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings) +no warnings qw(once redefine); + +use File::Spec; +use FindBin; +use Test::More; + +# Get SDR Repository Info can leave the reservation bit clear on a BMC that grants Reserve +# SDR Repository. The SDR read must still ask for the reservation and use it. + +BEGIN { + for my $module (qw( + xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI + xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils + xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage + xCAT::data::ibmhwtypes xCAT::data::ibmleds + xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents + IBM::EnergyManager + )) { + (my $file = $module) =~ s{::}{/}g; + $INC{"$file.pm"} = __FILE__; + no strict 'refs'; + *{"${module}::import"} = sub { }; + } + + package xCAT::SvrUtils; + our @messages; + sub import { } + sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; } + $INC{'xCAT/SvrUtils.pm'} = __FILE__; + + package xCAT::SPD; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::decode_spd"} = sub { return; }; + } + $INC{'xCAT/SPD.pm'} = __FILE__; + + package File::Path; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::mkpath"} = sub { return; }; + } + $INC{'File/Path.pm'} = __FILE__; + + package Thread; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::yield"} = sub { return; }; + } + $INC{'Thread.pm'} = __FILE__; + + package LWP; + our $VERSION = 5.64; + sub import { } + $INC{'LWP.pm'} = __FILE__; + + package HTTP::Request::Common; + sub import { + my $caller = caller; + no strict 'refs'; + *{"${caller}::GET"} = sub { return; }; + *{"${caller}::POST"} = sub { return; }; + } + $INC{'HTTP/Request/Common.pm'} = __FILE__; + + package main; + *CORE::GLOBAL::chmod = sub (@) { return 1; }; +} + +package FakeSession; +sub new { return bless { calls => [] }, shift; } +sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; } + +package main; + +my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..'); +$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server'); +my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm)); +do $plugin or die $@ || "Unable to load $plugin: $!"; + +# A device identity that no SDR cache file holds, so the SDR is read from the BMC. +sub new_sessdata { + return { + node => 'node01', + ipmisession => FakeSession->new(), + mfg_id => 0xfffe, + prod_id => 0xfffe, + device_id => 0xfe, + device_rev => 0, + firmware_rev1 => 0, + firmware_rev2 => 0, + }; +} + +# The Get SDR Repository Info reply of an OpenBMC that grants reservations, with the +# operation support byte last. +sub repository_info { + my ($operation_support) = @_; + return { code => 0, data => [ 0x51, 0x2b, 0x00, 0xff, 0xff, (0) x 8, $operation_support ] }; +} + +sub requests { return $_[0]->{ipmisession}->{calls}; } + +subtest 'a BMC that does not advertise the reservation is asked for one' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported'); + is(scalar @{ requests($sessdata) }, 1, 'one request follows'); + my $request = requests($sessdata)->[0] || {}; + is($request->{netfn}, 0x0a, 'the request is a storage command'); + is($request->{command}, 0x22, 'the request is Reserve SDR Repository'); + + ok($request->{callback}, "the request has a reply handler") or return; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => 0, data => [ 0x01, 0x00 ] }, $request->{callback_args}); + is_deeply(\@xCAT::SvrUtils::messages, [], 'the granted reservation reports no error'); + my $fetch = requests($sessdata)->[0] || {}; + is($fetch->{command}, 0x23, 'Get SDR follows the reservation'); + is_deeply([ @{ $fetch->{data} || [] }[ 0, 1 ] ], [ 0x01, 0x00 ], + 'Get SDR carries the granted reservation ID'); +}; + +subtest 'a refused reservation that was not advertised is reported as unsupported' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + my $request = requests($sessdata)->[0] || {}; + ok($request->{callback}, "a reservation is requested") or return; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => 0xc1, data => [] }, $request->{callback_args}); + is(scalar @xCAT::SvrUtils::messages, 1, 'one message'); + my $message = $xCAT::SvrUtils::messages[0] || {}; + is($message->{node}, 'node01', 'the message names the node'); + is_deeply($message->{text}, [ 1, 'SDR reservation unsupported.' ], 'the message keeps its text'); + is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows'); +}; + +subtest 'other refusals of a reservation that was not advertised keep their reason' => sub { + for my $refusal ( + [ 0xc0, 'Node busy, command could not be processed' ], + [ 0xd4, 'Insufficient privilege level' ], + ) { + my ($code, $reason) = @$refusal; + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata); + my $request = requests($sessdata)->[0] || {}; + ok($request->{callback}, "a reservation is requested") or next; + $sessdata->{ipmisession}->{calls} = []; + $request->{callback}->({ code => $code, data => [] }, $request->{callback_args}); + is_deeply([ map { $_->{text} } @xCAT::SvrUtils::messages ], [ [ 1, $reason ] ], + sprintf('completion code %02x is reported as itself', $code)); + is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows'); + } +}; + +subtest 'a BMC that advertises the reservation is still asked for one' => sub { + my $sessdata = new_sessdata(); + local @xCAT::SvrUtils::messages = (); + xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x02), $sessdata); + is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported'); + my $request = requests($sessdata)->[0] || {}; + is($request->{command}, 0x22, 'the request is Reserve SDR Repository'); +}; + +done_testing();