From fd8ba44039dbfa85bc686de1e895ff2917dfce33 Mon Sep 17 00:00:00 2001 From: XuWei Date: Thu, 16 Nov 2017 03:44:04 -0500 Subject: [PATCH 1/2] Modify timeout of login by curl command for OpenBMC --- 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 059fc1115..1c36378d3 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -591,7 +591,7 @@ sub process_request { foreach my $node (keys %node_info) { if (!$valid_nodes{$node}) { - xCAT::SvrUtils::sendmsg([1, "BMC did not respond within 10 seconds, retry the command."], $callback, $node); + xCAT::SvrUtils::sendmsg([1, "BMC could not be connected or did not respond within 20 seconds, retry the command."], $callback, $node); $wait_node_num--; } else { $login_url = "$http_protocol://$node_info{$node}{bmc}/login"; @@ -1566,7 +1566,7 @@ sub login_logout_request { my $curl_login_cmd = "curl -c $cjar_id -k -H 'Content-Type: application/json' -X POST $request_url/login -d '" . $content_login . "'"; my $curl_logout_cmd = "curl -b $cjar_id -k -H 'Content-Type: application/json' -X POST $request_url/logout -d '" . $content_logout . "'"; - my $curl_login_result = `$curl_login_cmd -s -m 10`; + my $curl_login_result = `$curl_login_cmd -s -m 20`; unless ($curl_login_result) { if ($xcatdebugmode) { From 5ae2aadc5f365b51d7ecf35614a043e6a92fce2e Mon Sep 17 00:00:00 2001 From: XuWei Date: Thu, 16 Nov 2017 19:44:37 -0500 Subject: [PATCH 2/2] modified depending on comments --- xCAT-server/lib/xcat/plugins/openbmc.pm | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 1c36378d3..8fe6dbdbe 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -18,6 +18,7 @@ use warnings "all"; use JSON; use HTTP::Async; use HTTP::Cookies; +use LWP::UserAgent; use File::Basename; use File::Spec; use File::Copy qw/copy cp mv move/; @@ -591,7 +592,7 @@ sub process_request { foreach my $node (keys %node_info) { if (!$valid_nodes{$node}) { - xCAT::SvrUtils::sendmsg([1, "BMC could not be connected or did not respond within 20 seconds, retry the command."], $callback, $node); + xCAT::SvrUtils::sendmsg([1, "BMC did not respond. Verify BMC is in BMCReady state and retry the command."], $callback, $node); $wait_node_num--; } else { $login_url = "$http_protocol://$node_info{$node}{bmc}/login"; @@ -1558,24 +1559,23 @@ sub process_debug_info { sub login_logout_request { my $node = shift; - my $request_url = "$http_protocol://" . $node_info{$node}{bmc}; - my $content_login = '{ "data": [ "' . $node_info{$node}{username} .'", "' . $node_info{$node}{password} . '" ] }'; - my $content_logout = '{ "data": [ ] }'; - my $cjar_id = "/tmp/_xcat_cjar.$node"; + my $login_url = "$http_protocol://" . $node_info{$node}{bmc} . "/login"; + my $data = '{ "data": [ "' . $node_info{$node}{username} .'", "' . $node_info{$node}{password} . '" ] }'; - my $curl_login_cmd = "curl -c $cjar_id -k -H 'Content-Type: application/json' -X POST $request_url/login -d '" . $content_login . "'"; - my $curl_logout_cmd = "curl -b $cjar_id -k -H 'Content-Type: application/json' -X POST $request_url/logout -d '" . $content_logout . "'"; + my $brower = LWP::UserAgent->new( ssl_opts => { SSL_verify_mode => 0x00, verify_hostname => 0 }, timeout => 20); + my $cookie_jar = HTTP::Cookies->new(); + my $header = HTTP::Headers->new('Content-Type' => 'application/json'); + $brower->cookie_jar($cookie_jar); - my $curl_login_result = `$curl_login_cmd -s -m 20`; + my $login_request = HTTP::Request->new( 'POST', $login_url, $header, $data ); + my $login_response = $brower->request($login_request); - unless ($curl_login_result) { + if ($login_response->status_line =~ /500 Can't connect to/ or $login_response->status_line =~ /500 read timeout/) { if ($xcatdebugmode) { my $debug_info = "LOGIN Failed using curl command"; process_debug_info($node, $debug_info); } return 1; - } else { - my $curl_logout_result = `$curl_logout_cmd -s`; } return 0;