Best Python code snippet using lisa_python
tools.py
Source:tools.py  
...176    def get_version(self, force_run: bool = False) -> str:177        # in some distro, the vmbus is builtin, the version cannot be gotten.178        modinfo = self.node.tools[Modinfo]179        return modinfo.get_version("hv_vmbus")180    def install_from_iso(self) -> ExecutableResult:181        lis_folder_path = self.download()182        return self.node.execute("./install.sh", cwd=lis_folder_path, sudo=True)183    def uninstall_from_iso(self) -> ExecutableResult:184        lis_folder_path = self.download()185        return self.node.execute("./uninstall.sh", cwd=lis_folder_path, sudo=True)186    def _check_exists(self) -> bool:187        if isinstance(self.node.os, Redhat):188            # currently LIS is only supported with Redhat189            # and its derived distros190            if self.node.os.package_exists(191                "kmod-microsoft-hyper-v"192            ) and self.node.os.package_exists("microsoft-hyper-v"):193                return True194        return False195    def _install(self) -> bool:196        result = self.install_from_iso()197        result.assert_exit_code(198            0,199            f"Unable to install the LIS RPMs! exit_code: {result.exit_code}"200            f"stderr: {result.stderr}",201        )202        self.node.reboot(360)203        return True204class KvpClient(Tool):205    """206    The KVP client is used to check kvp service status.207    """208    _binaries: Dict[str, str] = {209        "x86_64": "https://raw.githubusercontent.com/microsoft/"210        "lis-test/master/WS2012R2/lisa/tools/KVP/kvp_client64",...lissuite.py
Source:lissuite.py  
...112        fallocate = node.tools[Fallocate]113        stat = node.tools[Stat]114        df = node.tools[Df]115        rpm = node.tools[Rpm]116        cmd_result = lisdriver.uninstall_from_iso()117        cmd_result.assert_exit_code(0, "failed to uninstall lis")118        self._clean_up_files(node)119        lib_module_folder = "/lib/modules"120        boot_folder = "/boot"121        # fetched from spec122        min_space_for_ramfs_creation = 157286400123        # 9MB to hit rpm limit124        min_sz_root_partition_not_root = 9437184125        # 10MB for log file creation126        root_partition_buffer_space = 10485760127        # allowed limit of +- 1MB128        boot_partition_buffer_space = 1048576129        root_partition = df.get_partition_by_mountpoint("/")130        boot_partition = df.get_partition_by_mountpoint("/boot")131        assert root_partition, "fail to get root partition"132        assert boot_partition, "fail to get boot partition"133        ramdisk_size_factor = 1134        if root_partition.name != boot_partition.name:135            ramdisk_size_factor = 2136        lis_path = lisdriver.download()137        os_version = node.os.information.release.split(".")138        version = os_version[0] + os_version[1]139        lib_module_required_space = rpm.get_file_size(140            f"{lis_path}/RPMS{version}/kmod-microsoft-hyper*x86_64.rpm"141        )142        uname = node.tools[Uname]143        kernel_version = uname.get_linux_information().kernel_version_raw144        ramdisk_required_space = stat.get_total_size(145            f"/boot/initramfs-{kernel_version}.img"146        )147        boot_part_required_space = ramdisk_required_space + boot_partition_buffer_space148        root_part_required_space = (149            min_space_for_ramfs_creation150            + ramdisk_size_factor * ramdisk_required_space151            + lib_module_required_space152            + root_partition_buffer_space153        )154        node.execute("sync")155        fblock_non_root = stat.get_fs_available_size(lib_module_folder)156        fblock_root = stat.get_fs_free_blocks(lib_module_folder)157        boot_part_avail_space = stat.get_fs_block_size(158            boot_folder159        ) * stat.get_fs_available_size(boot_folder)160        root_part_avail_space = (161            stat.get_fs_block_size(lib_module_folder) * fblock_non_root162        )163        if test_type == "negative":164            boot_part_required_space = int(boot_part_required_space / 2)165            root_part_required_space = int(root_part_required_space / 2)166            # 6.X distro RPM does not use root user space free space.167            # Hence setting the min limit.168            if fblock_non_root != fblock_root:169                root_part_required_space = min_sz_root_partition_not_root170            single_partition_file_size = (171                root_part_avail_space - root_part_required_space172            )173            fallocate.create_file(single_partition_file_size, "/lib/modules/file.out")174        if boot_partition != root_partition:175            single_partition_file_size_boot = (176                boot_part_avail_space - boot_part_required_space177            )178            fallocate.create_file(single_partition_file_size_boot, "/boot/file.out")179        result = lisdriver.install_from_iso()180        if test_type == "negative":181            if result.exit_code == 0:182                raise LisaException(183                    "lis should fail to be installed for insufficient space"184                )185            else:186                log.debug(f"fail to install lis for reason {result.stdout}")187        self._clean_up_files(node)188        if test_type == "positive":189            lisdriver.uninstall_from_iso()190    # Returns true if version and source_version are the same191    def _check_lis_version(192        self, node: Node, version: str, source_version: str, log: Logger193    ) -> None:194        log.debug("Detected modinfo version is {version}")195        log.debug("Version found in source code is {source_version}")196        assert_that(version).described_as(197            "Detected version and Source version are different. Expected LIS version:"198            f" {source_version}, Actual LIS version: {version}"199        )200    # Returns true if version and source_version_hex are the same201    def _check_lis_version_hex(202        self, node: Node, version: str, source_version_hex: str, log: Logger203    ) -> None:...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!!
