Best Python code snippet using lisa_python
dpdksuite.py
Source:dpdksuite.py
...114 def verify_dpdk_ovs(115 self, node: Node, log: Logger, variables: Dict[str, Any]116 ) -> None:117 # initialize DPDK first, OVS requires it built from source before configuring.118 self._force_dpdk_default_source(variables)119 test_kit = initialize_node_resources(node, log, variables, "failsafe")120 # checkout OpenVirtualSwitch121 ovs = node.tools[DpdkOvs]122 # provide ovs build with DPDK tool info and build123 ovs.build_with_dpdk(test_kit.testpmd)124 # enable hugepages needed for dpdk EAL125 init_hugepages(node)126 try:127 # run OVS tests, providing OVS with the NIC info needed for DPDK init128 ovs.setup_ovs(node.nics.get_nic_by_index().pci_slot)129 # validate if OVS was able to initialize DPDK130 node.execute(131 "ovs-vsctl get Open_vSwitch . dpdk_initialized",132 sudo=True,133 expected_exit_code=0,134 expected_exit_code_failure_message=(135 "OVS repoted that DPDK EAL failed to initialize."136 ),137 )138 finally:139 ovs.stop_ovs()140 @TestCaseMetadata(141 description="""142 Install and run ci test for NFF-Go on ubuntu143 """,144 priority=4,145 requirement=simple_requirement(146 min_core_count=8,147 min_nic_count=2,148 network_interface=Sriov(),149 unsupported_features=[Gpu, Infiniband],150 supported_features=[IsolatedResource],151 ),152 )153 def verify_dpdk_nff_go(154 self, node: Node, log: Logger, variables: Dict[str, Any]155 ) -> None:156 try:157 nff_go = node.tools[DpdkNffGo]158 except UnsupportedDistroException as err:159 raise SkippedException(err)160 # hugepages needed for dpdk tests161 init_hugepages(node)162 # run the nff-go tests163 nff_go.run_test()164 @TestCaseMetadata(165 description="""166 Build and run DPDK multiprocess client/server sample application.167 Requires 3 nics since client/server needs two ports + 1 nic for LISA168 """,169 priority=4,170 requirement=simple_requirement(171 min_nic_count=3,172 network_interface=Sriov(),173 unsupported_features=[Gpu, Infiniband],174 supported_features=[IsolatedResource],175 ),176 )177 def verify_dpdk_multiprocess(178 self, node: Node, log: Logger, variables: Dict[str, Any]179 ) -> None:180 # multiprocess test requires dpdk source.181 self._force_dpdk_default_source(variables)182 kill = node.tools[Kill]183 pmd = "failsafe"184 server_app_name = "dpdk-mp_server"185 client_app_name = "dpdk-mp_client"186 # initialize DPDK with sample applications selected for build187 test_kit = initialize_node_resources(188 node,189 log,190 variables,191 pmd,192 sample_apps=[193 "multi_process/client_server_mp/mp_server",194 "multi_process/client_server_mp/mp_client",195 ],196 )197 if test_kit.testpmd.is_connect_x3:198 raise SkippedException(199 "Unsupported Hardware: ConnectX3 does not support secondary process RX"200 )201 # enable hugepages needed for dpdk EAL202 init_hugepages(node)203 # setup and run mp_server application204 examples_path = test_kit.testpmd.dpdk_build_path.joinpath("examples")205 server_app_path = examples_path.joinpath(server_app_name)206 client_app_path = examples_path.joinpath(client_app_name)207 # EAL -l: start server on cores 1-2,208 # EAL -n: use 4 memory channels209 # APP: -p : set port bitmask to port 0 and 1210 # APP: -n : allow one client to connect211 server_proc = node.execute_async(212 (213 f"{server_app_path} -l 1-2 -n 4 "214 f"-b {node.nics.get_nic_by_index(0).pci_slot} -- -p 3 -n 1"215 ),216 sudo=True,217 shell=True,218 )219 # Wait for server to finish init220 server_proc.wait_output("APP: Finished Process Init.", timeout=5)221 # EAL -l: start client on core 3,222 # EAL --proc-type: client runs as secondary process.223 # APP: -n : client index is 0224 client_result = node.execute(225 (226 f"timeout -s INT 2 {client_app_path} --proc-type=secondary -l 3 -n 4"227 f" -b {node.nics.get_nic_by_index(0).pci_slot} -- -n 0"228 ),229 sudo=True,230 shell=True,231 )232 # client blocks and returns, kill server once client is finished.233 kill.by_name(str(server_app_name), signum=SIGINT)234 server_result = server_proc.wait_result()235 # perform the checks from v2236 assert_that(client_result.stdout).described_as(237 "Secondary process did not finish initialization"238 ).contains("APP: Finished Process Init")239 assert_that(client_result.stdout).described_as(240 "Secondary process did not start accepting packets from server"241 ).contains("Client process 0 handling packets")242 # mp_client returns a nonstandard positive number when killed w signal.243 # one would expect either 0 or 130 (killed by signal w sigint).244 # check that the nonsense number is at least the expected one.245 assert_that(client_result.exit_code).described_as(246 "dpdk-mp client exit code was unexpected"247 ).is_equal_to(124)248 assert_that(server_result.exit_code).is_equal_to(0)249 @TestCaseMetadata(250 description="""251 test sriov failsafe during vf revoke (receive side)252 """,253 priority=2,254 requirement=simple_requirement(255 min_core_count=8,256 min_nic_count=2,257 network_interface=Sriov(),258 min_count=2,259 unsupported_features=[Gpu, Infiniband],260 supported_features=[IsolatedResource],261 ),262 )263 def verify_dpdk_sriov_rescind_failover_receiver(264 self, environment: Environment, log: Logger, variables: Dict[str, Any]265 ) -> None:266 test_kits = init_nodes_concurrent(environment, log, variables, "failsafe")267 try:268 check_send_receive_compatibility(test_kits)269 except UnsupportedPackageVersionException as err:270 raise SkippedException(err)271 sender, receiver = test_kits272 # Want to only switch receiver sriov to avoid timing weirdness273 receiver.switch_sriov = True274 sender.switch_sriov = False275 kit_cmd_pairs = generate_send_receive_run_info("failsafe", sender, receiver)276 run_testpmd_concurrent(277 kit_cmd_pairs, DPDK_VF_REMOVAL_MAX_TEST_TIME, log, rescind_sriov=True278 )279 rescind_tx_pps_set = receiver.testpmd.get_mean_rx_pps_sriov_rescind()280 self._check_rx_or_tx_pps_sriov_rescind("RX", rescind_tx_pps_set)281 @TestCaseMetadata(282 description="""283 test sriov failsafe during vf revoke (send only version)284 """,285 priority=2,286 requirement=simple_requirement(287 min_core_count=8,288 min_nic_count=2,289 network_interface=Sriov(),290 unsupported_features=[Gpu, Infiniband],291 supported_features=[IsolatedResource],292 ),293 )294 def verify_dpdk_sriov_rescind_failover_send_only(295 self, node: Node, log: Logger, variables: Dict[str, Any]296 ) -> None:297 test_kit = initialize_node_resources(node, log, variables, "failsafe")298 testpmd = test_kit.testpmd299 test_nic = node.nics.get_nic_by_index()300 testpmd_cmd = testpmd.generate_testpmd_command(301 test_nic, 0, "txonly", "failsafe"302 )303 kit_cmd_pairs = {304 test_kit: testpmd_cmd,305 }306 run_testpmd_concurrent(307 kit_cmd_pairs, DPDK_VF_REMOVAL_MAX_TEST_TIME, log, rescind_sriov=True308 )309 rescind_tx_pps_set = testpmd.get_mean_tx_pps_sriov_rescind()310 self._check_rx_or_tx_pps_sriov_rescind("TX", rescind_tx_pps_set)311 def _check_rx_or_tx_pps_sriov_rescind(312 self, tx_or_rx: str, pps: Tuple[int, int, int]313 ) -> None:314 before_rescind, during_rescind, after_reenable = pps315 self._check_rx_or_tx_pps(tx_or_rx, before_rescind, sriov_enabled=True)316 self._check_rx_or_tx_pps(tx_or_rx, during_rescind, sriov_enabled=False)317 self._check_rx_or_tx_pps(tx_or_rx, after_reenable, sriov_enabled=True)318 def _check_rx_or_tx_pps(319 self, tx_or_rx: str, pps: int, sriov_enabled: bool = True320 ) -> None:321 if sriov_enabled:322 assert_that(pps).described_as(323 f"{tx_or_rx}-PPS ({pps}) should have been greater "324 "than 2^20 (~1m) PPS before sriov disable."325 ).is_greater_than(2**20)326 else:327 assert_that(pps).described_as(328 f"{tx_or_rx}-PPS ({pps}) should have been less "329 "than 2^20 (~1m) PPS after sriov disable."330 ).is_less_than(2**20)331 @TestCaseMetadata(332 description="""333 verify vpp is able to detect azure network interfaces334 1. run fd.io vpp install scripts335 2. install vpp from their repositories336 3. start vpp service337 4. check that azure interfaces are detected by vpp338 """,339 priority=4,340 requirement=simple_requirement(341 min_core_count=8,342 min_nic_count=2,343 network_interface=Sriov(),344 unsupported_features=[Gpu, Infiniband],345 supported_features=[IsolatedResource],346 ),347 )348 def verify_dpdk_vpp(349 self, node: Node, log: Logger, variables: Dict[str, Any]350 ) -> None:351 vpp = node.tools[DpdkVpp]352 vpp.install()353 net = node.nics354 nic = net.get_nic_by_index()355 # set devices to down and restart vpp service356 ip = node.tools[Ip]357 for dev in [nic.lower, nic.upper]:358 ip.down(dev)359 for dev in [nic.lower, nic.upper]:360 ip.addr_flush(dev)361 vpp.start()362 vpp.run_test()363 @TestCaseMetadata(364 description="""365 This test runs the dpdk ring ping utility from:366 https://github.com/shemminger/dpdk-ring-ping367 to measure the maximum latency for 99.999 percent of packets during368 the test run. The maximum should be under 200000 nanoseconds369 (.2 milliseconds).370 Not dependent on any specific PMD.371 """,372 priority=4,373 requirement=simple_requirement(374 min_core_count=8,375 network_interface=Sriov(),376 unsupported_features=[Gpu, Infiniband],377 supported_features=[IsolatedResource],378 ),379 )380 def verify_dpdk_ring_ping(381 self, node: Node, log: Logger, variables: Dict[str, Any]382 ) -> None:383 # ring ping requires dpdk source to run, since default is package_manager384 # we special case here to use to dpdk-stable as the default.385 self._force_dpdk_default_source(variables)386 # setup and unwrap the resources for this test387 test_kit = initialize_node_resources(node, log, variables, "failsafe")388 testpmd = test_kit.testpmd389 # grab a nic and run testpmd390 git = node.tools[Git]391 make = node.tools[Make]392 echo = node.tools[Echo]393 rping_build_env_vars = [394 "export RTE_TARGET=build",395 f"export RTE_SDK={str(testpmd.dpdk_path)}",396 ]397 echo.write_to_file(398 ";".join(rping_build_env_vars), node.get_pure_path("~/.bashrc"), append=True399 )400 git_path = git.clone(401 "https://github.com/shemminger/dpdk-ring-ping.git", cwd=node.working_path402 )403 make.run(404 shell=True,405 cwd=git_path,406 expected_exit_code=0,407 expected_exit_code_failure_message="make could not build rping project.",408 ).assert_exit_code()409 # run ringping for 30 seconds410 runcmd = "./build/rping -c 0x03 -n 2 --no-pci --no-huge -- -d 5 -t 10"411 result = node.execute(412 runcmd,413 shell=True,414 cwd=git_path,415 expected_exit_code=0,416 expected_exit_code_failure_message="rping program failed to run correctly.",417 )418 result.assert_exit_code()419 # get the max latency for 99.999 percent of enqueued 'packets'.420 result_regex = self._ring_ping_percentile_regex.search(result.stdout)421 if result_regex and len(result_regex.groups()) == 1:422 max_ping_measured = int(result_regex.group(1))423 assert_that(max_ping_measured).described_as(424 (425 f"RingPing measured {max_ping_measured} as maximum ping latency,"426 f" maximum should be less than {MAX_RING_PING_LIMIT_NS}"427 )428 ).is_less_than(MAX_RING_PING_LIMIT_NS)429 else:430 fail(431 (432 "Could not get latency data from rping result. "433 f"Search was for 'percentile 99.999 = ([0-9]+)'\n{result.stdout}\n"434 )435 )436 @TestCaseMetadata(437 description="""438 Tests a basic sender/receiver setup for default failsafe driver setup.439 Sender sends the packets, receiver receives them.440 We check both to make sure the received traffic is within the expected441 order-of-magnitude.442 """,443 priority=2,444 requirement=simple_requirement(445 min_core_count=8,446 min_nic_count=2,447 network_interface=Sriov(),448 min_count=2,449 unsupported_features=[Gpu, Infiniband],450 supported_features=[IsolatedResource],451 ),452 )453 def verify_dpdk_send_receive_multi_txrx_queue_failsafe(454 self, environment: Environment, log: Logger, variables: Dict[str, Any]455 ) -> None:456 try:457 verify_dpdk_send_receive_multi_txrx_queue(458 environment, log, variables, "failsafe"459 )460 except UnsupportedPackageVersionException as err:461 raise SkippedException(err)462 @TestCaseMetadata(463 description="""464 Tests a basic sender/receiver setup for default failsafe driver setup.465 Sender sends the packets, receiver receives them.466 We check both to make sure the received traffic is within the expected467 order-of-magnitude.468 """,469 priority=2,470 requirement=simple_requirement(471 min_core_count=8,472 min_nic_count=2,473 network_interface=Sriov(),474 min_count=2,475 unsupported_features=[Gpu, Infiniband],476 supported_features=[IsolatedResource],477 ),478 )479 def verify_dpdk_send_receive_multi_txrx_queue_netvsc(480 self, environment: Environment, log: Logger, variables: Dict[str, Any]481 ) -> None:482 try:483 verify_dpdk_send_receive_multi_txrx_queue(484 environment, log, variables, "netvsc"485 )486 except UnsupportedPackageVersionException as err:487 raise SkippedException(err)488 @TestCaseMetadata(489 description="""490 Tests a basic sender/receiver setup for default failsafe driver setup.491 Sender sends the packets, receiver receives them.492 We check both to make sure the received traffic is within the expected493 order-of-magnitude.494 """,495 priority=2,496 requirement=simple_requirement(497 min_core_count=8,498 min_nic_count=2,499 network_interface=Sriov(),500 min_count=2,501 unsupported_features=[Gpu, Infiniband],502 supported_features=[IsolatedResource],503 ),504 )505 def verify_dpdk_send_receive_failsafe(506 self, environment: Environment, log: Logger, variables: Dict[str, Any]507 ) -> None:508 try:509 verify_dpdk_send_receive(environment, log, variables, "failsafe")510 except UnsupportedPackageVersionException as err:511 raise SkippedException(err)512 @TestCaseMetadata(513 description="""514 Tests a basic sender/receiver setup for direct netvsc pmd setup.515 Sender sends the packets, receiver receives them.516 We check both to make sure the received traffic is within the expected517 order-of-magnitude.518 """,519 priority=2,520 requirement=simple_requirement(521 min_core_count=8,522 min_nic_count=2,523 network_interface=Sriov(),524 min_count=2,525 unsupported_features=[Gpu, Infiniband],526 supported_features=[IsolatedResource],527 ),528 )529 def verify_dpdk_send_receive_netvsc(530 self, environment: Environment, log: Logger, variables: Dict[str, Any]531 ) -> None:532 try:533 verify_dpdk_send_receive(environment, log, variables, "netvsc")534 except UnsupportedPackageVersionException as err:535 raise SkippedException(err)536 @TestCaseMetadata(537 description="""538 UIO basic functionality test.539 - Bind interface to uio_hv_generic540 - check that sysfs entry is created541 - unbind542 - check that the driver is unloaded.543 - rebind to original driver544 """,545 priority=2,546 requirement=simple_requirement(547 min_nic_count=2,548 network_interface=Sriov(),549 unsupported_features=[Gpu, Infiniband],550 supported_features=[IsolatedResource],551 ),552 )553 def verify_uio_binding(554 self, node: Node, log: Logger, variables: Dict[str, Any]555 ) -> None:556 lsmod = node.tools[Lsmod]557 modprobe = node.tools[Modprobe]558 nic = node.nics.get_nic_by_index()559 node.nics.get_nic_driver(nic.upper)560 if nic.bound_driver == "hv_netvsc":561 enable_uio_hv_generic_for_nic(node, nic)562 original_driver = nic.driver_sysfs_path563 node.nics.unbind(nic)564 node.nics.bind(nic, UIO_HV_GENERIC_SYSFS_PATH)565 node.execute(566 "test -e /dev/uio0",567 shell=True,568 expected_exit_code=0,569 expected_exit_code_failure_message=(570 "/dev/uio0 did not exist after driver bind"571 ),572 )573 assert_that(lsmod.module_exists("uio_hv_generic", force_run=True)).described_as(574 "uio_hv_generic was not found after bind"575 ).is_true()576 node.nics.unbind(nic)577 node.nics.bind(nic, str(original_driver))578 nic.bound_driver = node.nics.get_nic_driver(nic.upper)579 assert_that(nic.bound_driver).described_as(580 (581 "Driver after unbind/rebind was unexpected. "582 f"Expected hv_netvsc, found {nic.bound_driver}"583 )584 ).is_equal_to("hv_netvsc")585 modprobe.remove(["uio_hv_generic"])586 node.execute(587 "test -e /dev/uio0",588 shell=True,589 expected_exit_code=1,590 expected_exit_code_failure_message=(591 "/dev/uio0 still exists after driver unload"592 ),593 )594 def _force_dpdk_default_source(self, variables: Dict[str, Any]) -> None:595 if not variables.get("dpdk_source", None):596 variables["dpdk_source"] = DPDK_STABLE_GIT_REPO597 def after_case(self, log: Logger, **kwargs: Any) -> None:598 environment: Environment = kwargs.pop("environment")599 for node in environment.nodes.list():600 modprobe = node.tools[Modprobe]601 if modprobe.module_exists("uio_hv_generic"):602 node.tools[Service].stop_service("vpp")603 modprobe.remove(["uio_hv_generic"])604 node.close()...
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!!