From 318212085b7bcf4bb70a1e9c47d2d7507d2dc35b Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 25 Sep 2009 17:34:47 +0200
Subject: [PATCH] Fix the confusing ssh/hostname message in node add

Before, it used to say:

  ssh/hostname verification failed node1.example.com -> hostname mismatch, got
  node2

Now it says for wrong hostnames (maybe too verbose):

  ssh/hostname verification failed (checking from node1.example.com): hostname
  mismatch, expected node2.example.com but got node3

And for non-FQDN hostnames:

  ssh/hostname verification failed (checking from node1.example.com): hostname
  not FQDN: expected node2.example.com but got node2

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cmdlib.py | 3 ++-
 lib/ssh.py    | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index bc46ba4f1..391443545 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -2431,7 +2431,8 @@ class LUAddNode(LogicalUnit):
                                  " for remote verification" % verifier)
       if result[verifier].data['nodelist']:
         for failed in result[verifier].data['nodelist']:
-          feedback_fn("ssh/hostname verification failed %s -> %s" %
+          feedback_fn("ssh/hostname verification failed"
+                      " (checking from %s): %s" %
                       (verifier, result[verifier].data['nodelist'][failed]))
         raise errors.OpExecError("ssh/hostname verification failed.")
 
diff --git a/lib/ssh.py b/lib/ssh.py
index f0362b4b8..e89131422 100644
--- a/lib/ssh.py
+++ b/lib/ssh.py
@@ -227,7 +227,12 @@ class SshRunner:
     remotehostname = retval.stdout.strip()
 
     if not remotehostname or remotehostname != node:
-      return False, "hostname mismatch, got %s" % remotehostname
+      if node.startswith(remotehostname + "."):
+        msg = "hostname not FQDN"
+      else:
+        msg = "hostname mistmatch"
+      return False, ("%s: expected %s but got %s" %
+                     (msg, node, remotehostname))
 
     return True, "host matches"
 
-- 
GitLab