Skip to content

Commit

Permalink
env_process: Refactor Libvirtd debug log setup/cleanup into a Setuper
Browse files Browse the repository at this point in the history
Move the setup/cleanup steps of the Libvirtd debug log from the
env_process.{pre,post}process into a Setuper subclass. The env_process
setup_manager will call the setup/cleanup methods when appropriate.

Signed-off-by: bgartzi <[email protected]>
  • Loading branch information
bgartzi committed Mar 6, 2024
1 parent 05bc5f7 commit 20f1bec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
18 changes: 2 additions & 16 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from virttest.test_setup.core import SetupManager
from virttest.test_setup.os_posix import UlimitConfig
from virttest.test_setup.networking import NetworkProxies, BridgeConfig

from virttest.test_setup.libvirt_setup import LibvirtdDebugLogConfig

# lazy imports for dependencies that are not needed in all modes of use
from virttest._wrappers import lazy_import
Expand Down Expand Up @@ -1096,23 +1096,12 @@ def preprocess(test, params, env):
_setup_manager.initialize(test, params, env)
_setup_manager.register(UlimitConfig)
_setup_manager.register(NetworkProxies)
_setup_manager.register(LibvirtdDebugLogConfig)
_setup_manager.register(BridgeConfig)
_setup_manager.do_setup()

vm_type = params.get("vm_type")

if vm_type == "libvirt":
if params.get("enable_libvirtd_debug_log", "yes") == "yes":
# By default log the info level
log_level = params.get("libvirtd_debug_level", "2")
log_file = params.get("libvirtd_debug_file", "")
log_filters = params.get("libvirtd_debug_filters", "%s:*" % log_level)
log_permission = params.get("libvirtd_log_permission")
libvirtd_debug_log = test_setup.LibvirtdDebugLog(
test, log_level, log_file, log_filters, log_permission
)
libvirtd_debug_log.enable()

base_dir = data_dir.get_data_dir()
if params.get("storage_type") == "iscsi":
iscsidev = qemu_storage.Iscsidev(params, base_dir, "iscsi")
Expand Down Expand Up @@ -1993,9 +1982,6 @@ def postprocess(test, params, env):
except Exception as details:
err += "\nPolkit cleanup: %s" % str(details).replace("\\n", "\n ")
LOG.error("Unexpected error: %s" % details)
if params.get("enable_libvirtd_debug_log", "yes") == "yes":
libvirtd_debug_log = test_setup.LibvirtdDebugLog(test)
libvirtd_debug_log.disable()

# Execute any post_commands
if params.get("post_command"):
Expand Down
27 changes: 27 additions & 0 deletions virttest/test_setup/libvirt_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from virttest.test_setup.core import Setuper
from virttest import test_setup


class LibvirtdDebugLogConfig(Setuper):
def setup(self):
if (
self.params.get("vm_type") == "libvirt"
and self.params.get("enable_libvirtd_debug_log", "yes") == "yes"
):
# By default log the info level
log_level = self.params.get("libvirtd_debug_level", "2")
log_file = self.params.get("libvirtd_debug_file", "")
log_filters = self.params.get("libvirtd_debug_filters", f"{log_level}:*")
log_permission = self.params.get("libvirtd_log_permission")
libvirtd_debug_log = test_setup.LibvirtdDebugLog(
self.test, log_level, log_file, log_filters, log_permission
)
libvirtd_debug_log.enable()

def cleanup(self):
if (
self.params.get("vm_type") == "libvirt"
and self.params.get("enable_libvirtd_debug_log", "yes") == "yes"
):
libvirtd_debug_log = test_setup.LibvirtdDebugLog(self.test)
libvirtd_debug_log.disable()

0 comments on commit 20f1bec

Please sign in to comment.