Skip to content

Commit

Permalink
The container implementation is now sensible to the exited st…
Browse files Browse the repository at this point in the history
…ate.

Fixes #165

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Sep 20, 2023
1 parent 40d9298 commit 838e651
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/165.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``container`` implementation is now sensible to the ``exited`` state when starting containers.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ forced-separate = ["tests"]
docstring-quotes = "double"

[tool.ruff.mccabe]
max-complexity = 20
max-complexity = 25

[tool.ruff.pylint]
max-args = 10
max-branches = 25
max-branches = 35
max-returns = 8

[tool.ruff.pep8-naming]
Expand Down
22 changes: 22 additions & 0 deletions src/saltfactories/daemons/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,28 @@ def start(self, *command, max_start_attempts=None, start_timeout=None): # noqa:
# state, and now it is, we have to re-set the self.container attribute
# so that it gives valid status information
self.container = self.docker_client.containers.get(self.name)

if self.container.status == "exited":
logs = self.container.logs(stdout=True, stderr=True, stream=False)
if isinstance(logs, bytes):
stdout = logs.decode()
stderr = None
else:
stdout = logs[0].decode()
stderr = logs[1].decode()
if stdout and stderr:
log.info("Container Exited. Logs:\n%s\n%s", stdout, stderr)
elif stdout:
log.info("Container Exited. Logs:\n%s", stdout)

try:
self.container.remove(force=True)
self.container.wait()
except APIError:
pass
self.container = None
break

if self.container.status != "running":
time.sleep(0.25)
continue
Expand Down

0 comments on commit 838e651

Please sign in to comment.