Skip to content

Commit

Permalink
Test Framework Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chaladak committed Jul 11, 2024
1 parent 17f3457 commit b09effc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
6 changes: 1 addition & 5 deletions tests/e2e-test-framework/framework/propagating_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ def has_failed(self):
return self.exc is not None

def get_target_name(self):
return self.target.__name__

# commented out to satisfy tox
# def join(self, timeout=None):
# super(PropagatingThread, self).join(timeout)
return self.target.__name__
44 changes: 39 additions & 5 deletions tests/e2e-test-framework/framework/ssh.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
from typing import Any, List, Tuple

import logging
import paramiko


class Ssh:
def execute_ssh_command(self, ip_address: str, command: str, username: str, password: str) -> str:
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(ip_address, username=username, password=password)
ssh_client.connect(
self.ip_address, username=self.username, password=self.password)

# pylint: disable=unused-variable
stdin, stdout, stderr = ssh_client.exec_command(command)
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
2 changes: 1 addition & 1 deletion tests/e2e-test-framework/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest==8.2.1
pytest-html-reporter==0.2.9
kubernetes==29.0.0
tox
tox==4.14.2
flake8==7.0.0
pylint==3.2.2
paramiko==3.4.0
Expand Down

0 comments on commit b09effc

Please sign in to comment.