Skip to content

Commit

Permalink
Add default session class if backend couldn't be imported.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapaioa committed Apr 8, 2024
1 parent dfe6dff commit 33d6dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion broker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
not these classes directly.
"""
from contextlib import contextmanager
import os
from pathlib import Path
import tempfile

Expand All @@ -23,6 +22,7 @@
SSH_BACKEND = settings.SSH_BACKEND

logger.info(f"{SSH_BACKEND=}")

try:
if SSH_BACKEND == "ansible-pylibssh":
from broker.ssh_session_pylibssh import InteractiveShell, Session
Expand All @@ -31,12 +31,16 @@
elif SSH_BACKEND in ("ssh2-python", "ssh2-python312"):
from broker.ssh_session_ssh2 import InteractiveShell, Session # noqa: F401
else:
from broker.ssh_session import BaseSession as Session

logger.warning(
f"SSH backend {SSH_BACKEND!r} not supported.\n"
"Supported ssh backends:\n"
f"{SSH_BACKENDS}"
)
except ImportError:
from broker.ssh_session import BaseSession as Session # noqa: F401

logger.warning(
f"{SSH_BACKEND} is not installed.\n"
"ssh actions will not work.\n"
Expand Down
4 changes: 4 additions & 0 deletions broker/ssh_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ def _create_connect_socket(host, port, timeout, ipv6=False, ipv4_fallback=True,
else:
sock.connect((host, port))
return sock, ipv6


class BaseSession:
"""Default wrapper around ssh backend's auth/connection system."""

0 comments on commit 33d6dff

Please sign in to comment.