diff --git a/xCAT-client/pods/man8/makeknownhosts.8.pod b/xCAT-client/pods/man8/makeknownhosts.8.pod index 612c04b7e..99047d1cb 100644 --- a/xCAT-client/pods/man8/makeknownhosts.8.pod +++ b/xCAT-client/pods/man8/makeknownhosts.8.pod @@ -4,7 +4,7 @@ B - Make a known_hosts file under $ROOTHOME/.ssh for input noder =head1 SYNOPSIS -B I [B<-r>|B<--remove>] [B<-V>|B<--verbose>] +B I [B<-r>|B<--remove>|B<-d>|B<--delete>] [B<-V>|B<--verbose>] B [B<-h>|B<--help>] @@ -29,10 +29,14 @@ The file should be distributed using B to all the nodes, if you want node A set of comma delimited node names and/or group names. See the I man page for details on supported formats. -=item B<-r|--remove> +=item B<-d|--delete> Only removes the entries for the nodes from the known_hosts file. +=item B<-r|--remove> + +Synonymous to B<-d|--delete>. + =item B<-V|--verbose> Verbose mode. @@ -56,7 +60,7 @@ To build the known_hosts entry for the nodes in the lpars and service groups =item 3. To remove the known_hosts entry for node02 - makeknownhosts node02 -r + makeknownhosts node02 -d =back diff --git a/xCAT-server/lib/xcat/plugins/00kitnodebase.pm b/xCAT-server/lib/xcat/plugins/00kitnodebase.pm index 4eb76eacb..256ce90a3 100644 --- a/xCAT-server/lib/xcat/plugins/00kitnodebase.pm +++ b/xCAT-server/lib/xcat/plugins/00kitnodebase.pm @@ -130,7 +130,7 @@ sub process_request { if ($runconservercmd) { push @commandslist, [ 'makeconservercf', '-d' ]; } - push @commandslist, [ 'makeknownhosts', '-r' ]; + push @commandslist, [ 'makeknownhosts', '-d' ]; if ($macflag) { push @commandslist, [ 'makedhcp', '-d' ]; } diff --git a/xCAT-server/lib/xcat/plugins/makeknownhosts.pm b/xCAT-server/lib/xcat/plugins/makeknownhosts.pm index ef15946a3..8779b257a 100644 --- a/xCAT-server/lib/xcat/plugins/makeknownhosts.pm +++ b/xCAT-server/lib/xcat/plugins/makeknownhosts.pm @@ -65,13 +65,14 @@ sub process_request if ($request && $request->{arg}) { @ARGV = @{ $request->{arg} }; } else { @ARGV = (); } - my $usage = "Usage: makeknownhosts [-r] [-V]\n makeknownhosts -h"; + my $usage = "Usage: makeknownhosts [-r|-d] [-V]\n makeknownhosts -h"; # print "argv=@ARGV\n"; if (!GetOptions( 'h|help' => \$::opt_h, 'V|verbose' => \$::opt_V, 'r|remove' => \$::opt_r + 'd|delete' => \$::opt_d )) { my $rsp = {}; @@ -81,23 +82,22 @@ sub process_request } # display the usage if -h - if ($::opt_h) - { + if ($::opt_h) { my $rsp = {}; $rsp->{data}->[0] = $usage; xCAT::MsgUtils->message("I", $rsp, $callback, 1); return 0; } - if ($nodes eq "") - { # no noderange + if ($nodes eq "") { + # no noderange my $rsp = {}; $rsp->{data}->[0] = "The Noderange is missing."; xCAT::MsgUtils->message("E", $rsp, $callback, 1); return 1; } my $hostkey = "/etc/xcat/hostkeys/ssh_host_rsa_key.pub"; - if (!(-e $hostkey)) - { # the key is missing, cannot create known_hosts + if (!(-e $hostkey)) { + # the key is missing, cannot create known_hosts my $rsp = {}; $rsp->{data}->[0] = "The keyfile:$hostkey is missing. Cannot create the known_hosts file."; @@ -107,35 +107,28 @@ sub process_request # Backup the existing known_hosts file to known_hosts.backup $rc = backup_known_hosts_file($callback); - if ($rc != 0) - { + if ($rc != 0) { my $rsp = {}; $rsp->{data}->[0] = "Error backing up known_hosts file."; xCAT::MsgUtils->message("E", $rsp, $callback, 1); return 1; - } # Remove the nodes from knownhosts file $rc = remove_nodes_from_knownhosts($callback, $nodes); - if ($rc != 0) - { + if ($rc != 0) { my $rsp = {}; $rsp->{data}->[0] = "Error backing up known_hosts file."; xCAT::MsgUtils->message("E", $rsp, $callback, 1); return 1; - } # if -r flag is not specified, adding the nodes back to known_hosts file - if (!$::opt_r) - { + if (!($::opt_r or $::opt_d)) { my @nodelist = @$nodes; - foreach my $node (@nodelist) - { + foreach my $node (@nodelist) { $rc = add_known_host($node, $callback); - if ($rc != 0) - { + if ($rc != 0) { my $rsp = {}; $rsp->{data}->[0] = "Error building known_hosts file."; xCAT::MsgUtils->message("E", $rsp, $callback, 1); @@ -153,8 +146,6 @@ sub process_request Backs up the old known_hosts file in roots .ssh directory, if it exists. - - =cut #------------------------------------------------------- diff --git a/xCAT-test/autotest/testcase/makeknownhosts/cases0 b/xCAT-test/autotest/testcase/makeknownhosts/cases0 index 3e7e2e512..afe1e371d 100644 --- a/xCAT-test/autotest/testcase/makeknownhosts/cases0 +++ b/xCAT-test/autotest/testcase/makeknownhosts/cases0 @@ -28,6 +28,18 @@ check:rc!=0 check:output!~$$CN end +start:makeknownhosts_node_d +description:delete known node entry from $ROOTHOME/.ssh +cmd:makeknownhosts $$CN +cmd:cat ~/.ssh/known_hosts|grep $$CN +check:output=~$$CN +cmd:makeknownhosts $$CN -d +check:rc==0 +cmd:cat ~/.ssh/known_hosts|grep $$CN +check:rc!=0 +check:output!~$$CN +end + start:makeknownhosts_node_v description:verbose cmd:makeknownhosts $$CN -V