How to use disable_devices_by_type method in lisa

Best Python code snippet using lisa_python

sriov.py

Source:sriov.py Github

copy

Full Screen

...221 )222 def verify_sriov_disable_enable_pci(self, environment: Environment) -> None:223 for node in environment.nodes.list():224 lspci = node.tools[Lspci]225 lspci.disable_devices_by_type(constants.DEVICE_TYPE_SRIOV)226 lspci.enable_devices()227 vm_nics = initialize_nic_info(environment)228 sriov_basic_test(environment, vm_nics)229 sriov_vf_connection_test(environment, vm_nics)230 @TestCaseMetadata(231 description="""232 This case verify VM works well after down the VF nic and up VF nic inside VM.233 Steps,234 1. Do the basic sriov check.235 2. Do network connection test with bring down the VF nic.236 3. After copy 200Mb file from source to desc.237 4. Check rx statistics of source synthetic nic and tx statistics of dest238 synthetic nic is increased.239 5. Bring up VF nic.240 """,241 priority=2,242 requirement=simple_requirement(243 min_count=2,244 network_interface=features.Sriov(),245 ),246 )247 def verify_sriov_disable_enable_on_guest(self, environment: Environment) -> None:248 vm_nics = initialize_nic_info(environment)249 sriov_basic_test(environment, vm_nics)250 sriov_vf_connection_test(environment, vm_nics, turn_off_vf=True)251 @TestCaseMetadata(252 description="""253 This case verify VM works well after attached the max sriov nics after254 provision.255 Steps,256 1. Attach 7 extra sriov nic into the VM.257 2. Do the basic sriov testing.258 """,259 priority=2,260 use_new_environment=True,261 requirement=simple_requirement(262 network_interface=schema.NetworkInterfaceOptionSettings(263 data_path=schema.NetworkDataPath.Sriov,264 max_nic_count=8,265 ),266 ),267 )268 def verify_sriov_add_max_nics(269 self, log_path: Path, log: Logger, environment: Environment270 ) -> None:271 remove_extra_nics(environment)272 try:273 node = cast(RemoteNode, environment.nodes[0])274 network_interface_feature = node.features[NetworkInterface]275 network_interface_feature.attach_nics(extra_nic_count=7)276 is_ready, tcp_error_code = wait_tcp_port_ready(277 node.public_address, node.public_port, log=log, timeout=self.TIME_OUT278 )279 if is_ready:280 vm_nics = initialize_nic_info(environment)281 sriov_basic_test(environment, vm_nics)282 else:283 serial_console = node.features[SerialConsole]284 serial_console.check_panic(285 saved_path=log_path, stage="after_attach_nics"286 )287 raise TcpConnectionException(288 node.public_address,289 node.public_port,290 tcp_error_code,291 "no panic found in serial log after attach nics",292 )293 finally:294 restore_extra_nics(environment)295 @TestCaseMetadata(296 description="""297 This case verify VM works well when provisioning with max (8) sriov nics.298 Steps,299 1. Provision VM with max network interfaces with enabling accelerated network.300 2. Do the basic sriov testing.301 """,302 priority=2,303 requirement=simple_requirement(304 min_nic_count=8,305 network_interface=features.Sriov(),306 ),307 )308 def verify_sriov_provision_with_max_nics(self, environment: Environment) -> None:309 vm_nics = initialize_nic_info(environment)310 sriov_basic_test(environment, vm_nics)311 @TestCaseMetadata(312 description="""313 This case verify VM works well when provisioning with max (8) sriov nics.314 Steps,315 1. Provision VM with max network interfaces with enabling accelerated network.316 2. Do the basic sriov testing.317 3. Reboot VM from guest.318 4. Do the basic sriov testing.319 """,320 priority=2,321 requirement=simple_requirement(322 min_nic_count=8,323 network_interface=features.Sriov(),324 ),325 )326 def verify_sriov_provision_with_max_nics_reboot(327 self, environment: Environment328 ) -> None:329 vm_nics = initialize_nic_info(environment)330 sriov_basic_test(environment, vm_nics)331 for node in environment.nodes.list():332 node.reboot()333 sriov_basic_test(environment, vm_nics)334 @TestCaseMetadata(335 description="""336 This case verify VM works well when provisioning with max (8) sriov nics.337 Steps,338 1. Provision VM with max network interfaces with enabling accelerated network.339 2. Do the basic sriov testing.340 3. Reboot VM from API.341 4. Do the basic sriov testing.342 """,343 priority=2,344 requirement=simple_requirement(345 min_nic_count=8,346 network_interface=features.Sriov(),347 ),348 )349 def verify_sriov_provision_with_max_nics_reboot_from_platform(350 self, environment: Environment351 ) -> None:352 vm_nics = initialize_nic_info(environment)353 sriov_basic_test(environment, vm_nics)354 for node in environment.nodes.list():355 start_stop = node.features[StartStop]356 start_stop.restart()357 sriov_basic_test(environment, vm_nics)358 @TestCaseMetadata(359 description="""360 This case verify VM works well when provisioning with max (8) sriov nics.361 Steps,362 1. Provision VM with max network interfaces with enabling accelerated network.363 2. Do the basic sriov testing.364 3. Stop and Start VM from API.365 4. Do the basic sriov testing.366 """,367 priority=2,368 requirement=simple_requirement(369 min_nic_count=8,370 network_interface=features.Sriov(),371 ),372 )373 def verify_sriov_provision_with_max_nics_stop_start_from_platform(374 self, environment: Environment375 ) -> None:376 vm_nics = initialize_nic_info(environment)377 sriov_basic_test(environment, vm_nics)378 for node in environment.nodes.list():379 start_stop = node.features[StartStop]380 start_stop.stop()381 start_stop.start()382 sriov_basic_test(environment, vm_nics)383 @TestCaseMetadata(384 description="""385 This case verify VM works well during remove and load sriov modules.386 Steps,387 1. Provision VM with max network interfaces with enabling accelerated network.388 2. Do the basic sriov testing.389 3. Remove sriov module, check network traffic through synthetic nic.390 4. Load sriov module, check network traffic through VF.391 """,392 priority=2,393 requirement=simple_requirement(394 min_count=2,395 min_nic_count=8,396 network_interface=features.Sriov(),397 ),398 )399 def verify_sriov_reload_modules(self, environment: Environment) -> None:400 for node in environment.nodes.list():401 if node.tools[KernelConfig].is_built_in(get_used_config(node)):402 raise SkippedException(403 "current VM's mlx driver is built-in, can not reload."404 )405 vm_nics = initialize_nic_info(environment)406 sriov_basic_test(environment, vm_nics)407 module_in_used: Dict[str, str] = {}408 for node in environment.nodes.list():409 module_in_used[node.name] = remove_module(node)410 sriov_vf_connection_test(environment, vm_nics, remove_module=True)411 for node in environment.nodes.list():412 load_module(node, module_in_used[node.name])413 vm_nics = initialize_nic_info(environment)414 sriov_vf_connection_test(environment, vm_nics)415 @TestCaseMetadata(416 description="""417 This case verify below two kernel patches.418 1. hv_netvsc: Sync offloading features to VF NIC419 https://github.com/torvalds/linux/commit/68622d071e555e1528f3e7807f30f73311c1acae#diff-007213ba7199932efdb096be47d209a2f83e4d425c486b3adaba861d0a0c80c5 # noqa: E501420 2. hv_netvsc: Allow scatter-gather feature to be tunable421 https://github.com/torvalds/linux/commit/b441f79532ec13dc82d05c55badc4da1f62a6141#diff-007213ba7199932efdb096be47d209a2f83e4d425c486b3adaba861d0a0c80c5 # noqa: E501422 Steps,423 1. Change scatter-gather feature on synthetic nic,424 verify the the feature status sync to the VF dynamically.425 2. Disable and enable sriov,426 check the scatter-gather feature status keep consistent in VF.427 """,428 priority=2,429 requirement=simple_requirement(430 min_count=2,431 network_interface=schema.NetworkInterfaceOptionSettings(432 nic_count=search_space.IntRange(min=3, max=8),433 data_path=schema.NetworkDataPath.Sriov,434 ),435 ),436 )437 def verify_sriov_ethtool_offload_setting(self, environment: Environment) -> None:438 client_iperf3_log = "iperfResults.log"439 server_node = cast(RemoteNode, environment.nodes[0])440 client_node = cast(RemoteNode, environment.nodes[1])441 client_ethtool = client_node.tools[Ethtool]442 vm_nics = initialize_nic_info(environment)443 # skip test if scatter-gather can't be updated444 for _, client_nic_info in vm_nics[client_node.name].items():445 device_sg_settings = client_ethtool.get_device_sg_settings(446 client_nic_info.upper, True447 )448 if device_sg_settings.sg_fixed:449 raise SkippedException(450 "scatter-gather is fixed, it cannot be changed for device"451 f" {client_nic_info.upper}. Skipping test."452 )453 else:454 break455 # save original enabled features456 device_enabled_features_origin = client_ethtool.get_all_device_enabled_features(457 True458 )459 # run iperf3 on server side and client side460 # iperfResults.log stored client side log461 source_iperf3 = server_node.tools[Iperf3]462 dest_iperf3 = client_node.tools[Iperf3]463 source_iperf3.run_as_server_async()464 dest_iperf3.run_as_client_async(465 server_ip=server_node.internal_address,466 log_file=client_iperf3_log,467 run_time_seconds=self.TIME_OUT,468 )469 # wait for a while then check any error shown up in iperfResults.log470 dest_cat = client_node.tools[Cat]471 iperf_log = dest_cat.read(client_iperf3_log, sudo=True, force_run=True)472 assert_that(iperf_log).does_not_contain("error")473 # disable and enable VF in pci level474 for node in environment.nodes.list():475 lspci = node.tools[Lspci]476 lspci.disable_devices_by_type(constants.DEVICE_TYPE_SRIOV)477 lspci.enable_devices()478 # check VF still paired with synthetic nic479 vm_nics = initialize_nic_info(environment)480 # get the enabled features after disable and enable VF481 # make sure there is not any change482 device_enabled_features_after = client_ethtool.get_all_device_enabled_features(483 True484 )485 assert_that(device_enabled_features_origin[0].enabled_features).is_equal_to(486 device_enabled_features_after[0].enabled_features487 )488 # set on for scatter-gather feature for synthetic nic489 # verify vf scatter-gather feature has value 'on'490 for _, client_nic_info in vm_nics[client_node.name].items():491 new_settings = client_ethtool.change_device_sg_settings(492 client_nic_info.upper, True493 )494 device_vf_sg_settings = client_ethtool.get_device_sg_settings(495 client_nic_info.lower, True496 )497 assert_that(498 new_settings.sg_setting,499 "sg setting is not sync into VF.",500 ).is_equal_to(device_vf_sg_settings.sg_setting)501 # set off for scatter-gather feature for synthetic nic502 # verify vf scatter-gather feature has value 'off'503 for _, client_nic_info in vm_nics[client_node.name].items():504 new_settings = client_ethtool.change_device_sg_settings(505 client_nic_info.upper, False506 )507 device_vf_sg_settings = client_ethtool.get_device_sg_settings(508 client_nic_info.lower, True509 )510 assert_that(511 new_settings.sg_setting,512 "sg setting is not sync into VF.",513 ).is_equal_to(device_vf_sg_settings.sg_setting)514 # disable and enable VF in pci level515 for node in environment.nodes.list():516 lspci = node.tools[Lspci]517 lspci.disable_devices_by_type(constants.DEVICE_TYPE_SRIOV)518 lspci.enable_devices()519 # check VF still paired with synthetic nic520 vm_nics = initialize_nic_info(environment)521 # check VF's scatter-gather feature keep consistent with previous status522 for _, client_nic_info in vm_nics[client_node.name].items():523 device_vf_sg_settings = client_ethtool.get_device_sg_settings(524 client_nic_info.lower, True525 )526 assert_that(527 device_vf_sg_settings.sg_setting,528 "sg setting is not sync into VF.",529 ).is_equal_to(False)530 # disable and enable sriov in network interface level531 network_interface_feature = client_node.features[NetworkInterface]...

