KVM unit tests: log collection for timeout failures

When KVM unit tests gets killed due to timeout, result.stdout
is empty and the test fails with "no results in stdout". In this
case it is useful to collect the logs from the "logs" directory
to debug the problem since we don't have any useful information
in stdout.

Signed-off-by: Anirudh Rayabharam <anrayabh@microsoft.com>
This commit is contained in:
Anirudh Rayabharam 2022-08-17 05:27:38 +00:00 коммит произвёл Chi Song
Родитель 7463cd7e10
Коммит e47af888b6
3 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -9,5 +9,8 @@ class Chmod(Tool):
def command(self) -> str:
return "chmod"
def chmod(self, path: str, permission: str, sudo: bool = False) -> None:
self.run(f"{permission} {path}", sudo=sudo, force_run=True)
def update_folder(self, path: str, permission: str, sudo: bool = False) -> None:
self.run(f"-R {permission} {path}", sudo=sudo, force_run=True)

Просмотреть файл

@ -24,6 +24,21 @@ class Ls(Tool):
)
return 0 == cmd_result.exit_code
def list(self, path: str, sudo: bool = False) -> List[str]:
cmd_result = self.run(
f"-d {path}/*",
force_run=True,
sudo=sudo,
shell=True,
)
# can fail due to insufficient permissions, non existent
# files/dirs etc.
if cmd_result.exit_code == 0:
return cmd_result.stdout.split()
else:
return []
def list_dir(self, path: str, sudo: bool = False) -> List[str]:
cmd_result = self.node.execute(
f"{self.command} -d {path}/*/",

Просмотреть файл

@ -12,7 +12,7 @@ from lisa.executable import Tool
from lisa.messages import SubTestMessage, TestStatus, create_test_result_message
from lisa.operating_system import Posix
from lisa.testsuite import TestResult
from lisa.tools import Git, Make
from lisa.tools import Chmod, Git, Ls, Make
from lisa.util import LisaException
@ -75,6 +75,7 @@ class KvmUnitTests(Tool):
results = self._parse_results(exec_result.stdout)
if not results:
self._save_all_logs(failure_logs_path)
raise LisaException("Did not find any test results in stdout.")
failed_tests = []
@ -140,6 +141,18 @@ class KvmUnitTests(Tool):
log_path / f"{test_name}.failure.log",
)
def _save_all_logs(self, log_path: Path) -> None:
logs_dir = self.repo_root / "logs"
self.node.tools[Chmod].chmod("a+x", str(logs_dir), sudo=True)
self.node.tools[Chmod].update_folder("a+r", str(logs_dir), sudo=True)
files = self.node.tools[Ls].list(str(logs_dir), sudo=True)
for f in files:
f_path = PurePath(f)
self.node.shell.copy_back(
f_path,
log_path / f"{f_path.name}",
)
def _initialize(self, *args: Any, **kwargs: Any) -> None:
tool_path = self.get_tool_path(use_global=True)
self.repo_root = tool_path.joinpath("kvm-unit-tests")