From 50265802216e5982650a09243a32d5b468eb30b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Wed, 2 Feb 2011 11:31:26 +0100
Subject: [PATCH] Make it possible to disable tty in qa_utils.GetCommandOutput
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The tty can have strange side effect as it seems to replace \n with
\r\n. In case of simply catting a file and compare it's output this
will break. This patch adds the possibility to disable tty if needed.

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 qa/qa_utils.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/qa/qa_utils.py b/qa/qa_utils.py
index a5cc2cd0f..be3781893 100644
--- a/qa/qa_utils.py
+++ b/qa/qa_utils.py
@@ -148,7 +148,7 @@ def AssertCommand(cmd, fail=False, node=None):
   return rcode
 
 
-def GetSSHCommand(node, cmd, strict=True, opts=None):
+def GetSSHCommand(node, cmd, strict=True, opts=None, tty=True):
   """Builds SSH command to be executed.
 
   @type node: string
@@ -160,9 +160,14 @@ def GetSSHCommand(node, cmd, strict=True, opts=None):
   @param strict: whether to enable strict host key checking
   @type opts: list
   @param opts: list of additional options
+  @type tty: Bool
+  @param tty: If we should use tty
 
   """
-  args = [ 'ssh', '-oEscapeChar=none', '-oBatchMode=yes', '-l', 'root', '-t' ]
+  args = ["ssh", "-oEscapeChar=none", "-oBatchMode=yes", "-l", "root"]
+
+  if tty:
+    args.append("-t")
 
   if strict:
     tmp = 'yes'
@@ -227,11 +232,12 @@ def CloseMultiplexers():
     utils.RemoveFile(sname)
 
 
-def GetCommandOutput(node, cmd):
+def GetCommandOutput(node, cmd, tty=True):
   """Returns the output of a command executed on the given node.
 
   """
-  p = StartLocalCommand(GetSSHCommand(node, cmd), stdout=subprocess.PIPE)
+  p = StartLocalCommand(GetSSHCommand(node, cmd, tty=tty),
+                        stdout=subprocess.PIPE)
   AssertEqual(p.wait(), 0)
   return p.stdout.read()
 
-- 
GitLab