Full Screen

Full Screen

nvme.py

Source:nvme.py Github

copy

Full Screen

...330 )331 def nvme_rescind_validation(self, node: Node) -> None:332 lspci = node.tools[Lspci]333 # 1. Disable NVME devices.334 lspci.disable_devices_by_type(device_type=constants.DEVICE_TYPE_NVME)335 # 2. Enable NVME device.336 lspci.enable_devices()337 @TestCaseMetadata(338 description="""339 This test case does following steps to verify VM working normally during340 disable and enable nvme and sriov devices.341 1. Disable PCI devices.342 2. Enable PCI devices.343 3. Get PCI devices slots.344 4. Check PCI devices are back after rescan.345 """,346 priority=2,347 requirement=simple_requirement(348 network_interface=Sriov(),349 supported_features=[Nvme],350 ),351 )352 def nvme_sriov_rescind_validation(self, node: Node) -> None:353 lspci = node.tools[Lspci]354 device_types = [constants.DEVICE_TYPE_NVME, constants.DEVICE_TYPE_SRIOV]355 for device_type in device_types:356 # 1. Disable PCI devices.357 before_pci_count = lspci.disable_devices_by_type(device_type)358 # 2. Enable PCI devices.359 lspci.enable_devices()360 # 3. Get PCI devices slots.361 after_devices_slots = lspci.get_device_names_by_type(device_type, True)362 # 4. Check PCI devices are back after rescan.363 assert_that(364 after_devices_slots,365 "After rescan, the disabled PCI devices should be back.",366 ).is_length(before_pci_count)367 def _validate_nvme_disk(self, environment: Environment, node: Node) -> None:368 # 1. Get nvme devices and nvme namespaces from /dev/ folder,369 # compare the count of nvme namespaces and nvme devices.370 nvme = node.features[Nvme]371 nvme_device = nvme.get_devices()...

Full Screen

Full Screen

lspci.py

Source:lspci.py Github

copy

Full Screen

...108 for pci_raw in result.stdout.splitlines():109 pci_device = PciDevice(pci_raw)110 self._pci_devices.append(pci_device)111 return self._pci_devices112 def disable_devices_by_type(self, device_type: str) -> int:113 devices = self.get_devices_by_type(device_type, force_run=True)114 if 0 == len(devices):115 self._log.debug("No matched devices found.")116 return len(devices)117 for device in devices:118 self.disable_device(device=device)119 return len(devices)120 def disable_device(self, device: PciDevice) -> None:121 echo = self.node.tools[Echo]122 echo.write_to_file(123 "1",124 self.node.get_pure_path(f"/sys/bus/pci/devices/{device.slot}/remove"),125 sudo=True,126 )...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful