Skip to content

Commit

Permalink
Allow for both filtered and unfiltered log file closing
Browse files Browse the repository at this point in the history
The environment setup module could close all log files once all
sessions are closed but we have to keep backwards compatibility
with other uses cases of closing just a single or few log files.

Signed-off-by: Plamen Dimitrov <[email protected]>
  • Loading branch information
pevogam committed Dec 7, 2023
1 parent 68c0b39 commit 04a89c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from virttest import migration
from virttest import utils_kernel_module
from virttest import arch
from virttest import utils_logfile
from virttest.utils_conn import SSHConnection
from virttest.utils_version import VersionInterval
from virttest.staging import service
Expand Down Expand Up @@ -630,6 +631,8 @@ def postprocess_vm(test, params, env, name):
except Exception:
pass

utils_logfile.close_log_file()

if params.get("vm_extra_dump_paths") is not None:
vm_extra_dumps = os.path.join(test.outputdir, "vm_extra_dumps")
if not os.path.exists(vm_extra_dumps):
Expand Down
7 changes: 4 additions & 3 deletions virttest/utils_logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def get_log_filename(filename):
os.path.abspath(utils_path.get_path(_log_file_dir, filename)))


def close_log_file(filename):
def close_log_file(filename="*"):
"""
Close all files that use the same base name as filename.
Close log files with the same base name as filename or all by default.
:param filename: Log file name
:raise: LogLockError if the lock is unavailable
Expand All @@ -156,7 +156,8 @@ def close_log_file(filename):
" _open_log_files")
try:
for log_file, log_fd in _open_log_files.items():
if os.path.basename(log_file) == os.path.basename(filename):
if (filename == '*' or
os.path.basename(log_file) == os.path.basename(filename)):
log_fd.close()
remove.append(log_file)
if remove:
Expand Down

0 comments on commit 04a89c0

Please sign in to comment.