From e7f8d4261c98de703bc2a0b684bebbb0182a4bb0 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 21 Sep 2016 22:40:36 -0400 Subject: [PATCH 1/3] bmcdiscover -i IP -u USERID -p PASSW0RD --ipsource failed --- xCAT-server/lib/xcat/plugins/bmcdiscover.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm index c07f29ad1..48aaabea8 100644 --- a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm @@ -204,6 +204,16 @@ sub bmcdiscovery_processargs { return 1; } + ############################################ + # Option -U and -P for bmc user and password + ############################################ + if ($::opt_U) { + $bmc_user = $::opt_U; + } + if ($::opt_P) { + $bmc_pass = $::opt_P; + } + ######################################### # Option -s -r should be together ###################################### @@ -303,6 +313,8 @@ sub bmcdiscovery_processargs { $msg = "The ipsource option requires a BMC IP. Specify the IP using the -i|--bmcip option."; } elsif (!defined($::opt_P)) { $msg = "The ipsource option requires a password. Specify the password with the -p|--bmcpasswd option."; + } else { + $msg = "Failed to process ipsource command for bmc ip=$::opt_I user=$bmc_user password=$bmc_pass"; } my $rsp = {}; push @{ $rsp->{data} }, "$msg"; @@ -343,12 +355,14 @@ sub get_bmc_ip_source { my $callback = $::CALLBACK; my $pcmd; + if ($bmcuser eq "none") { $pcmd = "/opt/xcat/bin/ipmitool-xcat -vv -I lanplus -P $bmcpw -H $bmcip lan print "; } else { $pcmd = "/opt/xcat/bin/ipmitool-xcat -vv -I lanplus -U $bmcuser -P $bmcpw -H $bmcip lan print "; } + my $output = xCAT::Utils->runcmd("$pcmd", -1); if ($output =~ "IP Address Source") { @@ -372,9 +386,13 @@ sub get_bmc_ip_source { # Error: RAKP 2 HMAC is invalid <== incorrect password push @{ $rsp->{data} }, "$bmc_resp2"; } else { + my $error_msg = `echo "$output"|grep "Error" `; + if ($error_msg eq ""){ + $error_msg = "Can not find IP address Source"; + } # all other errors - push @{ $rsp->{data} }, "Error: Can not find IP Address Source"; + push @{ $rsp->{data} }, "$error_msg"; } xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return 2; From 0a8379c9ec29f0ae792c20de189e8fab6556f9bd Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 22 Sep 2016 11:09:06 -0400 Subject: [PATCH 2/3] modify code per ErTao's suggestion --- xCAT-server/lib/xcat/plugins/bmcdiscover.pm | 29 ++++++++------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm index 48aaabea8..f267a1c62 100644 --- a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm @@ -207,8 +207,18 @@ sub bmcdiscovery_processargs { ############################################ # Option -U and -P for bmc user and password ############################################ + # + # Get the default bmc account from passwd table, + # this is only done for the discovery process + # + ($bmc_user, $bmc_pass) = bmcaccount_from_passwd(); + # overwrite the default user and password if one is provided if ($::opt_U) { $bmc_user = $::opt_U; + } elsif ($::opt_P) { + # If password is provided, but no user, set the user to blank + # Support older FSP and Tuletta machines + $bmc_user = ''; } if ($::opt_P) { $bmc_pass = $::opt_P; @@ -246,23 +256,6 @@ sub bmcdiscovery_processargs { return 1; } - # - # Get the default bmc account from passwd table, this is only done for the - # discovery process - # - ($bmc_user, $bmc_pass) = bmcaccount_from_passwd(); - # overwrite the default password if one is provided - if ($::opt_U) { - $bmc_user = $::opt_U; - } else { - # If password is provided, but no user, set the user to blank - # Support older FSP and Tuletta machines - $bmc_user = ''; - } - if ($::opt_P) { - $bmc_pass = $::opt_P; - } - scan_process($::opt_M, $::opt_R, $::opt_Z, $::opt_W, $request_command); return 0; } @@ -303,7 +296,7 @@ sub bmcdiscovery_processargs { # --ipsource option, requires -i, -p to be specified #################################################### if (defined($::opt_S)) { - if (defined($bmc_user) && defined($bmc_pass) && defined($::opt_I)) { + if (defined($bmc_pass) && defined($::opt_I)) { my $res = get_bmc_ip_source($::opt_I, $bmc_user, $bmc_pass); return $res; } From fb033f83d9e726a62f4088185ae85140ad5a8d7d Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Mon, 26 Sep 2016 08:50:37 -0400 Subject: [PATCH 3/3] removed some blank space --- xCAT-server/lib/xcat/plugins/bmcdiscover.pm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm index f267a1c62..350294aff 100644 --- a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm @@ -206,11 +206,10 @@ sub bmcdiscovery_processargs { ############################################ # Option -U and -P for bmc user and password - ############################################ # # Get the default bmc account from passwd table, # this is only done for the discovery process - # + ############################################ ($bmc_user, $bmc_pass) = bmcaccount_from_passwd(); # overwrite the default user and password if one is provided if ($::opt_U) { @@ -348,7 +347,6 @@ sub get_bmc_ip_source { my $callback = $::CALLBACK; my $pcmd; - if ($bmcuser eq "none") { $pcmd = "/opt/xcat/bin/ipmitool-xcat -vv -I lanplus -P $bmcpw -H $bmcip lan print "; } @@ -359,7 +357,6 @@ sub get_bmc_ip_source { my $output = xCAT::Utils->runcmd("$pcmd", -1); if ($output =~ "IP Address Source") { - # success case my $rsp = {}; my $ipsource = `echo "$output"|grep "IP Address Source"`; @@ -371,11 +368,9 @@ sub get_bmc_ip_source { else { my $rsp = {}; if ($output =~ $bmc_str1) { - # Error: RAKP 2 message indicates an error : unauthorized name <== incorrect username push @{ $rsp->{data} }, "$bmc_resp1"; } elsif ($output =~ $bmc_str2) { - # Error: RAKP 2 HMAC is invalid <== incorrect password push @{ $rsp->{data} }, "$bmc_resp2"; } else { @@ -383,7 +378,6 @@ sub get_bmc_ip_source { if ($error_msg eq ""){ $error_msg = "Can not find IP address Source"; } - # all other errors push @{ $rsp->{data} }, "$error_msg"; }