From 5557b04cf814fb2517a6f421c725a8d76a660600 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 19 Dec 2008 19:30:31 +0000
Subject: [PATCH] ganeti.bootstrap: Prepare for remote API certificate

Reviewed-by: amishchenko
---
 lib/bootstrap.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 7bef3faf1..71e2e9e35 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -322,15 +322,18 @@ def SetupNodeDaemon(cluster_name, node, ssh_key_check):
 
   """
   sshrunner = ssh.SshRunner(cluster_name)
-  gntpem = utils.ReadFile(constants.SSL_CERT_FILE)
+
+  noded_cert = utils.ReadFile(constants.SSL_CERT_FILE)
+
   # in the base64 pem encoding, neither '!' nor '.' are valid chars,
   # so we use this to detect an invalid certificate; as long as the
   # cert doesn't contain this, the here-document will be correctly
   # parsed by the shell sequence below
-  if re.search('^!EOF\.', gntpem, re.MULTILINE):
+  if re.search('^!EOF\.', noded_cert, re.MULTILINE):
     raise errors.OpExecError("invalid PEM encoding in the SSL certificate")
-  if not gntpem.endswith("\n"):
-    raise errors.OpExecError("PEM must end with newline")
+
+  if not noded_cert.endswith("\n"):
+    noded_cert += "\n"
 
   # set up inter-node password and certificate and restarts the node daemon
   # and then connect with ssh to set password and start ganeti-noded
@@ -339,7 +342,7 @@ def SetupNodeDaemon(cluster_name, node, ssh_key_check):
   mycommand = ("umask 077 && "
                "cat > '%s' << '!EOF.' && \n"
                "%s!EOF.\n%s restart" %
-               (constants.SSL_CERT_FILE, gntpem,
+               (constants.SSL_CERT_FILE, noded_cert,
                 constants.NODE_INITD_SCRIPT))
 
   result = sshrunner.Run(node, 'root', mycommand, batch=False,
-- 
GitLab