From ff98055b4c6e2e6b602c4a51836dd123cf97c187 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 28 Aug 2007 12:25:29 +0000
Subject: [PATCH] Refuse nodes with non-FQDN hostnames.

This changes the cluster init and node join to refuse a node that has a
different hostname than what the resolver returns.

Reviewed-by: imsnah
---
 lib/cmdlib.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 26057f38d..1f858463c 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -540,6 +540,12 @@ class LUInitCluster(LogicalUnit):
       raise errors.OpPrereqError("Cannot resolve my own hostname ('%s')" %
                                  hostname_local)
 
+    if hostname["hostname_full"] != hostname_local:
+      raise errors.OpPrereqError("My own hostname (%s) does not match the"
+                                 " resolver (%s): probably not using FQDN"
+                                 " for hostname." %
+                                 (hostname_local, hostname["hostname_full"]))
+
     self.clustername = clustername = utils.LookupHostname(self.op.cluster_name)
     if not clustername:
       raise errors.OpPrereqError("Cannot resolve given cluster name ('%s')"
@@ -1433,6 +1439,13 @@ class LUAddNode(LogicalUnit):
                                  "Please fix and re-run this command." %
                                  new_node.secondary_ip)
 
+    success, msg = ssh.VerifyNodeHostname(node)
+    if not success:
+      raise errors.OpExecError("Node '%s' claims it has a different hostname"
+                               " than the one the resolver gives: %s.\n"
+                               "Please fix and re-run this command." %
+                               (node, msg))
+
     # Distribute updated /etc/hosts and known_hosts to all nodes,
     # including the node just added
     myself = self.cfg.GetNodeInfo(self.sstore.GetMasterNode())
-- 
GitLab