2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-29 09:13:08 +00:00

Add support to resolve OpenBMC logging events to clear out faults

This commit is contained in:
Victor Hu 2017-12-20 14:36:41 -05:00
parent 9f9e406861
commit ba964c819c

View File

@ -93,6 +93,11 @@ unless (-d $::XCAT_LOG_DUMP_DIR) {
mkpath($::XCAT_LOG_DUMP_DIR);
}
# Common logging messages:
my $usage_errormsg = "Usage error.";
my $reventlog_no_id_resolved_errormsg = "Provide a comma separated list of IDs to resolved. Example: 'resolved=x,y,z'";
sub unsupported {
my $callback = shift;
if (defined($::OPENBMC_DEVEL) && ($::OPENBMC_DEVEL eq "YES")) {
@ -144,6 +149,7 @@ my $http_protocol="https";
my $openbmc_url = "/org/openbmc";
my $openbmc_project_url = "/xyz/openbmc_project";
$::SOFTWARE_URL = "$openbmc_project_url/software";
$::LOGGING_URL = "$openbmc_project_url/logging";
#-------------------------------------------------------
# The hash table to store method and url for request,
@ -197,6 +203,14 @@ my %status_info = (
REVENTLOG_CLEAR_RESPONSE => {
process => \&reventlog_response,
},
REVENTLOG_RESOLVED_REQUEST => {
method => "PUT",
init_url => "$::LOGGING_URL",
data => "1",
},
REVENTLOG_RESOLVED_RESPONSE => {
process => \&reventlog_response,
},
RFLASH_LIST_REQUEST => {
method => "GET",
@ -1021,6 +1035,9 @@ sub parse_args {
my $option_s;
GetOptions( 's' => \$option_s );
return ([ 1, "The -s option is not supported for OpenBMC." ]) if ($option_s);
if ( "resolved" ~~ @ARGV) {
return ([ 1, "$usage_errormsg $reventlog_no_id_resolved_errormsg" ]);
}
return ([ 1, "Only one option is supported at the same time for $command" ]);
} elsif (scalar(@ARGV) == 0 and $command =~ /rpower|rspconfig|rflash/) {
@ -1050,8 +1067,32 @@ sub parse_args {
return ([ 1, "Unsupported command: $command $subcommand" ]);
}
} elsif ($command eq "reventlog") {
#
# TODO, resolved should NOT be supported if range is provided
#
$subcommand = "all" if (!defined($ARGV[0]));
unless ($subcommand =~ /^\d$|^\d+$|^all$|^clear$/) {
if ($subcommand =~ /^(\w+)=(.*)/) {
my $key = $1;
my $value = $2;
if (not $value) {
return ([ 1, "$usage_errormsg $reventlog_no_id_resolved_errormsg" ]);
}
xCAT::SvrUtils::sendmsg("Attempting to resolve the following log entries: $value...", $callback);
my @entries = split(',', $value);
# take the first element from the list
my $log_id = shift @entries;
# and set the URL for the loggin entry to resolved
$status_info{REVENTLOG_RESOLVED_REQUEST}{init_url} = $::LOGGING_URL . "/entry/$log_id/attr/Resolved";
# If a list is provided, set the remaining log entries back to status_info
my $remaining = join (',', @entries);
$status_info{REVENTLOG_RESOLVED_REQUEST}{argv} = $remaining;
} elsif ($subcommand !~ /^\d$|^\d+$|^all$|^clear$/) {
if ($subcommand =~ "resolved") {
return ([ 1, "$usage_errormsg $reventlog_no_id_resolved_errormsg" ]);
}
return ([ 1, "Unsupported command: $command $subcommand" ]);
}
} elsif ($command eq "rspconfig") {
@ -1431,6 +1472,9 @@ sub parse_command_status {
if ($subcommand eq "clear") {
$next_status{LOGIN_RESPONSE} = "REVENTLOG_CLEAR_REQUEST";
$next_status{REVENTLOG_CLEAR_REQUEST} = "REVENTLOG_CLEAR_RESPONSE";
} elsif ($subcommand =~"resolved") {
$next_status{LOGIN_RESPONSE} = "REVENTLOG_RESOLVED_REQUEST";
$next_status{REVENTLOG_RESOLVED_REQUEST} = "REVENTLOG_RESOLVED_RESPONSE";
} else {
$next_status{LOGIN_RESPONSE} = "REVENTLOG_REQUEST";
$next_status{REVENTLOG_REQUEST} = "REVENTLOG_RESPONSE";
@ -2005,7 +2049,7 @@ sub parse_node_info {
next;
}
unless($node_info{$node}{bmcip}) {
xCAT::SvrUtils::sendmsg("Error: Unable to resolve ip address for bmc: $node_info{$node}{bmc}", $callback, $node);
xCAT::SvrUtils::sendmsg("Error: Unable to resolved ip address for bmc: $node_info{$node}{bmc}", $callback, $node);
delete $node_info{$node};
$rst = 1;
next;
@ -2162,18 +2206,21 @@ sub deal_with_response {
if ($node_info{$node}{cur_status} eq "RPOWER_BMC_STATUS_RESPONSE" and defined $status_info{RPOWER_BMC_STATUS_RESPONSE}{argv} and $status_info{RPOWER_BMC_STATUS_RESPONSE}{argv} =~ /bmcstate$/) {
retry_check_times($node, "RPOWER_BMC_STATUS_REQUEST", "bmc_conn_check_times", $::BMC_CHECK_INTERVAL, $response->status_line);
return;
}
}
if ($response->status_line eq $::RESPONSE_SERVICE_UNAVAILABLE) {
$error = $::RESPONSE_SERVICE_UNAVAILABLE;
} elsif ($response->status_line eq $::RESPONSE_METHOD_NOT_ALLOWED) {
# Special processing for file upload. At this point we do not know how to
# form a proper file upload request. It always fails with "Method not allowed" error.
# If that happens, just assume it worked.
# TODO remove this block when proper request can be generated
$status_info{ $node_info{$node}{cur_status} }->{process}->($node, $response);
return;
if ($node_info{$node}{cur_status} eq "REVENTLOG_RESOLVED_RESPONSE") {
$error = "Could not find ID specified.";
} else {
# Special processing for file upload. At this point we do not know how to
# form a proper file upload request. It always fails with "Method not allowed" error.
# If that happens, just assume it worked.
# TODO remove this block when proper request can be generated
$status_info{ $node_info{$node}{cur_status} }->{process}->($node, $response);
return;
}
} elsif ($response->status_line eq $::RESPONSE_SERVICE_TIMEOUT) {
if ($node_info{$node}{cur_status} eq "RPOWER_RESET_RESPONSE" and defined $status_info{RPOWER_RESET_RESPONSE}{argv} and $status_info{RPOWER_RESET_RESPONSE}{argv} =~ /bmcreboot$/) {
my $infomsg = "BMC $::POWER_STATE_REBOOT";
@ -2198,7 +2245,10 @@ sub deal_with_response {
} elsif ($node_info{$node}{cur_status} eq "RSETBOOT_ENABLE_RESPONSE" ) {
# If 403 is received setting boot method, API endpoint changed in 1738 FW, inform the user of work around.
$error = "Invalid endpoint used to set boot method. If running firmware < ibm-v1.99.10-0-r7, 'export XCAT_OPENBMC_FIRMWARE=1736' and retry.";
} else {
} elsif ($node_info{$node}{cur_status} eq "REVENTLOG_RESOLVED_RESPONSE") {
my $log_id = (split ('/', $status_info{REVENTLOG_RESOLVED_REQUEST}{init_url}))[5];
$error = "Invalid ID=$log_id provided to resolved. [$::RESPONSE_FORBIDDEN]";
} else{
$error = "$::RESPONSE_FORBIDDEN - Requested endpoint does not exists and may indicate function is not yet supported by OpenBMC firmware.";
}
# Handle 404
@ -2830,7 +2880,24 @@ sub reventlog_response {
if ($node_info{$node}{cur_status} eq "REVENTLOG_CLEAR_RESPONSE") {
if ($response_info->{'message'} eq $::RESPONSE_OK) {
xCAT::SvrUtils::sendmsg("clear", $callback, $node);
xCAT::SvrUtils::sendmsg("Logs cleared", $callback, $node);
}
} elsif ($node_info{$node}{cur_status} eq "REVENTLOG_RESOLVED_RESPONSE") {
if ($response_info->{'message'} eq $::RESPONSE_OK) {
my $log_id = (split ('/', $status_info{REVENTLOG_RESOLVED_REQUEST}{init_url}))[5];
xCAT::SvrUtils::sendmsg("Resolved $log_id.", $callback, $node);
}
my @entries = split (',', $status_info{REVENTLOG_RESOLVED_REQUEST}{argv} );
if (@entries) {
my $log_id = shift @entries;
$next_status{"REVENTLOG_RESOLVED_RESPONSE"} = "REVENTLOG_RESOLVED_REQUEST";
$next_status{"REVENTLOG_RESOLVED_REQUEST"} = "REVENTLOG_RESOLVED_RESPONSE";
$status_info{REVENTLOG_RESOLVED_REQUEST}{init_url} =
$::LOGGING_URL . "/entry/$log_id/attr/Resolved";
# If a list is provided, set the remaining log entries back to status_info
my $remaining = join (',', @entries);
$status_info{REVENTLOG_RESOLVED_REQUEST}{argv} = $remaining;
}
} else {
my $entry_string = $status_info{REVENTLOG_RESPONSE}{argv};