From 80e6a947b8e2b2207ec3c1ef73b5610d848090be Mon Sep 17 00:00:00 2001 From: ertaozh Date: Thu, 30 Jun 2016 01:44:24 -0400 Subject: [PATCH] Fix issue 1371: xcatprobe switch - could not get valid information while using switch-macmap --- perl-xCAT/xCAT/MacMap.pm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/perl-xCAT/xCAT/MacMap.pm b/perl-xCAT/xCAT/MacMap.pm index 74c6b8afc..bc78f8630 100644 --- a/perl-xCAT/xCAT/MacMap.pm +++ b/perl-xCAT/xCAT/MacMap.pm @@ -16,6 +16,7 @@ use xCAT::Table; use xCAT::Utils; use xCAT::MsgUtils; use xCAT::TableUtils; +use xCAT::NetworkUtils; use IO::Select; use IO::Handle; use Sys::Syslog; @@ -573,10 +574,14 @@ sub getsnmpsession { $snmpver=$swent->{snmpversion}; $community=$swent->{password}; } + my $switch_ip = xCAT::NetworkUtils->getipaddr($switch); + unless ($switch_ip) { + return ({"ErrorStr"=>"Can not resolve IP address for $switch"}); + } if ($snmpver ne '3') { if ($vlanid) { $community .= '@'.$vlanid; } $session = new SNMP::Session( - DestHost => $switch, + DestHost => $switch_ip, Version => $snmpver, Community => $community, UseNumeric => 1 @@ -587,7 +592,7 @@ sub getsnmpsession { } else { #we have snmp3 my %args= ( - DestHost => $switch, + DestHost => $switch_ip, SecName => $swent->{username}, AuthProto => uc($swent->{auth}), AuthPass => $community, @@ -629,8 +634,11 @@ sub refresh_switch { } return; } - elsif ($session->{ErrorStr} and $self->{collect_mac_info}) { - $self->{macinfo}->{$switch}->{ErrorStr} = $session->{ErrorStr}; + elsif ($session->{ErrorStr}) { + if ($self->{collect_mac_info}) { + $self->{macinfo}->{$switch}->{ErrorStr} = $session->{ErrorStr}; + } + return; } my $namemap = walkoid($session,'.1.3.6.1.2.1.31.1.1.1.1', verbose=>$self->{show_verbose_info}, switch=>$switch, callback=>$self->{callback}); #namemap is the mapping of ifIndex->(human readable name) @@ -695,6 +703,12 @@ sub refresh_switch { $session = $self->getsnmpsession('switch'=>$switch,'community'=>$community,'vlanid'=>$vlan); } unless ($session) { return; } + elsif ($session->{ErrorStr}) { + if ($self->{collect_mac_info}) { + $self->{macinfo}->{$switch}->{ErrorStr} = $session->{ErrorStr}; + } + return; + } my $bridgetoifmap = walkoid($session,'.1.3.6.1.2.1.17.1.4.1.2', ciscowarn=>$iscisco, verbose=>$self->{show_verbose_info}, switch=>$switch, callback=>$self->{callback}); # Good for all switches if (not ref $bridgetoifmap or !keys %{$bridgetoifmap}) { xCAT::MsgUtils->message("S","Error communicating with ".$session->{DestHost}.": failed to get a valid response to BRIDGE-MIB request");