Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add returncode to dcos_cli.exec_command #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dcos_test_utils/dcos_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def exec_command(self, cmd: str, stdin=None) -> tuple:
:type cmd: str
:param stdin: File to use for stdin
:type stdin: File
:returns: A tuple with stdout and stderr
:rtype: (str, str)
:returns: A tuple with stdout, stderr and returncode
:rtype: (str, str, int)
"""

log.info('CMD: {!r}'.format(cmd))
Expand All @@ -126,7 +126,7 @@ def exec_command(self, cmd: str, stdin=None) -> tuple:
log.info('STDOUT: {}'.format(stdout))
log.info('STDERR: {}'.format(stderr))

return (stdout, stderr)
return (stdout, stderr, process.returncode)

def setup_enterprise(
self,
Expand Down
7 changes: 5 additions & 2 deletions tests/test_dcos_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@

def test_exec_command(caplog):
cli = dcos_cli.DcosCli('')
stdout, stderr = cli.exec_command(
stdout, stderr, returncode = cli.exec_command(
['/bin/sh', '-c', 'echo "hello, world!"']
)
assert stdout == 'hello, world!\n'
assert stderr == ''
assert any(rec.message.startswith('CMD:') for rec in caplog.records)
assert any(rec.message.startswith('STDOUT:') for rec in caplog.records)
assert any(rec.message.startswith('STDERR:') for rec in caplog.records)
assert returncode == 0


def test_exec_command_fail(caplog):
cli = dcos_cli.DcosCli('')
with pytest.raises(subprocess.CalledProcessError):
cli.exec_command(['/bin/sh', '-c', 'does-not-exist'])
_stdout, _stderr, returncode = cli.exec_command(['/bin/sh', '-c', 'does-not-exist'])
assert returncode != 0

assert any(rec.message.startswith('CMD:') for rec in caplog.records)
assert any(rec.message.startswith('STDERR:') for rec in caplog.records)