Best Python code snippet using lisa_python
performance.py
Source:performance.py
...343 xdpdump.start_async(nic_name=receiver_nic.upper, timeout=0)344 pktgen_result = self._send_packets(345 is_multi_thread, sender, pktgen, sender_nic, receiver_nic346 )347 self._wait_packets_proceeded(348 log, receiver, receiver_nic, original_dropped_count349 )350 finally:351 receiver_kill = receiver.tools[Kill]352 receiver_kill.by_name("xdpdump")353 # capture stats to calculate delta354 dropped_count = get_dropped_count(355 node=receiver,356 nic=receiver_nic,357 previous_count=original_dropped_count,358 log=log,359 )360 log.debug(361 f"sender pktgen result: {pktgen_result}, "362 f"dropped on receiver: {dropped_count}"363 )364 self._check_threshold(365 pktgen_result.sent_count, dropped_count, threshold, "dropped packets"366 )367 assert_that(pktgen_result.pps).described_as(368 "pps must be greater than 1M."369 ).is_greater_than_or_equal_to(1000000)370 def _execute_tx_forward_test(371 self,372 environment: Environment,373 log: Logger,374 is_multi_threads: bool = False,375 threshold: float = _default_received_threshold,376 ) -> None:377 sender = environment.nodes[0]378 forwarder = environment.nodes[1]379 receiver = environment.nodes[2]380 # install pktgen on sender381 try:382 pktgen = sender.tools[Pktgen]383 except UnsupportedKernelException as identifier:384 raise SkippedException(identifier)385 # install xdp dump on forwarder and receiver386 forwarder_xdpdump, receiver_xdpdump = run_in_parallel(387 [388 partial(get_xdpdump, forwarder),389 partial(get_xdpdump, receiver),390 ],391 log=log,392 )393 sender_nic = sender.nics.get_nic_by_index(1)394 forwarder_nic = forwarder.nics.get_nic_by_index(1)395 receiver_nic = receiver.nics.get_nic_by_index(1)396 run_in_parallel(397 [398 partial(399 forwarder_xdpdump.make_on_forwarder_role,400 forwarder_nic=forwarder_nic,401 receiver_nic=receiver_nic,402 ),403 partial(404 receiver_xdpdump.make_by_build_type, build_type=BuildType.PERF_DROP405 ),406 ]407 )408 # capture existing stats to calculate delta409 original_forwarded_count = get_forwarded_count(410 node=forwarder,411 nic=forwarder_nic,412 previous_count=0,413 log=log,414 )415 original_dropped_count = get_dropped_count(416 node=receiver,417 nic=receiver_nic,418 previous_count=0,419 log=log,420 )421 try:422 # start xdpdump423 forwarder_xdpdump.start_async(nic_name=forwarder_nic.upper, timeout=0)424 receiver_xdpdump.start_async(nic_name=receiver_nic.upper, timeout=0)425 pktgen_result = self._send_packets(426 is_multi_threads, sender, pktgen, sender_nic, forwarder_nic427 )428 self._wait_packets_proceeded(429 log, receiver, receiver_nic, original_dropped_count430 )431 finally:432 # kill xdpdump processes.433 forwarder_kill = forwarder.tools[Kill]434 forwarder_kill.by_name("xdpdump")435 receiver_kill = receiver.tools[Kill]436 receiver_kill.by_name("xdpdump")437 # capture stats to calculate delta438 dropped_count = get_dropped_count(439 node=receiver,440 nic=receiver_nic,441 previous_count=original_dropped_count,442 log=log,443 )444 forwarded_count = get_forwarded_count(445 node=forwarder,446 nic=forwarder_nic,447 previous_count=original_forwarded_count,448 log=log,449 )450 # In some nodes like synthetic nic, there is no forward counter,451 # so count it by dropped count.452 validate_count = forwarded_count453 if not validate_count:454 validate_count = dropped_count455 log.debug(456 f"sender pktgen result: {pktgen_result}, "457 f"on forwarder: {forwarded_count}, "458 f"on receiver: {dropped_count}"459 )460 self._check_threshold(461 pktgen_result.sent_count, validate_count, threshold, "forwarded packets"462 )463 def _check_threshold(464 self, expected_count: int, actual_count: int, threshold: float, packet_name: str465 ) -> None:466 assert_that(actual_count / expected_count).described_as(467 f"{packet_name} rate should be above the threshold. "468 f"expected count: {expected_count}, actual count: {actual_count}"469 ).is_greater_than_or_equal_to(threshold)470 def _wait_packets_proceeded(471 self, log: Logger, receiver: Node, receiver_nic: NicInfo, original_count: int472 ) -> int:473 # wait until the forwarded count is not increased, it means there is474 # no more packets in queue.475 current_count = 0476 delta_count = 1477 while delta_count:478 sleep(1)479 previous_count = current_count480 current_count = get_dropped_count(481 node=receiver,482 nic=receiver_nic,483 previous_count=original_count,484 log=log,...
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!!