Skip to content

Commit

Permalink
Merge pull request #73 from jmtd/execute-return-type
Browse files Browse the repository at this point in the history
_execute: return tuple of success, logs
  • Loading branch information
jmtd authored Nov 28, 2024
2 parents e7e9c72 + 972b8ce commit ca379e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
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

0 comments on commit ca379e0

Please sign in to comment.