Making logs smaller by getting it only for the time of test execution
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
parent
d7fb6885bf
commit
bcc5c38c27
@ -1,11 +1,13 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2021 Intel Corporation
|
# Copyright(c) 2019-2021 Intel Corporation
|
||||||
|
# Copyright(c) 2025 Huawei Technologies Co., Ltd.
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -46,6 +48,7 @@ class Log(HtmlLogManager, metaclass=Singleton):
|
|||||||
logger = None
|
logger = None
|
||||||
LOG_FORMAT = '%(asctime)s %(levelname)s:\t%(message)s'
|
LOG_FORMAT = '%(asctime)s %(levelname)s:\t%(message)s'
|
||||||
DATE_FORMAT = "%Y/%m/%d %H:%M:%S"
|
DATE_FORMAT = "%Y/%m/%d %H:%M:%S"
|
||||||
|
unique_test_identifier = ""
|
||||||
command_id = 0
|
command_id = 0
|
||||||
lock = Lock()
|
lock = Lock()
|
||||||
|
|
||||||
@ -190,15 +193,23 @@ class Log(HtmlLogManager, metaclass=Singleton):
|
|||||||
def get_additional_logs(self):
|
def get_additional_logs(self):
|
||||||
from core.test_run import TestRun
|
from core.test_run import TestRun
|
||||||
from test_tools.fs_tools import check_if_file_exists
|
from test_tools.fs_tools import check_if_file_exists
|
||||||
|
|
||||||
messages_log = "/var/log/messages"
|
messages_log = "/var/log/messages"
|
||||||
if not check_if_file_exists(messages_log):
|
if not check_if_file_exists(messages_log):
|
||||||
messages_log = "/var/log/syslog"
|
messages_log = "/var/log/syslog"
|
||||||
log_files = {"messages.log": messages_log,
|
|
||||||
|
log_files = {"messages.log": posixpath.join(TestRun.TEST_RUN_DATA_PATH, "messages"),
|
||||||
"dmesg.log": posixpath.join(TestRun.TEST_RUN_DATA_PATH, "dmesg")}
|
"dmesg.log": posixpath.join(TestRun.TEST_RUN_DATA_PATH, "dmesg")}
|
||||||
extra_logs = TestRun.config.get("extra_logs", {})
|
extra_logs = TestRun.config.get("extra_logs", {})
|
||||||
log_files.update(extra_logs)
|
log_files.update(extra_logs)
|
||||||
|
|
||||||
TestRun.executor.run(f"dmesg > {log_files['dmesg.log']}")
|
# Escape special characters from test identifier to be properly processed by awk
|
||||||
|
test_identifier = re.escape(TestRun.LOGGER.unique_test_identifier)
|
||||||
|
|
||||||
|
TestRun.executor.run(
|
||||||
|
f"dmesg | awk '/{test_identifier}/,0' > {log_files['dmesg.log']}")
|
||||||
|
TestRun.executor.run(
|
||||||
|
f"awk '/{test_identifier}/,0' {messages_log} > {log_files['messages.log']}")
|
||||||
|
|
||||||
dut_identifier = TestRun.dut.ip if TestRun.dut.ip else TestRun.dut.config["host"]
|
dut_identifier = TestRun.dut.ip if TestRun.dut.ip else TestRun.dut.config["host"]
|
||||||
for log_name, log_source_path in log_files.items():
|
for log_name, log_source_path in log_files.items():
|
||||||
@ -229,3 +240,11 @@ class Log(HtmlLogManager, metaclass=Singleton):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
json.dump(data, summary)
|
json.dump(data, summary)
|
||||||
|
|
||||||
|
def print_test_identifier_to_logs(self):
|
||||||
|
from core.test_run import TestRun
|
||||||
|
# Add test identifier to dmesg
|
||||||
|
TestRun.executor.run(f"echo {self.unique_test_identifier} > /dev/kmsg")
|
||||||
|
|
||||||
|
# Add test identifier to messages log
|
||||||
|
TestRun.executor.run(f"logger {self.unique_test_identifier}")
|
||||||
|
Loading…
Reference in New Issue
Block a user