You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by kl...@apache.org on 2018/10/22 13:31:08 UTC

[mesos] branch master updated: Added 'exec_command' to test util functions for the new CLI.

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 963de3b  Added 'exec_command' to test util functions for the new CLI.
963de3b is described below

commit 963de3b1811ef569449102192d40ca2cbed73b3c
Author: Armand Grillet <ag...@mesosphere.io>
AuthorDate: Mon Oct 22 09:28:28 2018 -0400

    Added 'exec_command' to test util functions for the new CLI.
    
    This code was mostly 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 that do not return a specific output
    but an error code, stdout, and stderr. This will be the case for tests
    concerning the 'task exec' and 'task attach' subcommands.
    
    Review: https://reviews.apache.org/r/69114/
---
 src/python/cli_new/lib/cli/tests/base.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/python/cli_new/lib/cli/tests/base.py b/src/python/cli_new/lib/cli/tests/base.py
index 3fb471c..7fd39af 100644
--- a/src/python/cli_new/lib/cli/tests/base.py
+++ b/src/python/cli_new/lib/cli/tests/base.py
@@ -445,3 +445,29 @@ def capture_output(command, argv, extra_args=None):
     sys.stdout = stdout
 
     return output
+
+
+def exec_command(command, env=None, stdin=None, timeout=None):
+    """
+    Execute command.
+    """
+    process = subprocess.Popen(
+        command,
+        stdin=stdin,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+        env=env,
+        universal_newlines=True)
+
+    try:
+        stdout, stderr = process.communicate(timeout=timeout)
+    except subprocess.TimeoutExpired as exception:
+        # The child process is not killed if the timeout expires, so in order
+        # to cleanup properly a well-behaved application should kill the child
+        # process and finish communication.
+        # https://docs.python.org/3.5/library/subprocess.html
+        process.kill()
+        stdout, stderr = process.communicate()
+        raise CLIException("Timeout expired: {error}".format(error=exception))
+
+    return (process.returncode, stdout, stderr)