Skip to content

Commit

Permalink
Drop usage of placeholder session log file attribute
Browse files Browse the repository at this point in the history
Since we are handling the complete log file setup and cleanup on
the Avocado VT side we can use the more powerful close hook approach
to provide the log file path via currying and a function wrapper.

Signed-off-by: Plamen Dimitrov <[email protected]>
  • Loading branch information
pevogam committed Nov 25, 2023
1 parent f1c09e7 commit 68c0b39
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions virttest/libvirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,8 +1472,7 @@ def _create_serial_console(self):
self.serial_console_log = os.path.join(utils_logfile.get_log_file_dir(),
output_filename)
# Cause serial_console.close() to close open log file
self.serial_console.set_log_file(self.serial_console_log)
self.serial_console.close_hooks += [utils_logfile.close_own_log_file]
self.serial_console.close_hooks += [utils_logfile.close_own_log_file(self.serial_console_log)]

def set_root_serial_console(self, device, remove=False):
"""
Expand Down
3 changes: 1 addition & 2 deletions virttest/qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3534,8 +3534,7 @@ def create(self, name=None, params=None, root_dir=None,
auto_close=False,
output_func=utils_logfile.log_line,
output_params=(outfile,))
self.logsessions[key].set_log_file(outfile)
self.logsessions[key].close_hooks += [utils_logfile.close_own_log_file]
self.logsessions[key].close_hooks += [utils_logfile.close_own_log_file(outfile)]

# Wait for IO channels setting up completely,
# such as serial console.
Expand Down
3 changes: 1 addition & 2 deletions virttest/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def remote_commander(client, host, port, username, password, prompt,
log_file = utils_logfile.get_log_filename(log_filename)
session.set_output_func(utils_logfile.log_line)
session.set_output_params((log_file,))
session.set_log_file(log_file)
session.close_hooks += [utils_logfile.close_own_log_file]
session.close_hooks += [utils_logfile.close_own_log_file(log_file)]

session.send_ctrl("raw")
# Wrap io interfaces.
Expand Down
10 changes: 7 additions & 3 deletions virttest/utils_logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def close_log_file(filename):
_log_lock.release()


def close_own_log_file(self):
"""Closing hook for sessions whose log_file attribute should be passed along."""
close_log_file(self.log_file)
def close_own_log_file(log_file):
"""Closing hook for sessions with log_file managed locally."""

def hook(self):
close_log_file(log_file)

return hook
2 changes: 1 addition & 1 deletion virttest/utils_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def get_log_filename(filename):
def close_log_file(filename):
logging.warning("Calling log functions from `utils_misc` is deprecated, "
"please use `utils_logfile` for the purpose")
return utils_logfile.close_log_file()
return utils_logfile.close_log_file(filename)


# The following are miscellaneous utility functions.
Expand Down
4 changes: 2 additions & 2 deletions virttest/virt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,8 @@ def login(self, nic_index=0, timeout=LOGIN_TIMEOUT,
session = remote.remote_login(client, address, port, username,
password, prompt, linesep,
log_filename, log_function,
timeout, interface=neigh_attach_if)
session.close_hooks += [utils_logfile.close_own_log_file]
timeout, neigh_attach_if)
session.close_hooks += [utils_logfile.close_own_log_file(log_filename)]
session.set_status_test_command(self.params.get("status_test_command",
""))
self.remote_sessions.append(session)
Expand Down

0 comments on commit 68c0b39

Please sign in to comment.