summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2018-01-26 14:21:23 -0800
committerJoffrey F <joffrey@docker.com>2018-01-26 14:21:23 -0800
commit6e6eaece81ebeb43f644a14e498189a9d27d647e (patch)
tree9355f80f59d6962a33aeb45c6b974e6a53eec5dc
parentb0cc4b552070f721fa377b88bd572809429ac3d1 (diff)
downloaddocker-py-6e6eaece81ebeb43f644a14e498189a9d27d647e.tar.gz
Return tuple instead of dict in exec_run
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/models/containers.py11
-rw-r--r--tests/integration/models_containers_test.py6
-rw-r--r--tests/unit/models_containers_test.py10
3 files changed, 13 insertions, 14 deletions
diff --git a/docker/models/containers.py b/docker/models/containers.py
index 343535b..9644b00 100644
--- a/docker/models/containers.py
+++ b/docker/models/containers.py
@@ -150,13 +150,13 @@ class Container(Model):
workdir (str): Path to working directory for this exec session
Returns:
- dict:
+ (tuple): A tuple of (exit_code, output)
+ exit_code: (int):
+ Exit code for the executed command
output: (generator or str):
If ``stream=True``, a generator yielding response chunks.
If ``socket=True``, a socket object for the connection.
A string containing response data otherwise.
- exit_code: (int):
- Exited code of execution
Raises:
:py:class:`docker.errors.APIError`
@@ -173,10 +173,7 @@ class Container(Model):
exit_code = 0
if stream is False:
exit_code = self.client.api.exec_inspect(resp['Id'])['ExitCode']
- return {
- 'exit_code': exit_code,
- 'output': exec_output
- }
+ return (exit_code, exec_output)
def export(self):
"""
diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py
index fd052be..3c33cb0 100644
--- a/tests/integration/models_containers_test.py
+++ b/tests/integration/models_containers_test.py
@@ -189,8 +189,8 @@ class ContainerTest(BaseIntegrationTest):
)
self.tmp_containers.append(container.id)
exec_output = container.exec_run("cat /test")
- assert exec_output["output"] == b"hello\n"
- assert exec_output["exit_code"] == 0
+ assert exec_output[0] == 0
+ assert exec_output[1] == b"hello\n"
def test_exec_run_failed(self):
client = docker.from_env(version=TEST_API_VERSION)
@@ -199,7 +199,7 @@ class ContainerTest(BaseIntegrationTest):
)
self.tmp_containers.append(container.id)
exec_output = container.exec_run("docker ps")
- assert exec_output["exit_code"] == 126
+ assert exec_output[0] == 126
def test_kill(self):
client = docker.from_env(version=TEST_API_VERSION)
diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py
index f94c5cf..d7457ba 100644
--- a/tests/unit/models_containers_test.py
+++ b/tests/unit/models_containers_test.py
@@ -400,13 +400,15 @@ class ContainerTest(unittest.TestCase):
client.api.exec_start.assert_called_with(
FAKE_EXEC_ID, detach=False, tty=False, stream=True, socket=False
)
+
+ def test_exec_run_failure(self):
+ client = make_fake_client()
+ container = client.containers.get(FAKE_CONTAINER_ID)
container.exec_run("docker ps", privileged=True, stream=False)
client.api.exec_create.assert_called_with(
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
- stdin=False, tty=False, privileged=True, user='', environment=None
- )
- client.api.exec_start.assert_called_with(
- FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False
+ stdin=False, tty=False, privileged=True, user='', environment=None,
+ workdir=None
)
client.api.exec_start.assert_called_with(
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False