Skip to content

Commit

Permalink
Remove duplicate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ggediminass committed Dec 20, 2024
1 parent e86618a commit c8c0890
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 55 deletions.
52 changes: 0 additions & 52 deletions test/qa/lib/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, hostname: str, username: str, password: str):
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

self.daemon = self.Daemon(self)
self.io = self.IO(self)
self.meshnet = self.Meshnet(self)
self.network = self.Network(self)

Expand Down Expand Up @@ -60,57 +59,6 @@ def is_running(self):
else:
return True

class IO:
def __init__(self, ssh_class_instance):
self.ssh_class_instance: Ssh = ssh_class_instance

def get_file_hash(self, file_path: str) -> str:
return self.ssh_class_instance.exec_command(f"{lib.FILE_HASH_UTILITY} {file_path}").split()[0]

def create_directory(self, file_count: int, name_suffix: str = "", parent_dir: str = "", file_size: str = "1K") -> Directory:
"""
Creates a temporary directory on remote peer and populates it with a specified number of files.
Args:
file_count (int): The number of files to create in the directory.
name_suffix (str, optional): A suffix to append to the filenames. Defaults to an empty string.
parent_dir (str | None, optional): The parent directory where the temporary directory will be created.
If None, the system default temporary directory is used. Defaults to None.
file_size (str, optional): The size of each file to be created, specified using typical file size notation
(e.g., "1K", "128M"). Defaults to "1K".
Returns:
Directory: A Directory object containing:
- dir_path: Path to the created directory.
- paths: Full paths to the created files.
- transfer_paths: File paths with leading directories removed.
- filenames: Names of the created files.
"""
dir_path = self.ssh_class_instance.exec_command(f"mktemp -d {f'{parent_dir}/tmp.XXXXXX' if parent_dir else ''}").split()[0]
paths = []
transfer_paths = []
filenames = []
filehashes = []

for file_number in range(file_count):
filename = f"file_{file_number}{name_suffix}"
path = f"{dir_path}/{filename}"
paths.append(path)
# in transfer, files are displayed with leading directory only, i.e /tmp/dir/file becomes dir/file
transfer_paths.append(path.removeprefix("/tmp/"))
filenames.append(filename)

disallowed_filesize = ["G", "T", "P", "E", "Z", "Y"]
for size in disallowed_filesize:
if size in file_size:
raise ValueError("Specified file size is too big. Specify either (K)ilobytes or (M)egabytes")

self.ssh_class_instance.exec_command(f"fallocate -l {file_size} {dir_path}/{filename}")

hash_output = self.ssh_class_instance.exec_command(f"sha256sum {path}").strip().split()[0] # Only take the hash part of the output
filehashes.append(hash_output)

return Directory(dir_path, paths, transfer_paths, filenames, filehashes)

class Network:
def __init__(self, ssh_class_instance):
self.ssh_class_instance: Ssh = ssh_class_instance
Expand Down
6 changes: 3 additions & 3 deletions test/qa/test_fileshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,14 +1165,14 @@ def test_autoaccept(transfer_entity: fileshare.FileSystemEntity):

host_address = peer_list.get_this_device().ip

wdir = ssh_client.io.create_directory(0)
wfolder = ssh_client.io.create_directory(2, parent_dir=wdir.dir_path)
wdir = fileshare.create_directory(0, ssh_client=ssh_client)
wfolder = fileshare.create_directory(2, parent_dir=wdir.dir_path, ssh_client=ssh_client)

if transfer_entity == fileshare.FileSystemEntity.FILE:
path = wfolder.paths[0]
expected_files = [wfolder.filenames[0]]
elif transfer_entity == fileshare.FileSystemEntity.FOLDER_WITH_FILES:
wfolder = ssh_client.io.create_directory(2)
wfolder = fileshare.create_directory(2, ssh_client=ssh_client)
path = wfolder.dir_path
expected_files = wfolder.transfer_paths
elif transfer_entity == fileshare.FileSystemEntity.DIRECTORY_WITH_FOLDERS:
Expand Down

0 comments on commit c8c0890

Please sign in to comment.