From f24eed1e83289eaaecab1b45903e4788387af6a2 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 16 Oct 2026 23:32:07 +0200 Subject: [PATCH] tests: Collect only the test's part of opencas.log opencas.log is never rotated, so copying it whole after every test stores the entire history of the DUT in each test's logs. Mark the test start in it, like in dmesg and messages, and collect only what was logged from that point. Signed-off-by: Robert Baldyga --- test/functional/tests/conftest.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index 1b575d9aa..a25e596f9 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -7,6 +7,7 @@ import os import posixpath +import re import sys import traceback from datetime import timedelta @@ -38,6 +39,9 @@ from storage_devices.disk import Disk from storage_devices.drbd import Drbd +cas_log_path = "/var/log/opencas.log" +cas_log_test_part_path = posixpath.join(TestRun.TEST_RUN_DATA_PATH, "opencas.log") + def pytest_addoption(parser): TestRun.addoption(parser) @@ -106,7 +110,7 @@ def pytest_runtest_setup(item): dut_config["plugins_dir"] = os.path.join(os.path.dirname(__file__), "..", "lib") dut_config["opt_plugins"] = {"test_wrapper": {}, "serial_log": {}, "power_control": {}} - dut_config["extra_logs"] = {"cas": "/var/log/opencas.log"} + dut_config["extra_logs"] = {"cas": cas_log_test_part_path} try: TestRun.prepare(item, dut_config) @@ -129,6 +133,9 @@ def pytest_runtest_setup(item): ) TestRun.LOGGER.print_test_identifier_to_logs() + TestRun.executor.run( + f"echo '{TestRun.LOGGER.unique_test_identifier}' >> {cas_log_path}" + ) TestRun.usr = Opencas( repo_dir=os.path.join(os.path.dirname(__file__), "..", "..", ".."), @@ -309,6 +316,11 @@ def pytest_runtest_teardown(): ), exist_ok=True, ) + # opencas.log is never rotated, so collect only this test's part of it + test_identifier = re.escape(TestRun.LOGGER.unique_test_identifier) + TestRun.executor.run( + f"awk '/{test_identifier}/,0' {cas_log_path} > {cas_log_test_part_path}" + ) TestRun.LOGGER.get_additional_logs() Log.destroy() TestRun.teardown()