Make it possible to disable tty in qa_utils.GetCommandOutput
authorRené Nussbaumer <rn@google.com>
Wed, 2 Feb 2011 10:31:26 +0000 (11:31 +0100)
committerRené Nussbaumer <rn@google.com>
Thu, 3 Feb 2011 09:42:27 +0000 (10:42 +0100)
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

index a5cc2cd..be37818 100644 (file)
@@ -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()