Skip to content

Commit

Permalink
container.execute: fix when exec_start completes fast (#60)
Browse files Browse the repository at this point in the history
p.join will return None in two situations: when the timeout is reached,
and if the process has completed already.

Adjust the check so that we throw an exception in the former case but
not the latter.

Signed-off-by: Jonathan Dowland <jdowland@redhat.com>
  • Loading branch information
jmtd authored Mar 23, 2024
1 parent 9eb05de commit 0a2fb44
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions steps/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def startWithCommand(self, **kwargs):
self.running = True
self.ip_address = self.inspect()['NetworkSettings']['IPAddress']

def execute(self, cmd, detach=False):
def execute(self, cmd, detach=False, timeout=60):
""" executes cmd in container and return its output """
self.logger.debug("container.execute(%s,%s)" % (cmd,detach))
inst = d.exec_create(container=self.container, cmd=cmd)
Expand All @@ -161,9 +161,9 @@ def execute(self, cmd, detach=False):
p = ctx.Process(target=lambda q: q.put(d.exec_start(inst, detach=detach)), args=(q,))
p.start()

if None == p.join(60): # timeout in secs
if None == p.join(timeout) and p.exitcode == None:
p.terminate()
raise ExecException("container.execute: timeout reading from exec (command '{}')".format(cmd))
raise ExecException("container.execute: timeout reading from exec_start (command '{}')".format(cmd))

output = q.get()
retcode = d.exec_inspect(inst)['ExitCode']
Expand Down

0 comments on commit 0a2fb44

Please sign in to comment.