Skip to content

Commit 6e6eaec

Browse files
committed
Return tuple instead of dict in exec_run
Signed-off-by: Joffrey F <[email protected]>
1 parent b0cc4b5 commit 6e6eaec

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

docker/models/containers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
150150
workdir (str): Path to working directory for this exec session
151151
152152
Returns:
153-
dict:
153+
(tuple): A tuple of (exit_code, output)
154+
exit_code: (int):
155+
Exit code for the executed command
154156
output: (generator or str):
155157
If ``stream=True``, a generator yielding response chunks.
156158
If ``socket=True``, a socket object for the connection.
157159
A string containing response data otherwise.
158-
exit_code: (int):
159-
Exited code of execution
160160
161161
Raises:
162162
:py:class:`docker.errors.APIError`
@@ -173,10 +173,7 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
173173
exit_code = 0
174174
if stream is False:
175175
exit_code = self.client.api.exec_inspect(resp['Id'])['ExitCode']
176-
return {
177-
'exit_code': exit_code,
178-
'output': exec_output
179-
}
176+
return (exit_code, exec_output)
180177

181178
def export(self):
182179
"""

tests/integration/models_containers_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def test_exec_run_success(self):
189189
)
190190
self.tmp_containers.append(container.id)
191191
exec_output = container.exec_run("cat /test")
192-
assert exec_output["output"] == b"hello\n"
193-
assert exec_output["exit_code"] == 0
192+
assert exec_output[0] == 0
193+
assert exec_output[1] == b"hello\n"
194194

195195
def test_exec_run_failed(self):
196196
client = docker.from_env(version=TEST_API_VERSION)
@@ -199,7 +199,7 @@ def test_exec_run_failed(self):
199199
)
200200
self.tmp_containers.append(container.id)
201201
exec_output = container.exec_run("docker ps")
202-
assert exec_output["exit_code"] == 126
202+
assert exec_output[0] == 126
203203

204204
def test_kill(self):
205205
client = docker.from_env(version=TEST_API_VERSION)

tests/unit/models_containers_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,15 @@ def test_exec_run(self):
400400
client.api.exec_start.assert_called_with(
401401
FAKE_EXEC_ID, detach=False, tty=False, stream=True, socket=False
402402
)
403+
404+
def test_exec_run_failure(self):
405+
client = make_fake_client()
406+
container = client.containers.get(FAKE_CONTAINER_ID)
403407
container.exec_run("docker ps", privileged=True, stream=False)
404408
client.api.exec_create.assert_called_with(
405409
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
406-
stdin=False, tty=False, privileged=True, user='', environment=None
407-
)
408-
client.api.exec_start.assert_called_with(
409-
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False
410+
stdin=False, tty=False, privileged=True, user='', environment=None,
411+
workdir=None
410412
)
411413
client.api.exec_start.assert_called_with(
412414
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False

0 commit comments

Comments
 (0)