Best Python code snippet using lisa_python
features.py
Source:features.py
...427 supported = node.os.information.version >= "18.0.0"428 elif isinstance(node.os, Suse):429 supported = node.os.information.version >= "15.0.0"430 return supported431 def get_supported_driver(self) -> List[ComputeSDK]:432 driver_list = []433 node_runbook = self._node.capability.get_extended_runbook(434 AzureNodeSchema, AZURE435 )436 if re.match(self._grid_supported_skus, node_runbook.vm_size):437 driver_list.append(ComputeSDK.GRID)438 elif re.match(self._amd_supported_skus, node_runbook.vm_size):439 driver_list.append(ComputeSDK.AMD)440 self._is_nvidia: bool = False441 else:442 driver_list.append(ComputeSDK.CUDA)443 if not driver_list:444 raise LisaException(445 "No valid Compute SDK found to install for the VM size -"...
gpu.py
Source:gpu.py
...98 self._log.debug(99 f"LisDriver is not installed. It might not be required. {identifier}"100 )101 # install the driver102 supported_driver = self.get_supported_driver()103 for driver in supported_driver:104 if driver == ComputeSDK.GRID:105 if not version:106 version = DEFAULT_GRID_DRIVER_URL107 self._install_grid_driver(version)108 self.gpu_vendor.add("nvidia")109 elif driver == ComputeSDK.CUDA:110 if not version:111 version = DEFAULT_CUDA_DRIVER_VERSION112 self._install_cuda_driver(version)113 self.gpu_vendor.add("nvidia")114 else:115 raise LisaException(f"{driver} is not a valid value of ComputeSDK")116 if not self.gpu_vendor:117 raise LisaException("No supported gpu driver/vendor found for this node.")118 def get_gpu_count_with_lsvmbus(self) -> int:119 lsvmbus_device_count = 0120 bridge_device_count = 0121 lsvmbus_tool = self._node.tools[Lsvmbus]122 device_list = lsvmbus_tool.get_device_channels()123 for device in device_list:124 for name, id, bridge_count in NvidiaSmi.gpu_devices:125 if id in device.device_id:126 lsvmbus_device_count += 1127 bridge_device_count = bridge_count128 self._log.debug(f"GPU device {name} found!")129 break130 return lsvmbus_device_count - bridge_device_count131 def get_gpu_count_with_lspci(self) -> int:132 lspci_tool = self._node.tools[Lspci]133 device_list = lspci_tool.get_devices_by_type(134 constants.DEVICE_TYPE_GPU, force_run=True135 )136 # Remove Microsoft Virtual one. It presents with GRID driver.137 device_list = self.remove_virtual_gpus(device_list)138 return len(device_list)139 def get_gpu_count_with_vendor_cmd(self) -> int:140 nvidiasmi = self._node.tools[NvidiaSmi]141 return nvidiasmi.get_gpu_count()142 def get_supported_driver(self) -> List[ComputeSDK]:143 raise NotImplementedError()144 def _initialize(self, *args: Any, **kwargs: Any) -> None:145 self.gpu_vendor: Set[str] = set()146 @classmethod147 def _install_by_platform(cls, *args: Any, **kwargs: Any) -> None:148 raise NotImplementedError()149 # download and install NVIDIA grid driver150 def _install_grid_driver(self, driver_url: str) -> None:151 self._log.debug("Starting GRID driver installation")152 # download and install the NVIDIA GRID driver153 wget_tool = self._node.tools[Wget]154 grid_file_path = wget_tool.get(155 driver_url,156 str(self._node.working_path),...
gpusuite.py
Source:gpusuite.py
...162def _check_driver_installed(node: Node) -> None:163 gpu = node.features[Gpu]164 if not gpu.is_supported():165 raise SkippedException(f"GPU is not supported with distro {node.os.name}")166 if ComputeSDK.AMD in gpu.get_supported_driver():167 raise SkippedException("AMD vm sizes is not supported")168 try:169 _ = node.tools[NvidiaSmi]170 except Exception as identifier:171 raise LisaException(172 f"Cannot find nvidia-smi, make sure the driver installed correctly. "173 f"Inner exception: {identifier}"174 )175def _install_cudnn(node: Node) -> None:176 wget = node.tools[Wget]177 tar = node.tools[Tar]178 path = wget.get_tool_path(use_global=True)179 extracted_path = tar.get_tool_path(use_global=True)180 if node.shell.exists(path / _cudnn_file_name):181 return182 download_path = wget.get(183 url=_cudnn_location, filename=str(_cudnn_file_name), file_path=str(path)184 )185 tar.extract(download_path, dest_dir=str(extracted_path))186 if isinstance(node.os, Debian):187 target_path = "/usr/lib/x86_64-linux-gnu/"188 else:189 target_path = "/usr/lib64/"190 node.execute(191 f"cp -p {extracted_path}/cuda/lib64/libcudnn* {target_path}",192 shell=True,193 sudo=True,194 )195 return196# We use platform to install the driver by default. If in future, it needs to197# install independently, this logic can be reused.198def _ensure_driver_installed(199 node: Node, gpu_feature: Gpu, log_path: Path, log: Logger200) -> None:201 if gpu_feature.is_module_loaded():202 return203 gpu_feature.install_compute_sdk()204 log.debug(205 f"{gpu_feature.get_supported_driver()} sdk installed. "206 "Will reboot to load driver."207 )208 reboot_tool = node.tools[Reboot]209 reboot_tool.reboot_and_check_panic(log_path)...
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!!