From 9c9704b6d2658bc6288aafeaeb8af9581f7fc053 Mon Sep 17 00:00:00 2001 From: Deepak S Date: Thu, 8 Dec 2016 13:57:13 +0530 Subject: ssh.py: add flag to request for a pseudo terminal (pty) for ssh connection For some VNFs we may want to send periodic commands, for example to print statistics etc. When you open a SSH connection, request a pseudo terminal (pty) which allows passing of control characters to the connection. JIRA: YARDSTICK-453 Change-Id: Ibfd4164e745f005d0e29f6efdc63076e1e220b60 Signed-off-by: Deepak S --- yardstick/ssh.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/yardstick/ssh.py b/yardstick/ssh.py index 46d53b7d2..2ba6de92e 100644 --- a/yardstick/ssh.py +++ b/yardstick/ssh.py @@ -157,7 +157,7 @@ class SSH(object): def run(self, cmd, stdin=None, stdout=None, stderr=None, raise_on_error=True, timeout=3600, - keep_stdin_open=False): + keep_stdin_open=False, pty=False): """Execute specified command on the server. :param cmd: Command to be executed. @@ -171,6 +171,10 @@ class SSH(object): Default 1 hour. No timeout if set to 0. :param keep_stdin_open: don't close stdin on empty reads :type keep_stdin_open: bool + :param pty: Request a pseudo terminal for this connection. + This allows passing control characters. + Default False. + :type pty: bool """ client = self._get_client() @@ -181,14 +185,16 @@ class SSH(object): return self._run(client, cmd, stdin=stdin, stdout=stdout, stderr=stderr, raise_on_error=raise_on_error, timeout=timeout, - keep_stdin_open=keep_stdin_open) + keep_stdin_open=keep_stdin_open, pty=pty) def _run(self, client, cmd, stdin=None, stdout=None, stderr=None, raise_on_error=True, timeout=3600, - keep_stdin_open=False): + keep_stdin_open=False, pty=False): transport = client.get_transport() session = transport.open_session() + if pty: + session.get_pty() session.exec_command(cmd) start_time = time.time() -- cgit 1.2.3-korg