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

_execute: return tuple of success, logs #73

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
7 changes: 3 additions & 4 deletions steps/s2i_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def s2i_inner(context, application, path='.', env="", incremental=False, tag="ma
)
logger.info("Executing new S2I build with the command [%s]..." % command)

output = _execute(command)
if output:
context.config.userdata['s2i_build_log'] = output
return output
success, output = _execute(command)
context.config.userdata['s2i_build_log'] = output
return success


@given(u's2i build {application} from {path} without running')
Expand Down
14 changes: 6 additions & 8 deletions steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import select
import socket
import fcntl
from typing import Tuple

from behave import then, given
from container import ExecException
Expand All @@ -15,7 +16,7 @@
TIMEOUT = int(os.getenv('BEHAVE_TIMEOUT', '30'))


def _execute(command, log_output=True):
def _execute(command, log_output=True) -> Tuple[bool, str]:
"""
Helper method to execute a shell command and redirect the logs to logger
with proper log level.
Expand Down Expand Up @@ -44,8 +45,8 @@ def _execute(command, log_output=True):
fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK,
)

out = ""
if log_output:
out = ""

while proc.poll() is None:
readx = select.select([proc.stdout, proc.stderr], [], [])[0]
Expand All @@ -63,16 +64,13 @@ def _execute(command, log_output=True):
if retcode != 0:
logger.error(
"Command '%s' returned code was %s, check logs" % (command, retcode))
return False
return False, out

except subprocess.CalledProcessError:
logger.error("Command '%s' failed, check logs" % command)
return False
return False, out

if log_output:
return out
else:
return True
return True, out


@then(u'check that page is not served')
Expand Down