Skip to content

Commit

Permalink
[ISSUE-1190]: remote command executor for e2e (ssh) (#1191)
Browse files Browse the repository at this point in the history
Signed-off-by: Dawid Korzepa <[email protected]>
  • Loading branch information
korzepadawid authored Jul 2, 2024
1 parent 9a1b730 commit 5d21eab
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/e2e-test-framework/framework/ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging
import paramiko
from typing import Any, List, Tuple


class SSHCommandExecutor:
"""
A class for executing SSH commands on a remote server.
Args:
ip_address (str): The IP address of the SSH server.
username (str): The username for authentication.
password (str): The password for authentication.
"""

def __init__(self, ip_address: str, username: str, password: str) -> None:
"""
Initializes the SSHCommandExecutor with the given IP address, username, and password.
"""
self.ip_address = ip_address
self.username = username
self.password = password

def exec(self, command: str) -> Tuple[str, List[Any]]:
"""
Executes an SSH command on the remote server.
Args
command (str): The command to execute.
Returns:
str: The output of the executed command.
list: A list of error messages, if any, from the executed command.
"""
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(
self.ip_address, username=self.username, password=self.password)

logging.info(f"SSH connected, executing command: {command}")
_, stdout, stderr = ssh_client.exec_command(command)
output = stdout.read().decode().strip()
error = stderr.readlines()

ssh_client.close()

if len(error) > 0:
logging.error(f"SSH command {command} failed: {error}")

return output, error
1 change: 1 addition & 0 deletions tests/e2e-test-framework/framework/sts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from typing import List

class STS:
def __init__(self, namespace: str, name: str, replicas: int = 1) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/e2e-test-framework/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ kubernetes==29.0.0
tox==4.14.2
flake8==7.0.0
pylint==3.1.0
paramiko==3.4.0

0 comments on commit 5d21eab

Please sign in to comment.