waft.system.clients.ssh_client.ssh_client module

SshClient is an internal module that represents a client for ssh connections and commands

class waft.system.clients.ssh_client.ssh_client.SshClient(connection_details: ConnectionDetails)

Bases: ClientBase

SshClient is a class that acts as an ssh client where ssh commands can be executed from

bind_remote_port_to_local(remote_port: int, local_port: int, remote_host: str = 'localhost', local_host: str = 'localhost')

Bind a port on the remote machine to a port on localhost. This is intended for use on systems behind a proxy

Parameters:
  • remote_port – Port number on remote machine to bind to a port on localhost

  • local_port – Port on test runner that should be bound to given remote port

  • remote_host – Host on remote port for which the given port is to be forwarded (Default: localhost)

  • local_host – Local host to which given port should be forwarded (Default: localhost)

exec_command(command: list, input: str | list[str] | None = None, retry_handler: RetryHandler | None = None, expected_exit_code: int | None = 0, auto_raise: bool = True, custom_exception: Type[Exception] | None = None, custom_exception_msg: str | None = None, **kwargs) Result

Executes a command on a remote SSH server with configurable retry logic.

This method will automatically raise an exception if the returned command status is not equal to the expected_exit_code and auto_raise is set to True.

Parameters:
  • command (list[str]) – The system command to execute.

  • input (Optional[str | list[str]]) – Command input.

  • retry_handler (Optional[RetryHandler]) – An instance of RetryHandler for retrying command execution.

  • None. (expected_exit_code. Defaults to)

  • expected_exit_code (Optional[int]) – The expected exit code of the command. Defaults to 0.

  • auto_raise (bool) – Whether to automatically raise an exception if the command’s exit code does not match

  • True. (the expected_exit_code. Defaults to)

  • custom_exception (Optional[Type[Exception]]) – Custom exception to raise if the command status is not the

  • None.

  • custom_exception_msg (Optional[str]) – Custom message to include with the custom exception. Defaults to None.

  • **kwargs – Custom keyword arguments for client execution

Returns:

An object representing the response of the SSH command.

Return type:

Result

Raises:
  • RuntimeError – If the command execution fails after retries and auto_raise is True.

  • custom_exception – If provided, raised when the command’s exit code does not match the expected_exit_code

  • and auto_raise is True.

get_file(remote_file_path: PurePath, local_file_path: Path) None

Downloads a file from the remote server to the local machine.

property is_unix: bool

Returns whether or not the client is a unix system

reset_connection()

Reset connection for the current session

send_file(remote_file_path: PurePath, local_file_path: Path) None

Uploads a file from the local machine to the remote server.

property sftp: SftpManager

Returns an initialized SFTP connection

property ssh: SshConnection

Returns an initialized SSH connection

test_connection() bool

Tests the SSH connection by attempting to open a connection and execute a simple command.