From 5bf6e1dc83fe579a4a9d12a4e70ae8d9ece32552 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Sat, 2 Dec 2017 22:49:45 -0500 Subject: [PATCH 1/3] Improve the message on the HTTP response --- xCAT-server/lib/xcat/plugins/openbmc.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 093ff906e..75f1d00d5 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1752,8 +1752,10 @@ sub deal_with_response { $error = $::RESPONSE_SERVICE_TIMEOUT; } else { my $response_info = decode_json $response->content; + # Handle 500 if ($response->status_line eq $::RESPONSE_SERVER_ERROR) { - $error = $response_info->{'data'}->{'exception'}; + $error = "[" . $response->code . "] " . $response_info->{'data'}->{'exception'}; + # Handle 403 } elsif ($response->status_line eq $::RESPONSE_FORBIDDEN) { # # For any invalid data that we can detect, provide a better response message @@ -1764,21 +1766,21 @@ 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 { $error = "$::RESPONSE_FORBIDDEN - Requested endpoint does not exists and may indicate function is not yet supported by OpenBMC firmware."; } - } elsif ($response_info->{'data'}->{'description'} =~ /path or object not found: (.+)/) { + # Handle 404 + } elsif ($response->status_line eq $::RESPONSE_NOT_FOUND) { # # For any invalid data that we can detect, provide a better response message # if ($node_info{$node}{cur_status} eq "RFLASH_DELETE_IMAGE_RESPONSE") { $error = "Invalid ID provided to delete. Use the -l option to view valid firmware IDs."; } else { - $error = "Path or object not found: $1"; + $error = "[" . $response->code . "] Path or object not found: $1"; } } else { - $error = $response_info->{'data'}->{'description'}; + $error = "[" . $response->code . "] " . $response_info->{'data'}->{'description'}; } } xCAT::SvrUtils::sendmsg([1, $error], $callback, $node); @@ -1852,7 +1854,7 @@ sub login_request { # Check the return code if ($login_response->code != 200) { # handle the errors generically - xCAT::SvrUtils::sendmsg([1 ,"Login to BMC failed. Status: " . $login_response->status_line . "."], $callback, $node); + xCAT::SvrUtils::sendmsg([1 ,"[" . $login_response->code . "] Login to BMC failed: " . $login_response->status_line . "."], $callback, $node); return 1; } From c29d0c960a4a1adef43c55948ed32fdb1b4e5c31 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Sun, 3 Dec 2017 23:34:52 -0500 Subject: [PATCH 2/3] Only handle 404 and 504 in the login request code, defer the rest to deal_with_response() --- xCAT-server/lib/xcat/plugins/openbmc.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 75f1d00d5..00c837fb2 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1852,8 +1852,8 @@ sub login_request { my $login_response = $brower->request($login_request); # Check the return code - if ($login_response->code != 200) { - # handle the errors generically + if ($login_response->code eq 500 or $login_response->code eq 404) { + # handle only 404 and 504 in this code, defer to deal_with_response for the rest xCAT::SvrUtils::sendmsg([1 ,"[" . $login_response->code . "] Login to BMC failed: " . $login_response->status_line . "."], $callback, $node); return 1; } From 22692d27648b995d885318f3cd664ac7541a1437 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 5 Dec 2017 22:32:35 -0500 Subject: [PATCH 3/3] Update the print out based on the review comment, should not use since the regular expression is removed --- xCAT-server/lib/xcat/plugins/openbmc.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 00c837fb2..d841c7d6b 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1777,7 +1777,7 @@ sub deal_with_response { if ($node_info{$node}{cur_status} eq "RFLASH_DELETE_IMAGE_RESPONSE") { $error = "Invalid ID provided to delete. Use the -l option to view valid firmware IDs."; } else { - $error = "[" . $response->code . "] Path or object not found: $1"; + $error = "[" . $response->code . "] " . $response_info->{'data'}->{'description'}; } } else { $error = "[" . $response->code . "] " . $response_info->{'data'}->{'description'};