This is an automated email from the ASF dual-hosted git repository. klueska pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push: new 6d0cbda Added 'popen_tty()' to test util functions for the new CLI. 6d0cbda is described below commit 6d0cbda19ad8a5453c960e37424a38c4be1924a9 Author: Armand Grillet <agril...@mesosphere.io> AuthorDate: Fri Nov 2 19:08:24 2018 -0400 Added 'popen_tty()' to test util functions for the new CLI. This code was pulled directly from: https://github.com/dcos/dcos-core-cli/blob/ 7fd55421939a7782c237e2b8719c0fe2f543acd7/ python/lib/dcoscli/dcoscli/test/common.py This function will be used by tests requiring a TTY. This will be the case for tests concerning the 'task attach' subcommand. Review: https://reviews.apache.org/r/69116/ --- src/python/cli_new/lib/cli/tests/base.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/python/cli_new/lib/cli/tests/base.py b/src/python/cli_new/lib/cli/tests/base.py index 7fd39af..5d9cf01 100644 --- a/src/python/cli_new/lib/cli/tests/base.py +++ b/src/python/cli_new/lib/cli/tests/base.py @@ -20,6 +20,7 @@ Set of classes and helper functions for building unit tests for the Mesos CLI. import io import os +import pty import shutil import subprocess import sys @@ -471,3 +472,29 @@ def exec_command(command, env=None, stdin=None, timeout=None): raise CLIException("Timeout expired: {error}".format(error=exception)) return (process.returncode, stdout, stderr) + + +def popen_tty(cmd, shell=True): + """ + Open a process with stdin connected to a pseudo-tty. + + :param cmd: command to run + :type cmd: str + :returns: (Popen, master) tuple, where master is the master side + of the of the tty-pair. It is the responsibility of the caller + to close the master fd, and to perform any cleanup (including + waiting for completion) of the Popen object. + :rtype: (Popen, int) + """ + master, slave = pty.openpty() + # pylint: disable=subprocess-popen-preexec-fn + proc = subprocess.Popen(cmd, + stdin=slave, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + preexec_fn=os.setsid, + close_fds=True, + shell=shell) + os.close(slave) + + return (proc, master)