mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-28 21:32:20 +00:00
Merge pull request #8000 from VersatusHPC/fix/ipmi-sdr-reservation
fix(ipmi): read the SDR when the BMC grants an unadvertised reservation
This commit is contained in:
@@ -7653,15 +7653,11 @@ 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.");
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -7695,7 +7691,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 +7705,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 +7759,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 +7769,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 +7992,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 +8003,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 +8089,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 +8100,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 +8115,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 {
|
||||
@@ -8127,10 +8123,13 @@ 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);
|
||||
}
|
||||
sendoutput([ 1, $text ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
my @returnd = @{ $rsp->{data} };
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user