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

Verify hash ID

This commit is contained in:
Mark Gurevich 2017-11-16 13:37:16 -05:00
parent b1b310b302
commit 8ecd711c3d

View File

@ -50,6 +50,7 @@ $::POWER_STATE_RESET = "reset";
$::POWER_STATE_REBOOT = "reboot";
$::UPLOAD_FILE = "";
$::UPLOAD_FILE_VERSION = "";
$::UPLOAD_FILE_HASH_ID = "";
$::RSETBOOT_URL_PATH = "boot";
# To improve the output to users, store this value as a global
$::UPLOAD_AND_ACTIVATE = 0;
@ -1127,6 +1128,8 @@ sub parse_command_status {
my $file_id = undef;
my $grep_cmd = "/usr/bin/grep -a";
my $tr_cmd = "/usr/bin/tr";
my $sha512sum_cmd = "/usr/bin/sha512sum";
my $version_tag = '"^version="';
my $purpose_tag = '"purpose="';
my $purpose_value;
@ -1166,6 +1169,11 @@ sub parse_command_status {
$purpose_value = "Host";
}
$::UPLOAD_FILE_VERSION = $version_value;
if (-x $sha512sum_cmd) {
# Save hash id this firmware version should resolve to:
# take version string, get rid of newline, run through sha512sum, take first 8 characters
$::UPLOAD_FILE_HASH_ID = substr(`echo $::UPLOAD_FILE_VERSION | $tr_cmd -d '\n' | $sha512sum_cmd`, 0,8);
}
}
if ($check_version) {
@ -2607,6 +2615,12 @@ sub rflash_response {
$found_match = 1;
# Found a match of uploaded file version with the image in software/enumerate
# If we have a saved expected hash ID, compare it to the one just found
if ($::UPLOAD_FILE_HASH_ID && ($::UPLOAD_FILE_HASH_ID ne $update_id)) {
xCAT::SvrUtils::sendmsg([1,"Firmware uploaded, but not activated. ID $update_id did not match expected ID $::UPLOAD_FILE_HASH_ID "], $callback, $node);
$wait_node_num--;
return; # Stop processing for this node, do not activate. Firmware shold be left in "Ready" state.
}
# Set the image id for the activation request
$status_info{RFLASH_UPDATE_ACTIVATE_REQUEST}{init_url} =
$::SOFTWARE_URL . "/$update_id/attr/RequestedActivation";