Skip to content

Commit

Permalink
_execute: return tuple of success, logs
Browse files Browse the repository at this point in the history
Adjust _execute to return the success/failure status of the command
and the commands output as two separate values, paired.

Adjust s2i_inner to reflect the altered return type, and to assign
the returned output to s2i_build_log in the success and failure
cases.

Fixes #72.

Signed-off-by: Jonathan Dowland <[email protected]>
  • Loading branch information
jmtd committed Nov 28, 2024
1 parent e7e9c72 commit ef98123
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 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
11 changes: 4 additions & 7 deletions steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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 +63,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 ef98123

Please sign in to comment.