Skip to content

Commit

Permalink
fix: Podman error handling while connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Sunglasses committed Feb 16, 2025
1 parent c8351ce commit c595cfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions podman/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def __init__(self, **kwargs) -> None:
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
api_kwargs["base_url"] = "http+unix://" + path
self.api = APIClient(**api_kwargs)
self.system = SystemManager(client=self.api)

# Check connection to Podman service
try:
self.system.ping()
except Exception as e:
error_msg = "Failed to connect to Podman service"
raise PodmanConnectionError(message=error_msg, original_error=e)

def __enter__(self) -> "PodmanClient":
return self
Expand Down
4 changes: 3 additions & 1 deletion podman/tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def consume_lines(pipe, consume_fn):
def consume(line: str):
logger.debug(line.strip("\n") + f" refid={self.reference_id}")

self.proc = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # pylint: disable=consider-using-with
self.proc = subprocess.Popen(
self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
) # pylint: disable=consider-using-with
threading.Thread(target=consume_lines, args=[self.proc.stdout, consume]).start()

if not check_socket:
Expand Down

0 comments on commit c595cfc

Please sign in to comment.