Best Python code snippet using lisa_python
common.py
Source:common.py
...47 f"actual sriov nic count is {sriov_count}"48 ).is_equal_to(sriov_count)49 vm_nics[node.name] = node_nic_info.nics50 return vm_nics51def get_used_module(node: Node) -> str:52 lspci = node.tools[Lspci]53 devices_slots = lspci.get_device_names_by_type(54 constants.DEVICE_TYPE_SRIOV, force_run=True55 )56 # there will not be multiple Mellanox types in one VM57 # get the used module using any one of sriov device58 return lspci.get_used_module(devices_slots[0])59def get_used_config(node: Node) -> str:60 return modules_config_dict[get_used_module(node)]61def remove_module(node: Node) -> str:62 modprobe = node.tools[Modprobe]63 module_in_used = get_used_module(node)64 assert_that(reload_modules_dict).described_as(65 f"used modules {module_in_used} should be contained"66 f" in dict {reload_modules_dict}"67 ).contains(module_in_used)68 modprobe.remove(reload_modules_dict[module_in_used])69 return module_in_used70def load_module(node: Node, module_name: str) -> None:71 modprobe = node.tools[Modprobe]72 modprobe.load(module_name)73def get_packets(node: Node, nic_name: str, name: str = "tx_packets") -> int:74 cat = node.tools[Cat]75 return int(cat.read(f"/sys/class/net/{nic_name}/statistics/{name}", force_run=True))76@retry(exceptions=AssertionError, tries=150, delay=2)77def sriov_basic_test(78 environment: Environment, vm_nics: Dict[str, Dict[str, NicInfo]]79) -> None:80 for node in environment.nodes.list():81 # 1. Check module of sriov network device is loaded.82 used_module = get_used_module(node)83 if not node.tools[KernelConfig].is_built_in(modules_config_dict[used_module]):84 lsmod = node.tools[Lsmod]85 assert_that(lsmod.module_exists(used_module, force_run=True)).described_as(86 "The module of sriov network device isn't loaded."87 ).is_true()88 # 2. Check VF counts listed from lspci is expected.89 lspci = node.tools[Lspci]90 devices_slots = lspci.get_device_names_by_type(91 constants.DEVICE_TYPE_SRIOV, force_run=True92 )93 assert_that(devices_slots).described_as(94 "count of sriov devices listed from lspci is not expected,"95 " please check the driver works properly"96 ).is_length(len([x for x in vm_nics[node.name].values() if x.lower != ""]))...
lspci.py
Source:lspci.py
...130 def enable_devices(self) -> None:131 self.node.tools[Echo].write_to_file(132 "1", self.node.get_pure_path("/sys/bus/pci/rescan"), sudo=True133 )134 def get_used_module(self, slot: str) -> str:135 result = self.run(136 f"-nks {slot}",137 force_run=True,138 shell=True,139 expected_exit_code=0,140 )141 matched = get_matched_str(result.stdout, PATTERN_MODULE_IN_USE)142 assert matched...
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!!