#2 Add get_pty option to run command with pseudo terminal
Closed 6 years ago by mrniranjan. Opened 7 years ago by mrniranjan.
mrniranjan/python-pytest-multihost master  into  master

file modified
+3 -2
@@ -201,7 +201,7 @@ 

  

      def run_command(self, argv, set_env=True, stdin_text=None,

                      log_stdout=True, raiseonerr=True,

-                     cwd=None):

+                     cwd=None, get_pty=False):

          """Run the given command on this host

  

          Returns a Command instance. The command will have already run in the
@@ -218,8 +218,9 @@ 

          :param raiseonerr: If true, an exception will be raised if the command

                             does not exit with return code 0

          :param cwd: The working directory for the command

+         :param get_pty: If True, request a pseudo-terminal from the server.

          """

-         command = self.transport.start_shell(argv, log_stdout=log_stdout)

+         command = self.transport.start_shell(argv, log_stdout=log_stdout, get_pty=get_pty)

          # Set working directory

          if cwd is None:

              cwd = self.test_dir

@@ -248,13 +248,13 @@ 

          self.log.info('MKDIR %s', path)

          self.sftp.mkdir(path)

  

-     def start_shell(self, argv, log_stdout=True):

+     def start_shell(self, argv, log_stdout=True, get_pty=False):

          logger_name = self.get_next_command_logger_name()

          ssh = self._transport.open_channel('session')

          self.log.info('RUN %s', argv)

          return SSHCommand(ssh, argv, logger_name=logger_name,

                            log_stdout=log_stdout,

-                           get_logger=self.host.config.get_logger)

+                           get_logger=self.host.config.get_logger, get_pty=get_pty)

  

      def get_file(self, remotepath, localpath):

          self.log.debug('GET %s', remotepath)
@@ -432,7 +432,7 @@ 

  class SSHCommand(Command):

      """Command implementation for ParamikoTransport and OpenSSHTranspport"""

      def __init__(self, ssh, argv, logger_name, log_stdout=True,

-                  collect_output=True, encoding='utf-8', get_logger=None):

+                  collect_output=True, encoding='utf-8', get_logger=None, get_pty=False):

          super(SSHCommand, self).__init__(argv, logger_name,

                                           log_stdout=log_stdout,

                                           get_logger=get_logger)
@@ -443,6 +443,9 @@ 

          self._ssh = ssh

  

          self.log.debug('RUN %s', argv)

+         

+         if get_pty:

+             self._ssh.get_pty()

  

          self._ssh.invoke_shell()

          def wrap_file(file, encoding):

I'd like to see a test for this functionality. I'll get to writing one when I find some time.

I can write a test, i am thinking what command i can use which is available locally which will test this functionality. I tested this specifically with atomic/docker commands .

Pull-Request has been closed by mrniranjan

6 years ago