import subprocess as sp import paramiko import pytest from os import getenv @pytest.fixture def server(): try: s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) s.connect(hostname = getenv("host"), username = getenv("user"), password = getenv("pass")) print("con suc") _, _, _ = s.exec_command("iperf3 -s") yield True except paramiko.AuthenticationException: print("aut fal") yield False except paramiko.SSHException as e: print(f"err {e}") yield False finally: s.close() @pytest.fixture def client(server): assert server res = "" p = sp.Popen( ["iperf3", "--forceflush", "-i", "1", "-c", getenv("host")], stdout = sp.PIPE, stderr = sp.PIPE) while True: l = p.stdout.readline() if l: res += l.decode("UTF-8") if p.poll() != None: break if p.stderr.read(): return False else: return res