From 071f336c17b2cb78a2d817848c0d90b5d2bd7a47 Mon Sep 17 00:00:00 2001 From: chenglch Date: Fri, 17 Nov 2017 14:12:12 +0800 Subject: [PATCH] Fix some bus in makegocons --- xCAT-server/lib/perl/xCAT/Goconserver.pm | 14 +++++++---- xCAT-server/lib/xcat/plugins/goconserver.pm | 28 ++++++++++----------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Goconserver.pm b/xCAT-server/lib/perl/xCAT/Goconserver.pm index 0fc6032ae..fc83206dd 100644 --- a/xCAT-server/lib/perl/xCAT/Goconserver.pm +++ b/xCAT-server/lib/perl/xCAT/Goconserver.pm @@ -47,13 +47,14 @@ sub delete_nodes { my ($api_url, $node_map, $delmode, $callback) = @_; my $url = "$api_url/bulk/nodes"; my @a = (); - my ($data, $rsp); + my ($data, $rsp, $ret); $data->{nodes} = \@a; foreach my $node (keys %{$node_map}) { my $temp; $temp->{name} = $node; push @a, $temp; } + $ret = 0; my $response = http_request("DELETE", $url, $data); if (!defined($response)) { $rsp->{data}->[0] = "Failed to send delete request."; @@ -62,25 +63,27 @@ sub delete_nodes { } elsif ($delmode) { while (my ($k, $v) = each %{$response}) { if ($v ne "Deleted") { - $rsp->{data}->[0] = "$k: Failed to delete delete entry in goconserver: $v"; + $rsp->{data}->[0] = "$k: Failed to delete entry in goconserver: $v"; xCAT::MsgUtils->message("E", $rsp, $callback); + $ret = 1; } else { $rsp->{data}->[0] = "$k: $v"; xCAT::MsgUtils->message("I", $rsp, $callback); } } } - return 0; + return $ret; } sub create_nodes { my ($api_url, $node_map, $callback) = @_; my $url = "$api_url/bulk/nodes"; - my ($data, $rsp, @a); + my ($data, $rsp, @a, $ret); $data->{nodes} = \@a; while (my ($k, $v) = each %{$node_map}) { push @a, $v; } + $ret = 0; my $response = http_request("POST", $url, $data); if (!defined($response)) { $rsp->{data}->[0] = "Failed to send create request."; @@ -91,13 +94,14 @@ sub create_nodes { if ($v ne "Created") { $rsp->{data}->[0] = "$k: Failed to create console entry in goconserver: $v"; xCAT::MsgUtils->message("E", $rsp, $::callback); + $ret = 1; } else { $rsp->{data}->[0] = "$k: $v"; xCAT::MsgUtils->message("I", $rsp, $::callback); } } } - return 0; + return $ret; } 1; \ No newline at end of file diff --git a/xCAT-server/lib/xcat/plugins/goconserver.pm b/xCAT-server/lib/xcat/plugins/goconserver.pm index 8fe84178f..7dd9aac01 100644 --- a/xCAT-server/lib/xcat/plugins/goconserver.pm +++ b/xCAT-server/lib/xcat/plugins/goconserver.pm @@ -3,10 +3,6 @@ package xCAT_plugin::goconserver; BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; - my $async_path = "/usr/local/share/perl5/"; - unless (grep { $_ eq $async_path } @INC) { - push @INC, $async_path; - } } use lib "$::XCATROOT/lib/perl"; use strict; @@ -160,9 +156,6 @@ sub preprocess_request { $reqcopy->{_xcatpreprocessed}->[0] = 1; $reqcopy->{'_allnodes'} = [$allnodes]; # the original command comes with nodes or not $reqcopy->{node} = $cons_hash{$cons}{nodes}; - my $no = $reqcopy->{node}; - - #print "node=@$no\n"; push @requests, $reqcopy; } #end if } #end foreach @@ -180,10 +173,10 @@ sub process_request { $::callback = shift; my @hostinfo = xCAT::NetworkUtils->determinehostname(); $host = $hostinfo[-1]; - if ($req->{command}->[0] eq "makegocons") { - makegocons($req); - } $isSN = xCAT::Utils->isServiceNode(); + if ($req->{command}->[0] eq "makegocons") { + makegocons($req, \@hostinfo); + } } sub get_cons_map { @@ -234,7 +227,7 @@ sub gen_request_data { my ($cons_map, $siteondemand) = @_; my (@openbmc_nodes, $data); while (my ($k, $v) = each %{$cons_map}) { - my $ondemaind = \0; + my $ondemaind = \1; my $cmd; my $cmeth = $v->{cons}; if ($cmeth eq "openbmc") { @@ -363,6 +356,7 @@ sub start_goconserver { sub makegocons { my $req = shift; + my $hostinfo = shift; my $extrargs = $req->{arg}; my @exargs = ($req->{arg}); if (ref($extrargs)) { @@ -378,11 +372,13 @@ sub makegocons { if (exists($req->{svboot})) { $svboot = 1; } - my @hostinfo = xCAT::NetworkUtils->determinehostname(); my %iphash = (); - foreach (@hostinfo) { $iphash{$_} = 1; } + foreach (@$hostinfo) { $iphash{$_} = 1; } my %cons_map = get_cons_map($req, \%iphash); - + if (! %cons_map) { + xCAT::SvrUtils::sendmsg([ 1, "Could not get any console request entry" ], $::callback); + return 1; + } my $ret = start_goconserver(); if ($ret != 0) { return 1; @@ -401,6 +397,10 @@ sub makegocons { } my (@nodes); my $data = gen_request_data(\%cons_map, $siteondemand); + if (! $data) { + xCAT::SvrUtils::sendmsg([ 1, "Could not generate the request data" ], $::callback); + return 1; + } my $api_url = "https://$host:$go_api_port"; $ret = xCAT::Goconserver::delete_nodes($api_url, $data, $delmode, $::callback); if ($delmode) {