From e52acb37993f354c08138714fb87853bb0a94d64 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Wed, 3 Apr 2019 15:59:53 -0400 Subject: [PATCH] Handle openbmc login errors --- xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py | 6 +++++- xCAT-server/lib/xcat/plugins/openbmc.pm | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py index 3b1fffee4..1565418ae 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py @@ -314,8 +314,12 @@ class OpenBMCRest(object): def handle_response (self, resp, cmd=''): - data = resp.json() # it will raise ValueError code = resp.status_code + if code == requests.codes.bad_gateway: + error = "(Verify REST server is running on the BMC)" + self._print_error_log(error, cmd) + raise SelfServerException(code, error, host_and_port=self.bmcip) + data = resp.json() # it will raise ValueError if code != requests.codes.ok: description = ''.join(data['data']['description']) error = '[%d] %s' % (code, description) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index f8f74dc46..f704bf8ae 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -2649,6 +2649,11 @@ sub login_request { xCAT::SvrUtils::sendmsg([1 ,"[" . $login_response->code . "] Login to BMC failed: " . $login_response->status_line . "."], $callback, $node); return 1; } + if ($login_response->code eq 502) { + # Possible reason for 502 code is the REST server not running + xCAT::SvrUtils::sendmsg([1 ,"[" . $login_response->code . "] Login to BMC failed: " . $login_response->status_line . ". Verify REST server is running on the BMC."], $callback, $node); + return 1; + } return 0; } @@ -2950,9 +2955,10 @@ sub rpower_response { retry_after($node, $next_status{ $node_info{$node}{cur_status} }{OFF}, $::RPOWER_CHECK_ON_INTERVAL); return; } else { - #after retry 5 times, the host is still off, print error and return + # if after 5 retries, the host is still off, print error and return my $wait_time_X = $node_info{$node}{wait_on_end} - $node_info{$node}{wait_on_start}; xCAT::SvrUtils::sendmsg([1, "Sent power-on command but state did not change to $::POWER_STATE_ON after waiting $wait_time_X seconds. (State=$all_status)."], $callback, $node); + xCAT::SvrUtils::sendmsg([1, "Run 'reventlog' command to see possible reasons for failure."], $callback, $node); $node_info{$node}{cur_status} = ""; $wait_node_num--; return;