defect 3851- handle multiple MN in DB
This commit is contained in:
		@@ -3237,7 +3237,14 @@ sub bld_resolve_nodes_hash
 | 
			
		||||
 | 
			
		||||
    # find out if we have an MN in the list, local cp and sh will be used
 | 
			
		||||
    # not remote shell
 | 
			
		||||
    my $mname = xCAT::Utils->noderangecontainsMn(@target_list);
 | 
			
		||||
    # find out the names for the Management Node
 | 
			
		||||
    my @MNnodeinfo   = xCAT::NetworkUtils->determinehostname;
 | 
			
		||||
    my $mname   = pop @MNnodeinfo;                  # hostname
 | 
			
		||||
    #my $rsp = {};
 | 
			
		||||
    #$rsp->{info}->[0] =
 | 
			
		||||
    #      "Management node name is $mname.";
 | 
			
		||||
    #            xCAT::MsgUtils->message("I", $rsp, $::CALLBACK);
 | 
			
		||||
 | 
			
		||||
    foreach my $target (@target_list)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@@ -4079,11 +4086,12 @@ sub parse_and_run_dsh
 | 
			
		||||
        # check if any node in the noderange is the Management Node and exit 
 | 
			
		||||
        # with error, if the Management Node is in the Database and in the
 | 
			
		||||
        # noderange
 | 
			
		||||
        my $mname = xCAT::Utils->noderangecontainsMn(@nodelist); 
 | 
			
		||||
        if ($mname) {  # MN in the nodelist
 | 
			
		||||
        my @mname = xCAT::Utils->noderangecontainsMn(@nodelist); 
 | 
			
		||||
        if (@mname) {  # MN in the nodelist
 | 
			
		||||
            my $nodes=join(',', @mname);
 | 
			
		||||
            my $rsp = {};
 | 
			
		||||
            $rsp->{error}->[0] =
 | 
			
		||||
              "You must not run -K option against the Management Node:$mname.";
 | 
			
		||||
              "You must not run -K option against the Management Node:$nodes.";
 | 
			
		||||
            xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1);
 | 
			
		||||
            return;
 | 
			
		||||
        } 
 | 
			
		||||
 
 | 
			
		||||
