Fix bugs: 2829874 lsconn and mkconn not working in 0728 xCAT 2.3 build; 2826734 lsslp can only write one BPA side into xCAT DB
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3912 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -73,8 +73,10 @@ sub mkconn_parse_args | ||||
|     my $nodes = $request->{node}; | ||||
|     my $ppctab  = xCAT::Table->new( 'ppc' ); | ||||
|     my $nodetypetab = xCAT::Table->new( 'nodetype'); | ||||
|     my $vpdtab = xCAT::Table->new( 'vpd'); | ||||
|     my @bpa_ctrled_nodes = (); | ||||
|     my @no_type_nodes    = (); | ||||
|     my @frame_members    = (); | ||||
|     if ( $ppctab) | ||||
|     { | ||||
|         for my $node ( @$nodes) | ||||
| @@ -97,23 +99,78 @@ sub mkconn_parse_args | ||||
|             { | ||||
|                 push @bpa_ctrled_nodes, $node; | ||||
|             } | ||||
|              | ||||
|             if ( $nodetype eq 'bpa') | ||||
|             { | ||||
|                 my $my_frame_bpa_cec = getFrameMembers( $node, $vpdtab, $ppctab); | ||||
|                 push @frame_members, @$my_frame_bpa_cec; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (scalar(@no_type_nodes)) | ||||
|     { | ||||
|         my $tmp_nodelist = join ',', @no_type_nodes; | ||||
|         return ( usage("Attribute nodetype.nodetype cannot be found for node(s) $tmp_nodelist")); | ||||
|     } | ||||
|  | ||||
|     if (scalar(@bpa_ctrled_nodes)) | ||||
|     { | ||||
|         my $tmp_nodelist = join ',', @bpa_ctrled_nodes; | ||||
|         return ( usage("Node(s) $tmp_nodelist is(are) controlled by BPA.")); | ||||
|     } | ||||
|      | ||||
|     if ( scalar( @frame_members)) | ||||
|     { | ||||
|          $request->{node} = xCAT::Utils::get_unique_members( @$nodes, @frame_members); | ||||
|     } | ||||
|     # Set HW type to 'hmc' anyway, so that this command will not going to  | ||||
|     # PPCfsp.pm | ||||
|     $request->{ 'hwtype'} = 'hmc'; | ||||
|     $request->{method} = 'mkconn'; | ||||
|     return( \%opt); | ||||
| } | ||||
|  | ||||
| #################################################### | ||||
| # Get frame members | ||||
| #################################################### | ||||
| #ppc/vpd nodes cache | ||||
| my @all_ppc_nodes; | ||||
| my @all_vpd_nodes; | ||||
| sub getFrameMembers | ||||
| { | ||||
|     my $node = shift; #this a BPA node | ||||
|     my $vpdtab = shift; | ||||
|     my $ppctab = shift; | ||||
|     my @frame_members; | ||||
|     my $vpdhash = $vpdtab->getNodeAttribs( $node, [qw(mtm serial)]); | ||||
|     my $mtm = $vpdhash->{mtm}; | ||||
|     my $serial = $vpdhash->{serial}; | ||||
|     if ( scalar( @all_ppc_nodes) == 0) | ||||
|     { | ||||
|         @all_ppc_nodes = $ppctab->getAllNodeAttribs( ['node', 'parent']); | ||||
|     } | ||||
|     for my $ppc_node (@all_ppc_nodes) | ||||
|     { | ||||
|         if ( $ppc_node->{parent} eq $node) | ||||
|         { | ||||
|             push @frame_members, $ppc_node->{'node'}; | ||||
|         } | ||||
|     } | ||||
|     if ( scalar( @all_vpd_nodes) == 0) | ||||
|     { | ||||
|         @all_vpd_nodes = $vpdtab->getAllNodeAttribs( ['node', 'mtm', 'serial']); | ||||
|     } | ||||
|     for my $vpd_node (@all_vpd_nodes) | ||||
|     { | ||||
|         if ( $vpd_node->{'mtm'} eq $mtm and $vpd_node->{'serial'} eq $serial) | ||||
|         { | ||||
|             push @frame_members, $vpd_node->{'node'}; | ||||
|         } | ||||
|     } | ||||
|     return \@frame_members; | ||||
| } | ||||
|  | ||||
| ########################################################################## | ||||
| # Parse arguments for lsconn | ||||
| ########################################################################## | ||||
| @@ -130,7 +187,7 @@ sub lsconn_parse_args | ||||
| ############################################# | ||||
| # Get options in command line | ||||
| ############################################# | ||||
|     local @ARGV = @$args; | ||||
|     local @ARGV = ref($args) eq 'ARRAY'? @$args:(); | ||||
|     $Getopt::Long::ignorecase = 0; | ||||
|     Getopt::Long::Configure( "bundling" ); | ||||
|  | ||||
| @@ -141,7 +198,7 @@ sub lsconn_parse_args | ||||
|     ############################################# | ||||
|     # Process command-line arguments | ||||
|     ############################################# | ||||
|     if ( scalar @$args) { | ||||
|     if ( $args && scalar @$args) { | ||||
|         return(usage( "No additional flag is support by this command" )); | ||||
|     } | ||||
|     my $notypetab = xCAT::Table->new('nodetype'); | ||||
| @@ -263,6 +320,10 @@ sub mkconn | ||||
|         my $res = xCAT::PPCcli::mksysconn( $exp, $node_ip, $type, $passwd); | ||||
|         $Rc = shift @$res; | ||||
|         push @value, [$node_name, @$res[0], $Rc]; | ||||
|         if ( !$Rc) | ||||
|         { | ||||
|             sethmcmgt( $node_name, $exp->[3]); | ||||
|         } | ||||
|     } | ||||
|     return \@value; | ||||
| } | ||||
| @@ -395,7 +456,57 @@ sub rmconn | ||||
|         my $res = xCAT::PPCcli::rmsysconn( $exp, $type, $cec_bpa); | ||||
|         $Rc = shift @$res; | ||||
|         push @value, [$node_name, @$res[0], $Rc]; | ||||
|         if ( !$Rc) | ||||
|         { | ||||
|             rmhmcmgt( $node_name, $type); | ||||
|         } | ||||
|     } | ||||
|     return \@value; | ||||
| } | ||||
|  | ||||
| ################################################################# | ||||
| # set node mgt to hmc, and hcp to the hmc node name | ||||
| ################################################################# | ||||
| sub sethmcmgt | ||||
| { | ||||
|     my $node = shift; | ||||
|     my $hcp  = shift; | ||||
|  | ||||
|     my $nodehm_tab = xCAT::Table->new('nodehm', -create=>1); | ||||
|     my $ent = $nodehm_tab->getNodeAttribs( $node, ['mgt']); | ||||
|     if ( !$ent or $ent->{mgt} ne 'hmc') | ||||
|     { | ||||
|         $nodehm_tab->setNodeAttribs( $node, { mgt=>'hmc'}); | ||||
|     } | ||||
|      | ||||
|     my $ppc_tab = xCAT::Table->new('ppc', -create=>1); | ||||
|     my $ent = $ppc_tab->getNodeAttribs( $node, ['hcp']); | ||||
|     if ( !$ent or $ent->{hcp} ne $hcp) | ||||
|     { | ||||
|         $ppc_tab->setNodeAttribs( $node, { hcp=>$hcp}); | ||||
|     } | ||||
| } | ||||
| ################################################################# | ||||
| # set node as the standalone fsp/bpa node | ||||
| ################################################################# | ||||
| sub rmhmcmgt | ||||
| { | ||||
|     my $node = shift; | ||||
|     my $hwtype = shift; | ||||
|  | ||||
|     my $nodehm_tab = xCAT::Table->new('nodehm', -create=>1); | ||||
|     my $ent = $nodehm_tab->getNodeAttribs( $node, ['mgt']); | ||||
|     if ( !$ent or $ent->{mgt} ne $hwtype) | ||||
|     { | ||||
|         $nodehm_tab->setNodeAttribs( $node, { mgt=>$hwtype}); | ||||
|     } | ||||
|      | ||||
|     my $ppc_tab = xCAT::Table->new('ppc', -create=>1); | ||||
|     my $ent = $ppc_tab->getNodeAttribs( $node, ['hcp']); | ||||
|     if ( !$ent or $ent->{hcp} ne $node) | ||||
|     { | ||||
|         $ppc_tab->setNodeAttribs( $node, { hcp=>$node}); | ||||
|     } | ||||
| } | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -4965,4 +4965,35 @@ sub getNodeNetworkCfg | ||||
|     return ($ip, $node, undef, xCAT::Utils::formatNetmask($mask,1,0)); | ||||
| } | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3   get_unique_members  | ||||
|     Description: | ||||
|         Return an array which have unique members | ||||
|  | ||||
|     Arguments: | ||||
|         origarray: the original array to be treated | ||||
|     Returns: | ||||
|         Return an array, which contains unique members. | ||||
|     Globals: | ||||
|         none | ||||
|     Error: | ||||
|         none | ||||
|     Example: | ||||
|         my @new_array = xCAT::Utils::get_unique_members(@orig_array); | ||||
|     Comments: | ||||
|  | ||||
| =cut | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
| sub get_unique_members | ||||
| { | ||||
|     my @orig_array = @_; | ||||
|     my %tmp_hash = {}; | ||||
|     for (@orig_array) | ||||
|     { | ||||
|         $tmp_hash{$_} = 1; | ||||
|     } | ||||
|     return keys %tmp_hash; | ||||
| } | ||||
| 1; | ||||
|   | ||||
| @@ -589,8 +589,10 @@ sub preprocess_nodes { | ||||
|     #   Direct-attached FSP  | ||||
|     ######################################## | ||||
|     if (( $request->{command} =~ /^(rscan|rspconfig)$/ ) or | ||||
|             ( $request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa") or | ||||
|         ($request->{command} eq 'lsconn' and $request->{nodetype} eq 'hmc')) { | ||||
| #        (( $request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa" ) and ( $request->{command} ne "mkconn")) or | ||||
|         ($request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa" ) or | ||||
|         ($request->{command} eq 'lsconn' and $request->{nodetype} eq 'hmc') | ||||
| ) { | ||||
|         my $result = resolve_hcp( $request, $noderange ); | ||||
|         return( $result ); | ||||
|     } | ||||
| @@ -1348,9 +1350,12 @@ sub process_request { | ||||
| #    $request->{hwtype}  = $package; | ||||
|     $request->{callback}= $callback; | ||||
|     ######################### | ||||
|     #This is a special case for rspconfig, we shouldn't set hwtype as$package. and reserved for other commands. | ||||
|     #This is a special case for rspconfig and mkconn,  | ||||
|     #we shouldn't set hwtype as$package. and reserved for other commands. | ||||
|     #probably for all HW ctrl commands it still true? | ||||
|     ######################### | ||||
|     if($request->{command} ne "rspconfig") { | ||||
|     if($request->{command} ne "rspconfig" and  | ||||
|         $request->{command} ne "mkconn") { | ||||
|         $request->{hwtype}  = $package; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1449,6 +1449,46 @@ sub parse_responses { | ||||
|         $result[0] = $service_slp{$type}; | ||||
|         $outhash{$host} = \@result; | ||||
|     } | ||||
|      | ||||
|     ########################################################## | ||||
|     # Correct BPA node name because both side | ||||
|     # have the same MTMS and may get the same factory name | ||||
|     # If there are same factory name for 2 BPA (should be 2 sides | ||||
|     # on one frame), change them to like <bpa>_1 and <bpa>_2 | ||||
|     ########################################################## | ||||
|     my %hostname_record; | ||||
|     for my $h ( keys %outhash) | ||||
|     { | ||||
|         my ($name, $ip); | ||||
|         if ( $h =~ /^([^\(]+)\(([^\)]+)\)$/) | ||||
|         { | ||||
|             $name = $1; | ||||
|             $ip   = $2; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             next; | ||||
|         } | ||||
|          | ||||
|         if (exists $hostname_record{$name}) | ||||
|         { | ||||
|             #Name is duplicated | ||||
|             my ($old_h, $old_ip) = @{$hostname_record{$name}}; | ||||
|  | ||||
|             $outhash{$old_h}->[4] = $name . "-1" . "($old_ip)"; | ||||
|             $outhash{$name . "-1" . "($old_ip)"} = $outhash{$old_h}; | ||||
|             delete $outhash{$old_h}; | ||||
|              | ||||
|             $outhash{$h}->[4] = $name . "-2" . "($ip)"; | ||||
|             $outhash{$name . "-2" . "($ip)"} = $outhash{$h}; | ||||
|             delete $outhash{$h}; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             $hostname_record{$name} = [$h,$ip]; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return( \%outhash ); | ||||
| } | ||||
|  | ||||
| @@ -1513,7 +1553,13 @@ sub xCATdB { | ||||
|         { | ||||
|             if ( $ent->{mtm} and $ent->{serial}) | ||||
|             { | ||||
|                 $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} = $ent->{node}; | ||||
|                 # if there is no BPA, or there is the second BPA, change it | ||||
|                 if ( ! exists $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} or  | ||||
|                      $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} =~ /-2$/ | ||||
|                    ) | ||||
|                 { | ||||
|                     $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} = $ent->{node}; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -1567,9 +1613,9 @@ sub xCATdB { | ||||
|             # May be no Frame with this FSP | ||||
|             ######################################## | ||||
|             if (( $bpc_model ne "0" ) and ( $bpc_serial ne "0" )) { | ||||
|                 if ( exists $sn_node{"$bpc_model*$bpc_serial"}) | ||||
|                 if ( exists $sn_node{"Server-$bpc_model-SN$bpc_serial"}) | ||||
|                 { | ||||
|                     $frame = $sn_node{"$bpc_model*$bpc_serial"}; | ||||
|                     $frame = $sn_node{"Server-$bpc_model-SN$bpc_serial"}; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user