Best Python code snippet using lisa_python
iperf3.py
Source:iperf3.py  
...90        posix_os.install_packages("iperf3")91        if not self._check_exists():92            self._install_from_src()93        return self._check_exists()94    def run_as_server_async(95        self,96        port: int = 0,97        report_unit: str = "",98        report_periodic: int = 0,99        use_json_format: bool = False,100        one_connection_only: bool = False,101        daemon: bool = True,102    ) -> Process:103        # -s: run iperf3 as server mode104        # -D: run iperf3 as a daemon105        cmd = " -s"106        if daemon:107            cmd += " -D "108        if one_connection_only:109            cmd += " -1 "110        if use_json_format:111            cmd += " -J "112        if report_periodic:113            cmd += f" -i{report_periodic} "114        if report_unit:115            cmd += f" -f {report_unit} "116        if port:117            cmd += f" -p {port} "118        process = self.node.execute_async(119            f"{self.command} {cmd}", shell=True, sudo=True120        )121        return process122    def run_as_server(123        self,124        port: int = 0,125        report_unit: str = "",126        report_periodic: int = 0,127        use_json_format: bool = False,128        one_connection_only: bool = False,129        daemon: bool = True,130    ) -> None:131        # -s: run iperf3 as server mode132        # -D: run iperf3 as a daemon133        # -p: server port to listen on/connect to134        # -f: [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits135        # -i: seconds between periodic throughput reports136        # -1: handle one client connection then exit137        # -J: output in JSON format138        process = self.run_as_server_async(139            port,140            report_unit,141            report_periodic,142            use_json_format,143            one_connection_only,144            daemon,145        )146        process.wait_result(147            expected_exit_code=0,148            expected_exit_code_failure_message="fail to launch iperf3 server",149        )150    @retry(tries=10, delay=2)151    def run_as_client_async(  # noqa: C901152        self,...common.py
Source:common.py  
...107    if len(environment.nodes) >= 2:108        server_node = cast(RemoteNode, environment.nodes[1])109    iperf3_server = server_node.tools[Iperf3]110    iperf3_client = client_node.tools[Iperf3]111    iperf3_server.run_as_server_async()112    iperf3_client_result = iperf3_client.run_as_client_async(113        server_ip=server_node.internal_address,114        parallel_number=8,115        run_time_seconds=120,116    )117    result_before_hb = iperf3_client_result.wait_result()118    kill = server_node.tools[Kill]119    kill.by_name("iperf3")120    return iperf3_client.get_sender_bandwidth(result_before_hb.stdout)121def cleanup_env(environment: Environment) -> None:122    remote_node = cast(RemoteNode, environment.nodes[0])123    startstop = remote_node.features[StartStop]124    startstop.start()125    for node in environment.nodes.list():...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