@@ -242,12 +242,13 @@ sub getAllSN
 | 
			
		||||
    # if did not input "ALL" and there is a MN, remove it
 | 
			
		||||
    my @newservicenodes;
 | 
			
		||||
    if ((!defined($options)) || ($options ne "ALL")) {   
 | 
			
		||||
       my $mname = xCAT::Utils->noderangecontainsMn(@servicenodes);
 | 
			
		||||
       if ($mname) { # if there is a MN
 | 
			
		||||
        foreach my $nodes (@servicenodes) {
 | 
			
		||||
           if ($mname ne ($nodes)){
 | 
			
		||||
              push @newservicenodes, $nodes;
 | 
			
		||||
           }
 | 
			
		||||
       my @mname = xCAT::Utils->noderangecontainsMn(@servicenodes);
 | 
			
		||||
       if (@mname) { # if there is a MN
 | 
			
		||||
        foreach my $node (@servicenodes) {
 | 
			
		||||
          # check to see if node in MN list
 | 
			
		||||
          if (!(grep(/^$node$/, @mname))) { # if node not in the MN array
 | 
			
		||||
              push @newservicenodes, $node;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        $servicenodetab->close;
 | 
			
		||||
        return @newservicenodes;  # return without the MN in the array
 | 
			
		||||
 
 | 
			
		||||
@@ -211,7 +211,7 @@ sub makescript {
 | 
			
		||||
     return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $mn = xCAT::Utils->noderangecontainsMn(@$nodes);
 | 
			
		||||
  @::mn = xCAT::Utils->noderangecontainsMn(@$nodes);
 | 
			
		||||
 | 
			
		||||
  my $cfgflag=0;
 | 
			
		||||
  my $cloudflag=0;
 | 
			
		||||
@@ -652,7 +652,7 @@ sub getNodeType
 | 
			
		||||
    my $node   = shift;
 | 
			
		||||
    my $result;
 | 
			
		||||
   
 | 
			
		||||
    if ( $node =~ /^$mn$/) {
 | 
			
		||||
    if (grep(/^$node$/, @::mn)) {   # is it in the Management Node array 
 | 
			
		||||
        $result="MN";
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -396,12 +396,13 @@ sub preprocess_updatenode
 | 
			
		||||
 | 
			
		||||
        # check to see if the Management Node is in the noderange and
 | 
			
		||||
        # if it is abort
 | 
			
		||||
        my $mname = xCAT::Utils->noderangecontainsMn(@$nodes);
 | 
			
		||||
        if ($mname)
 | 
			
		||||
        my @mname = xCAT::Utils->noderangecontainsMn(@$nodes);
 | 
			
		||||
        if (@mname)
 | 
			
		||||
        {    # MN in the nodelist
 | 
			
		||||
            my $nodes=join(',', @mname);
 | 
			
		||||
            my $rsp = {};
 | 
			
		||||
            $rsp->{error}->[0] =
 | 
			
		||||
              "You must not run -k option against the Management Node:$mname.";
 | 
			
		||||
              "You must not run -k option against a management node: $nodes.";
 | 
			
		||||
            xCAT::MsgUtils->message("E", $rsp, $callback, 1);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2124,23 +2124,27 @@ sub setupMNinDB
 | 
			
		||||
 | 
			
		||||
   my $defined  = 0;
 | 
			
		||||
   my $cmds="XCATBYPASS=Y $::XCATROOT/sbin/tabdump nodelist | grep  __mgmtnode";
 | 
			
		||||
   my $output = xCAT::Utils->runcmd("$cmds", -1);
 | 
			
		||||
   my @output = xCAT::Utils->runcmd("$cmds", -1);
 | 
			
		||||
   
 | 
			
		||||
   if ($::RUNCMD_RC == 0)  # found a management node defined
 | 
			
		||||
   {
 | 
			
		||||
      my $chtabcmds;
 | 
			
		||||
      my @mn = split(",", $output);  
 | 
			
		||||
      my @mn = split(",", $output[0]);  
 | 
			
		||||
      $mn[0] =~ s/"//g;   # remove the quotes
 | 
			
		||||
      if  ($mn[0] ne $mnname) {   # does not match current host name,delete it
 | 
			
		||||
        $chtabcmds = "$::XCATROOT/sbin/chtab -d node=$mn[0] nodelist;";
 | 
			
		||||
        my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
 | 
			
		||||
        if ($::RUNCMD_RC != 0)
 | 
			
		||||
        {
 | 
			
		||||
          xCAT::MsgUtils->message('E', "Could not run $chtabcmds.");
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
         my $size=@output;   # if more than one management  node defined, do not remove any
 | 
			
		||||
         if ($size == 1) {
 | 
			
		||||
           $chtabcmds = "$::XCATROOT/sbin/chtab -d node=$mn[0] nodelist;";
 | 
			
		||||
           my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
 | 
			
		||||
           if ($::RUNCMD_RC != 0)
 | 
			
		||||
           {
 | 
			
		||||
             xCAT::MsgUtils->message('E', "Could not run $chtabcmds.");
 | 
			
		||||
             return;
 | 
			
		||||
           }
 | 
			
		||||
         }
 | 
			
		||||
      } else {  # it is defined and good
 | 
			
		||||
          xCAT::MsgUtils->message('I', "$mnname already defined in the nodelist table.");
 | 
			
		||||
          $defined=1;     
 | 
			
		||||
             xCAT::MsgUtils->message('I', "$mnname already defined in the nodelist table.");
 | 
			
		||||
             $defined=1;     
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    # now add with the new name , if not already there
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user