Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate case verify_lis_preinstall_disk_size #1811

Merged
merged 2 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lisa/base_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .cat import Cat
from .rpm import Rpm
from .sed import Sed
from .uname import Uname
from .wget import Wget

__all__ = ["Uname", "Sed", "Wget", "Cat"]
__all__ = ["Uname", "Sed", "Wget", "Cat", "Rpm"]
30 changes: 30 additions & 0 deletions lisa/base_tools/rpm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import cast

from lisa.executable import Tool


class Rpm(Tool):
@property
def command(self) -> str:
return "rpm"

@property
def can_install(self) -> bool:
return True

def install(self) -> bool:
from lisa.operating_system import Posix

posix_os: Posix = cast(Posix, self.node.os)
package_name = "rpm"
posix_os.install_packages(package_name)
return self._check_exists()

def get_file_size(self, file: str) -> int:
cmd_result = self.run(
"--queryformat='%{SIZE}' " f"-qp {file}",
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message=(f"fail to get size of file {file}"),
)
return int(cmd_result.stdout)
42 changes: 26 additions & 16 deletions lisa/sut_orchestrator/azure/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT license.

import re
from pathlib import PurePath
from typing import Any, Dict, List, Optional, Type

from assertpy import assert_that
Expand All @@ -11,6 +12,7 @@
from lisa.operating_system import CoreOs, Redhat
from lisa.tools import Gcc, Modinfo, PowerShell, Uname
from lisa.util import LisaException, find_patterns_in_lines, get_matched_str
from lisa.util.process import ExecutableResult


class Waagent(Tool):
Expand Down Expand Up @@ -193,6 +195,29 @@ def can_install(self) -> bool:

return False

def download(self) -> PurePath:
if not self.node.shell.exists(self.node.working_path.joinpath("LISISO")):
wget_tool = self.node.tools[Wget]
lis_path = wget_tool.get("https://aka.ms/lis", str(self.node.working_path))
from lisa.tools import Tar

tar = self.node.tools[Tar]
tar.extract(file=lis_path, dest_dir=str(self.node.working_path))
return self.node.working_path.joinpath("LISISO")

def get_version(self, force_run: bool = False) -> str:
# in some distro, the vmbus is builtin, the version cannot be gotten.
modinfo = self.node.tools[Modinfo]
return modinfo.get_version("hv_vmbus")

def install_from_iso(self) -> ExecutableResult:
lis_folder_path = self.download()
return self.node.execute("./install.sh", cwd=lis_folder_path, sudo=True)

def uninstall_from_iso(self) -> ExecutableResult:
lis_folder_path = self.download()
return self.node.execute("./uninstall.sh", cwd=lis_folder_path, sudo=True)

def _check_exists(self) -> bool:
if isinstance(self.node.os, Redhat):
# currently LIS is only supported with Redhat
Expand All @@ -204,17 +229,7 @@ def _check_exists(self) -> bool:
return False

def _install(self) -> bool:
wget_tool = self.node.tools[Wget]
lis_path = wget_tool.get("https://aka.ms/lis", str(self.node.working_path))

result = self.node.execute(f"tar -xvzf {lis_path}", cwd=self.node.working_path)
if result.exit_code != 0:
raise LisaException(
"Failed to extract tar file after downloading LIS package. "
f"exit_code: {result.exit_code} stderr: {result.stderr}"
)
lis_folder_path = self.node.working_path.joinpath("LISISO")
result = self.node.execute("./install.sh", cwd=lis_folder_path, sudo=True)
result = self.install_from_iso()
if result.exit_code != 0:
raise LisaException(
f"Unable to install the LIS RPMs! exit_code: {result.exit_code}"
Expand All @@ -223,11 +238,6 @@ def _install(self) -> bool:
self.node.reboot(360)
return True

def get_version(self, force_run: bool = False) -> str:
# in some distro, the vmbus is builtin, the version cannot be gotten.
modinfo = self.node.tools[Modinfo]
return modinfo.get_version("hv_vmbus")


class KvpClient(Tool):
"""
Expand Down
7 changes: 6 additions & 1 deletion lisa/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT license.


from lisa.base_tools import Cat, Sed, Uname, Wget
from lisa.base_tools import Cat, Rpm, Sed, Uname, Wget

from .blkid import Blkid
from .chown import Chown
Expand All @@ -16,6 +16,7 @@
from .docker_compose import DockerCompose
from .echo import Echo
from .ethtool import Ethtool
from .fallocate import Fallocate
from .fdisk import Fdisk
from .find import Find
from .fio import FIOMODES, Fio, FIOResult
Expand Down Expand Up @@ -63,6 +64,7 @@
from .service import Service
from .ssh import Ssh
from .sshpass import Sshpass
from .stat import Stat
from .swap import Swap
from .swapon import SwapOn
from .sysctl import Sysctl
Expand Down Expand Up @@ -90,6 +92,7 @@
"DockerCompose",
"Echo",
"Ethtool",
"Fallocate",
"Fdisk",
"Find",
"FIOMODES",
Expand Down Expand Up @@ -141,12 +144,14 @@
"Qemu",
"QemuImg",
"Reboot",
"Rpm",
"Sar",
"Sed",
"Uname",
"Service",
"Ssh",
"Sshpass",
"Stat",
"Swap",
"SwapOn",
"Sysctl",
Expand Down
33 changes: 33 additions & 0 deletions lisa/tools/fallocate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from typing import cast

from lisa.executable import Tool
from lisa.operating_system import Posix


class Fallocate(Tool):
@property
def command(self) -> str:
return "fallocate"

@property
def can_install(self) -> bool:
return True

def install(self) -> bool:
posix_os: Posix = cast(Posix, self.node.os)
package_name = "util-linux"
posix_os.install_packages(package_name)
return self._check_exists()

def create_file(self, length_in_bytes: int, file_path: str) -> None:
self.run(
f"-l {length_in_bytes} {file_path}",
shell=True,
sudo=True,
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message="fail to create file by fallocate",
)
65 changes: 65 additions & 0 deletions lisa/tools/stat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from typing import cast

from lisa.executable import Tool
from lisa.operating_system import Posix


class Stat(Tool):
@property
def command(self) -> str:
return "stat"

@property
def can_install(self) -> bool:
return True

def install(self) -> bool:
posix_os: Posix = cast(Posix, self.node.os)
package_name = "coreutils"
posix_os.install_packages(package_name)
return self._check_exists()

def get_fs_block_size(self, file: str) -> int:
cmd_result = self.run(
"-f --format='%S' " f"{file}",
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message=(
f"fail to get block size of {file} in file system"
),
)
return int(cmd_result.stdout)

def get_fs_available_size(self, file: str) -> int:
cmd_result = self.run(
"-f --format='%a' " f"{file}",
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message=(
f"fail to get available size of {file} in filesystem"
),
)
return int(cmd_result.stdout)

def get_total_size(self, file: str) -> int:
cmd_result = self.run(
f"{file}" " --format='%s'",
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message=(f"fail to get total size of {file}"),
)
return int(cmd_result.stdout)

def get_fs_free_blocks(self, file: str) -> int:
cmd_result = self.run(
"-f --format='%f'" f" {file}",
force_run=True,
expected_exit_code=0,
expected_exit_code_failure_message=(
f"fail to get free blocks of {file} in file system"
),
)
return int(cmd_result.stdout)
Loading