From c4b6c29c7a06874f40e92522d30cc642d8651b42 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 15 Aug 2008 08:55:09 +0000
Subject: [PATCH] gnt-node: Add option to always accept peer's SSH key

This option will be used to add nodes to the cluster without
asking the user to confirm the key. Together with key based
authentication this can be used in the QA tests.

Reviewed-by: ultrotter
---
 lib/bootstrap.py | 8 +++++---
 scripts/gnt-node | 8 ++++++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 3045a44e8..160c1a59a 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -243,7 +243,7 @@ def FinalizeClusterDestroy(master):
     logging.warning("Could not shutdown the node daemon and cleanup the node")
 
 
-def SetupNodeDaemon(node):
+def SetupNodeDaemon(node, ssh_key_check):
   """Add a node to the cluster.
 
   This function must be called before the actual opcode, and will ssh
@@ -285,8 +285,10 @@ def SetupNodeDaemon(node):
                 constants.SSL_CERT_FILE, gntpem,
                 constants.NODE_INITD_SCRIPT))
 
-  result = sshrunner.Run(node, 'root', mycommand, batch=False, ask_key=True,
-                         use_cluster_key=False)
+  result = sshrunner.Run(node, 'root', mycommand, batch=False,
+                         ask_key=ssh_key_check,
+                         use_cluster_key=False,
+                         strict_host_check=ssh_key_check)
   if result.failed:
     raise errors.OpExecError("Remote command on node %s, error: %s,"
                              " output: %s" %
diff --git a/scripts/gnt-node b/scripts/gnt-node
index 20461b587..8acf34a8e 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -61,7 +61,7 @@ def AddNode(opts, args):
     "on the target machine (%s) with the ones of the current one\n"
     "and grant full intra-cluster ssh root access to/from it\n" % node)
 
-  bootstrap.SetupNodeDaemon(node)
+  bootstrap.SetupNodeDaemon(node, opts.ssh_key_check)
 
   op = opcodes.OpAddNode(node_name=args[0], secondary_ip=opts.secondary_ip,
                          readd=opts.readd)
@@ -314,8 +314,12 @@ commands = {
            make_option("--readd", dest="readd",
                        default=False, action="store_true",
                        help="Readd old node after replacing it"),
+           make_option("--no-ssh-key-check", dest="ssh_key_check",
+                       default=True, action="store_false",
+                       help="Disable SSH key fingerprint checking"),
            ],
-          "[-s ip] [--readd] <node_name>", "Add a node to the cluster"),
+          "[-s ip] [--readd] [--no-ssh-key-check] <node_name>",
+          "Add a node to the cluster"),
   'evacuate': (EvacuateNode, ARGS_FIXED(2),
                [DEBUG_OPT, FORCE_OPT],
                "[-f] <src> <dst>",
-- 
GitLab